[hackers] [ubase] umount -a should unmount in the reverse order || sin
commit 6ef8c718e15fa2e6c90cf2a6266850fa1c46727e
Author: sin <sin_AT_2f30.org>
Date: Sat Mar 15 18:44:16 2014 +0000
umount -a should unmount in the reverse order
diff --git a/umount.c b/umount.c
index c7d4882..efe7d84 100644
--- a/umount.c
+++ b/umount.c
_AT_@ -61,6 +61,8 @@ umountall(int flags)
FILE *fp;
struct mntent *me;
int ret;
+ char **mntdirs = NULL;
+ int len = 0;
fp = setmntent("/etc/mtab", "r");
if (!fp)
_AT_@ -68,11 +70,19 @@ umountall(int flags)
while ((me = getmntent(fp))) {
if (strcmp(me->mnt_type, "proc") == 0)
continue;
- if (umount2(me->mnt_dir, flags) < 0) {
- weprintf("umount2 %s:", me->mnt_dir);
+ mntdirs = realloc(mntdirs, ++len * sizeof(*mntdirs));
+ if (!mntdirs)
+ eprintf("realloc:");
+ mntdirs[len - 1] = strdup(me->mnt_dir);
+ }
+ endmntent(fp);
+ while (--len >= 0) {
+ if (umount2(mntdirs[len], flags) < 0) {
+ weprintf("umount2 %s:", mntdirs[len]);
ret = EXIT_FAILURE;
}
+ free(mntdirs[len]);
}
- endmntent(fp);
+ free(mntdirs);
return ret;
}
Received on Sat Mar 15 2014 - 19:49:37 CET
This archive was generated by hypermail 2.3.0
: Sat Mar 15 2014 - 20:00:18 CET