summaryrefslogtreecommitdiffstats
path: root/debian/functions
diff options
context:
space:
mode:
Diffstat (limited to 'debian/functions')
-rw-r--r--debian/functions72
1 files changed, 45 insertions, 27 deletions
diff --git a/debian/functions b/debian/functions
index 3409787..7d3b6c2 100644
--- a/debian/functions
+++ b/debian/functions
@@ -115,7 +115,7 @@ crypttab_parse_options() {
# use decrypt_keyctl by default if no keyscript in /etc/crypttab
if [ -z "$CRYPTTAB_OPTION_keyscript" ]; then
- CRYPTTAB_OPTION_keyscript="/lib/cryptsetup/scripts/decrypt_keyctl"
+ CRYPTTAB_OPTION_keyscript="/usr/lib/cryptsetup/scripts/decrypt_keyctl"
fi
if ! _get_crypt_type; then # set CRYPTTAB_TYPE to the type of crypt device
@@ -609,34 +609,52 @@ _resolve_device() {
# mounted currenty mounted on $mountpoint.
# Return 0 on success, 1 on error (if $mountpoint is not a mountpoint).
get_mnt_devno() {
- local wantmount="$1" devnos="" uuid dev IFS
- local spec mountpoint fstype _ DEV MAJ MIN
-
- while IFS=" " read -r spec mountpoint fstype _; do
- # treat lines starting with '#' as comments; /proc/mounts
- # doesn't seem to contain these but per procfs(5) the format of
- # that file is analogous to fstab(5)'s
- if [ "${spec#\#}" = "$spec" ] && [ -n "$spec" ] &&
- [ "$(printf '%b' "$mountpoint")" = "$wantmount" ]; then
- # take the last mountpoint if used several times (shadowed)
- unset -v devnos
- spec="$(printf '%b' "$spec")"
- _resolve_device "$spec" || continue # _resolve_device() already warns on error
- fstype="$(printf '%b' "$fstype")"
- if [ "$fstype" = "btrfs" ]; then
- # btrfs can span over multiple devices
- if uuid="$(_device_uuid "$DEV")"; then
- for dev in "/sys/fs/$fstype/$uuid/devices"/*/dev; do
- devnos="${devnos:+$devnos }$(cat "$dev")"
- done
- else
- cryptsetup_message "ERROR: $spec: Couldn't determine UUID"
- fi
- elif [ -n "$fstype" ]; then
- devnos="$MAJ:$MIN"
+ local wantmount="$1" devnos="" uuid dev
+ local out spec fstype DEV MAJ MIN
+
+ # use awk rather than a `while read; do done` loop here as /proc/mounts
+ # can be many thousands lines long and the `read` builtin goes one
+ # byte at the time which slows down execution time, see MR !36
+ out="$(awk -v mp="$wantmount" -- '
+ BEGIN {
+ FS = "[ \t]"
+ ret = ""
+ }
+ !/^\s*(#|$)/ {
+ # decode octal sequences; per procfs(5) the format of /proc/mounts
+ # is analogous to fstab(5)
+ head = ""
+ while (match($2, /\\[0-7]{3}/)) {
+ oct = substr($2, RSTART+1, RLENGTH-1)
+ dec = (substr(oct, 1, 1) * 8 + substr(oct, 2, 1)) * 8 + substr(oct, 3, 1)
+ head = head substr($2, 1, RSTART-1) sprintf("%c", dec)
+ $2 = substr($2, RSTART+RLENGTH)
+ }
+ if (head $2 == mp) {
+ # take the last mountpoint if used several times (shadowed)
+ ret = $1 " " $3
+ }
+ }
+ END {
+ print ret
+ }' </proc/mounts)" || out=""
+
+ spec="$(printf '%b' "${out% *}")"
+ if [ -n "$out" ] && _resolve_device "$spec"; then # _resolve_device() already warns on error
+ fstype="${out##* }"
+ if [ "$fstype" = "btrfs" ]; then
+ # btrfs can span over multiple devices
+ if uuid="$(_device_uuid "$DEV")"; then
+ for dev in "/sys/fs/$fstype/$uuid/devices"/*/dev; do
+ devnos="${devnos:+$devnos }$(cat "$dev")"
+ done
+ else
+ cryptsetup_message "ERROR: $spec: Couldn't determine UUID"
fi
+ elif [ -n "$fstype" ]; then
+ devnos="$MAJ:$MIN"
fi
- done </proc/mounts
+ fi
if [ -z "${devnos:+x}" ]; then
return 1 # not found