]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
e2scrub_all: fix broken stdin redirection
authorDarrick J. Wong <darrick.wong@oracle.com>
Tue, 5 Nov 2019 01:54:20 +0000 (17:54 -0800)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 10 Nov 2019 01:29:12 +0000 (20:29 -0500)
gregor herrmann reports that the weekly e2scrub cronjob emits these
errors:

/sbin/e2scrub_all: line 173: /proc/8234/fd/pipe:[90083173]: No such file or directory

The root cause of this is that the ls_targets stdout is piped to stdin
to the entire ls_targets loop body to prevent the loop body from reading
the loop iteration items.  Remove all the broken hackery by reading the
target list into a bash array and iterating the bash array.

Addresses-Debian-Bug: #944033

Reported-by: gregor herrmann <gregoa@debian.org>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
scrub/e2scrub_all.in

index 72e66ff6af32c21b729cd29cc7ac1d8c42343e6b..f03367115c0173e8f4dc4f27bc36cc39755a3791 100644 (file)
@@ -101,6 +101,12 @@ exec 3<&-
 # indicating success to avoid spamming the sysadmin with fail messages
 # when e2scrub_all is run out of cron or a systemd timer.
 
+if ! type mapfile >& /dev/null ; then
+    test -n "${SERVICE_MODE}" && exitcode 0
+    echo "e2scrub_all: can't find mapfile --- is bash 4.xx installed?"
+    exitcode 1
+fi
+
 if ! type lsblk >& /dev/null ; then
     test -n "${SERVICE_MODE}" && exitcode 0
     echo "e2scrub_all: can't find lsblk --- is util-linux installed?"
@@ -165,13 +171,13 @@ escape_path_for_systemd() {
 }
 
 # Scrub any mounted fs on lvm by creating a snapshot and fscking that.
-stdin="$(realpath /dev/stdin)"
-ls_targets | while read tgt; do
+mapfile -t targets < <(ls_targets)
+for tgt in "${targets[@]}"; do
        # If we're not reaping and systemd is present, try invoking the
        # systemd service.
        if [ "${reap}" -ne 1 ] && type systemctl > /dev/null 2>&1; then
                tgt_esc="$(escape_path_for_systemd "${tgt}")"
-               ${DBG} systemctl start "e2scrub@${tgt_esc}" 2> /dev/null < "${stdin}"
+               ${DBG} systemctl start "e2scrub@${tgt_esc}" 2> /dev/null
                res=$?
                if [ "${res}" -eq 0 ] || [ "${res}" -eq 1 ]; then
                        continue;
@@ -179,7 +185,7 @@ ls_targets | while read tgt; do
        fi
 
        # Otherwise use direct invocation
-       ${DBG} "@root_sbindir@/e2scrub" ${scrub_args} "${tgt}" < "${stdin}"
+       ${DBG} "@root_sbindir@/e2scrub" ${scrub_args} "${tgt}"
 done
 
 exitcode 0