From 5adb92ca1b7831b0ecc88c2791f973c2d40b3ab7 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Tue, 12 Apr 2022 21:42:10 +0200 Subject: [PATCH] Catch and print any errors when unmounting filesystems at reboot Signed-off-by: Joachim Wiberg --- src/mount.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/mount.c b/src/mount.c index a0405a4b..430e3a85 100644 --- a/src/mount.c +++ b/src/mount.c @@ -21,10 +21,13 @@ * THE SOFTWARE. */ +#include #include #include #include +#include "helpers.h" + /* * SysV init on Debian/Ubuntu skips these protected mount points * @@ -86,13 +89,24 @@ static struct mntent *iterator(char *fstab, FILE **fp) return NULL; } +static int unmount(const char *target) +{ + int rc; + + rc = umount(target); + if (rc) + print(2, "Failed unmounting %s, error %d: %s", target, errno, strerror(errno)); + + return rc; +} + void unmount_tmpfs(void) { struct mntent *mnt; FILE *fp = NULL; while ((mnt = iterator("/proc/mounts", &fp))) { - if (!strcmp("tmpfs", mnt->mnt_fsname) && !umount(mnt->mnt_dir)) + if (!strcmp("tmpfs", mnt->mnt_fsname) && !unmount(mnt->mnt_dir)) iterator_end(&fp); /* Restart iteration */ } } @@ -103,7 +117,7 @@ void unmount_regular(void) FILE *fp = NULL; while ((mnt = iterator("/proc/mounts", &fp))) { - if (!umount(mnt->mnt_dir)) + if (!unmount(mnt->mnt_dir)) iterator_end(&fp); /* Restart iteration */ } }