[hackers] [ubase] Factor out umount -a into a separate function || sin
commit 98f7fcad946431881edf44c2415e96956b8ecd75
Author: sin <sin_AT_2f30.org>
Date: Sat Mar 15 18:37:16 2014 +0000
Factor out umount -a into a separate function
diff --git a/umount.c b/umount.c
index c413a0e..c7d4882 100644
--- a/umount.c
+++ b/umount.c
_AT_@ -6,6 +6,8 @@
#include <sys/mount.h>
#include "util.h"
+static int umountall(int);
+
static void
usage(void)
{
_AT_@ -21,8 +23,6 @@ main(int argc, char *argv[])
int aflag = 0;
int flags = 0;
int ret = EXIT_SUCCESS;
- FILE *fp;
- struct mntent *me;
ARGBEGIN {
case 'a':
_AT_@ -43,21 +43,8 @@ main(int argc, char *argv[])
if (argc < 1 && aflag == 0)
usage();
- if (aflag == 1) {
- fp = setmntent("/etc/mtab", "r");
- if (!fp)
- eprintf("setmntent %s:", "/etc/mtab");
- 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);
- ret = EXIT_FAILURE;
- }
- }
- endmntent(fp);
- return ret;
- }
+ if (aflag == 1)
+ return umountall(flags);
for (i = 0; i < argc; i++) {
if (umount2(argv[i], flags) < 0) {
_AT_@ -67,3 +54,25 @@ main(int argc, char *argv[])
}
return ret;
}
+
+static int
+umountall(int flags)
+{
+ FILE *fp;
+ struct mntent *me;
+ int ret;
+
+ fp = setmntent("/etc/mtab", "r");
+ if (!fp)
+ eprintf("setmntent %s:", "/etc/mtab");
+ 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);
+ ret = EXIT_FAILURE;
+ }
+ }
+ endmntent(fp);
+ return ret;
+}
Received on Sat Mar 15 2014 - 19:49:31 CET
This archive was generated by hypermail 2.3.0
: Sat Mar 15 2014 - 20:00:15 CET