]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
e2scrub_all: make sure fd 3 is closed before running lvm commands
authorTheodore Ts'o <tytso@mit.edu>
Mon, 23 Sep 2019 17:17:13 +0000 (13:17 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 23 Sep 2019 17:17:13 +0000 (13:17 -0400)
Some versions of cron leave fd 3 open for some unknown reason.  So
when e2scrub_all is run by cron (on non-systemd systems) this results
in an annoying message from the Cron Daemon because lvm will print
warning messages about "leaked file descriptors.  So force close fd 3
at the beginning of e2scrub and e2scrub_all.

Addresses-Debian-Bug: #940240
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
scrub/e2scrub.in
scrub/e2scrub_all.in

index b660e56950922e2ea8eea06c05feca2c08a740ae..b778a92a93e3a81891ad6c314dbb7c9c96eb85f1 100644 (file)
@@ -101,6 +101,9 @@ if ! type lvcreate >& /dev/null ; then
     exitcode 1
 fi
 
+# close file descriptor 3 (from cron) since it causes lvm to kvetch
+exec 3<&-
+
 # Find the device for a given mountpoint
 dev_from_mount() {
        local mountpt="$(realpath "$1")"
@@ -171,10 +174,10 @@ snap_dev="/dev/${LVM2_VG_NAME}/${snap}"
 
 teardown() {
        # Remove and wait for removal to succeed.
-       ${DBG} lvremove -f "${LVM2_VG_NAME}/${snap}" 3>&-
+       ${DBG} lvremove -f "${LVM2_VG_NAME}/${snap}"
        while [ -e "${snap_dev}" ] && [ "$?" -eq "5" ]; do
                sleep 0.5
-               ${DBG} lvremove -f "${LVM2_VG_NAME}/${snap}" 3>&-
+               ${DBG} lvremove -f "${LVM2_VG_NAME}/${snap}"
        done
 }
 
@@ -199,18 +202,18 @@ mark_corrupt() {
 setup() {
        # Try to remove snapshot for 30s, bail out if we can't remove it.
        lveremove_deadline="$(( $(date "+%s") + 30))"
-       ${DBG} lvremove -f "${LVM2_VG_NAME}/${snap}" 3>&- 2>/dev/null
+       ${DBG} lvremove -f "${LVM2_VG_NAME}/${snap}" 2>/dev/null
        while [ -e "${snap_dev}" ] && [ "$?" -eq "5" ] &&
              [ "$(date "+%s")" -lt "${lvremove_deadline}" ]; do
                sleep 0.5
-               ${DBG} lvremove -f "${LVM2_VG_NAME}/${snap}" 3>&-
+               ${DBG} lvremove -f "${LVM2_VG_NAME}/${snap}"
        done
        if [ -e "${snap_dev}" ]; then
                echo "${arg}: e2scrub snapshot is in use, cannot check!"
                return 1
        fi
        # Create the snapshot, wait for device to appear.
-       ${DBG} lvcreate -s -L "${snap_size_mb}m" -n "${snap}" "${LVM2_VG_NAME}/${LVM2_LV_NAME}" 3>&-
+       ${DBG} lvcreate -s -L "${snap_size_mb}m" -n "${snap}" "${LVM2_VG_NAME}/${LVM2_LV_NAME}"
        if [ $? -ne 0 ]; then
                echo "${arg}: e2scrub snapshot FAILED, will not check!"
                return 1
index 2c563672efe52cf834f41a4b507071b3d3d23821..1418a229f6dab5de705868cdcc0b73c0f61973e8 100644 (file)
@@ -85,6 +85,9 @@ then
     exitcode 0
 fi
 
+# close file descriptor 3 (from cron) since it causes lvm to kvetch
+exec 3<&-
+
 # If some prerequisite packages are not installed, exit with a code
 # indicating success to avoid spamming the sysadmin with fail messages
 # when e2scrub_all is run out of cron or a systemd timer.