diff options
author | Theodore Ts'o <tytso@mit.edu> | 2019-09-23 13:17:13 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2019-09-23 13:17:13 -0400 |
commit | 8111b79da71e24bf945ea3ff8b6a83ecc779f932 (patch) | |
tree | 92ecb956df9fa6ffd626003ceb8537c62a9230ba | |
parent | 1b866f5584bc9deefab7c657895413eb7f13f1f9 (diff) |
e2scrub_all: make sure fd 3 is closed before running lvm commands
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>
-rw-r--r-- | scrub/e2scrub.in | 13 | ||||
-rw-r--r-- | scrub/e2scrub_all.in | 3 |
2 files changed, 11 insertions, 5 deletions
diff --git a/scrub/e2scrub.in b/scrub/e2scrub.in index b660e569..b778a92a 100644 --- a/scrub/e2scrub.in +++ b/scrub/e2scrub.in @@ -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 diff --git a/scrub/e2scrub_all.in b/scrub/e2scrub_all.in index 2c563672..1418a229 100644 --- a/scrub/e2scrub_all.in +++ b/scrub/e2scrub_all.in @@ -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. |