From 4c7029c3d53a860c463ba4228ca0ea700cb4cc9d Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sat, 17 Feb 2018 19:23:19 +0000 Subject: [PATCH] Handle the case where udevadm exists but is non-functional, as warned about by Lintian 2.5.75. --- debian/changelog | 2 ++ debian/postinst.in | 43 +++++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/debian/changelog b/debian/changelog index b0d40210b..dc601e384 100644 --- a/debian/changelog +++ b/debian/changelog @@ -11,6 +11,8 @@ grub2 (2.02+dfsg1-1) UNRELEASED; urgency=medium versions of libgcrypt (closes: #745409). * Cherry-pick upstream patch to avoid -Werror=unused-value build failure (closes: #890431). + * Handle the case where udevadm exists but is non-functional, as warned + about by Lintian 2.5.75. -- Colin Watson Sun, 11 Feb 2018 23:23:09 +0000 diff --git a/debian/postinst.in b/debian/postinst.in index f1384c687..16cd64023 100644 --- a/debian/postinst.in +++ b/debian/postinst.in @@ -184,33 +184,36 @@ camcontrol_size() echo "$size" } +maybe_udevadm() +{ + if which udevadm >/dev/null 2>&1; then + udevadm "$@" || true + fi +} + # Returns value in $RET, like a debconf command. describe_disk() { - local disk id base size + local disk id sysfs_path disk_basename size model disk="$1" id="$2" model= case $(uname -s) in Linux) - if which udevadm >/dev/null 2>&1; then - size="$(sysfs_size "/sys$(udevadm info -n "$disk" -q path)")" - else - base="${disk#/dev/}" - base="$(printf %s "$base" | sed 's,/,!,g')" - size="$(sysfs_size "/sys/block/$base")" + sysfs_path="$(maybe_udevadm info -n "$disk" -q path)" + if [ -z "$sysfs_path" ]; then + sysfs_path="/block/$(printf %s "${disk#/dev/}" | sed 's,/,!,g')" fi + size="$(sysfs_size "/sys$sysfs_path")" - if which udevadm >/dev/null 2>&1; then - model="$(udevadm info -n "$disk" -q property | sed -n 's/^ID_MODEL=//p')" + model="$(maybe_udevadm info -n "$disk" -q property | sed -n 's/^ID_MODEL=//p')" + if [ -z "$model" ]; then + model="$(maybe_udevadm info -n "$disk" -q property | sed -n 's/^DM_NAME=//p')" if [ -z "$model" ]; then - model="$(udevadm info -n "$disk" -q property | sed -n 's/^DM_NAME=//p')" - if [ -z "$model" ]; then - model="$(udevadm info -n "$disk" -q property | sed -n 's/^MD_NAME=//p')" - if [ -z "$model" ] && which dmsetup >/dev/null 2>&1; then - model="$(dmsetup info -c --noheadings -o name "$disk" 2>/dev/null || true)" - fi + model="$(maybe_udevadm info -n "$disk" -q property | sed -n 's/^MD_NAME=//p')" + if [ -z "$model" ] && which dmsetup >/dev/null 2>&1; then + model="$(dmsetup info -c --noheadings -o name "$disk" 2>/dev/null || true)" fi fi fi @@ -233,21 +236,21 @@ describe_disk() # Returns value in $RET, like a debconf command. describe_partition() { - local disk part id path diskbase partbase size + local disk part id path sysfs_path diskbase partbase size disk="$1" part="$2" id="$3" path="$4" - if which udevadm >/dev/null 2>&1; then - size="$(sysfs_size "/sys$(udevadm info -n "$part" -q path)")" - else + sysfs_path="$(maybe_udevadm info -n "$part" -q path)" + if [ -z "$sysfs_path" ]; then diskbase="${disk#/dev/}" diskbase="$(printf %s "$diskbase" | sed 's,/,!,g')" partbase="${part#/dev/}" partbase="$(printf %s "$partbase" | sed 's,/,!,g')" - size="$(sysfs_size "/sys/block/$diskbase/$partbase")" + sysfs_path="/block/$diskbase/$partbase" fi + size="$(sysfs_size "/sys$sysfs_path")" db_subst grub-pc/partition_description DEVICE "$part" db_subst grub-pc/partition_description SIZE "$size"