diff options
author | Eric Andersen <andersen@codepoet.org> | 2002-10-26 10:27:42 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2002-10-26 10:27:42 +0000 |
commit | db1df5ebebc574bdc02adecf703a89d049b744ac (patch) | |
tree | 69c3f1b7f42af0aefc2f1465e2d91c728e1acc31 | |
parent | fda2b7ff47c6cd35f2fdf673125a834d0ffe0593 (diff) | |
download | busybox-db1df5ebebc574bdc02adecf703a89d049b744ac.tar.gz |
last_patch64 from vodz:
The following usage from original user:
$ ./busybox swapon -a
Have typo problem:
swapon: swapon: Operation not permitted
But regular version:
swapon: /dev/hda5: Operation not permitted
Patch attached, reduced 9 bytes and advanced
exit code also.
-rw-r--r-- | util-linux/swaponoff.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c index 6cc736ab1..a57dfe472 100644 --- a/util-linux/swaponoff.c +++ b/util-linux/swaponoff.c @@ -39,13 +39,13 @@ extern int swapoff (__const char *__path); #include "busybox.h" -static int whichApp; +static int whichApp; /* default SWAPON_APP */ -static const int SWAPON_APP = 1; -static const int SWAPOFF_APP = 2; +static const int SWAPON_APP = 0; +static const int SWAPOFF_APP = 1; -static void swap_enable_disable(char *device) +static int swap_enable_disable(const char *device) { int status; @@ -54,32 +54,35 @@ static void swap_enable_disable(char *device) else status = swapoff(device); - if (status != 0) - perror_msg_and_die(applet_name); + if (status != 0) { + perror_msg("%s", device); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; } -static void do_em_all(void) +static int do_em_all(void) { struct mntent *m; FILE *f = setmntent("/etc/fstab", "r"); + int err = 0; if (f == NULL) perror_msg_and_die("/etc/fstab"); while ((m = getmntent(f)) != NULL) { if (strcmp(m->mnt_type, MNTTYPE_SWAP)==0) { - swap_enable_disable(m->mnt_fsname); + if(swap_enable_disable(m->mnt_fsname) == EXIT_FAILURE) + err++; } } endmntent(f); - exit(EXIT_SUCCESS); + return err; } extern int swap_on_off_main(int argc, char **argv) { - if (strcmp(applet_name, "swapon") == 0) { - whichApp = SWAPON_APP; - } else { + if (applet_name[5] == 'f') { /* "swapoff" */ whichApp = SWAPOFF_APP; } @@ -100,14 +103,13 @@ extern int swap_on_off_main(int argc, char **argv) if (stat("/etc/fstab", &statBuf) < 0) error_msg_and_die("/etc/fstab file missing"); } - do_em_all(); + return do_em_all(); break; default: goto usage_and_exit; } } - swap_enable_disable(*argv); - return EXIT_SUCCESS; + return swap_enable_disable(*argv); usage_and_exit: show_usage(); |