Factor out umount -a into a separate function

This commit is contained in:
sin 2014-03-15 18:37:16 +00:00
parent e5b9f69626
commit 98f7fcad94

View File

@ -6,6 +6,8 @@
#include <sys/mount.h> #include <sys/mount.h>
#include "util.h" #include "util.h"
static int umountall(int);
static void static void
usage(void) usage(void)
{ {
@ -21,8 +23,6 @@ main(int argc, char *argv[])
int aflag = 0; int aflag = 0;
int flags = 0; int flags = 0;
int ret = EXIT_SUCCESS; int ret = EXIT_SUCCESS;
FILE *fp;
struct mntent *me;
ARGBEGIN { ARGBEGIN {
case 'a': case 'a':
@ -43,7 +43,25 @@ main(int argc, char *argv[])
if (argc < 1 && aflag == 0) if (argc < 1 && aflag == 0)
usage(); usage();
if (aflag == 1) { if (aflag == 1)
return umountall(flags);
for (i = 0; i < argc; i++) {
if (umount2(argv[i], flags) < 0) {
weprintf("umount2 %s:", argv[i]);
ret = EXIT_FAILURE;
}
}
return ret;
}
static int
umountall(int flags)
{
FILE *fp;
struct mntent *me;
int ret;
fp = setmntent("/etc/mtab", "r"); fp = setmntent("/etc/mtab", "r");
if (!fp) if (!fp)
eprintf("setmntent %s:", "/etc/mtab"); eprintf("setmntent %s:", "/etc/mtab");
@ -57,13 +75,4 @@ main(int argc, char *argv[])
} }
endmntent(fp); endmntent(fp);
return ret; return ret;
}
for (i = 0; i < argc; i++) {
if (umount2(argv[i], flags) < 0) {
weprintf("umount2 %s:", argv[i]);
ret = EXIT_FAILURE;
}
}
return ret;
} }