ubase

suckless linux base utils
git clone git://git.2f30.org/ubase
Log | Files | Refs | README | LICENSE

commit 6ef8c718e15fa2e6c90cf2a6266850fa1c46727e
parent 98f7fcad946431881edf44c2415e96956b8ecd75
Author: sin <sin@2f30.org>
Date:   Sat, 15 Mar 2014 18:44:16 +0000

umount -a should unmount in the reverse order

Diffstat:
Mumount.c | 16+++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/umount.c b/umount.c @@ -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) @@ -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; }