aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-10-26 10:27:42 +0000
committerEric Andersen <andersen@codepoet.org>2002-10-26 10:27:42 +0000
commitdb1df5ebebc574bdc02adecf703a89d049b744ac (patch)
tree69c3f1b7f42af0aefc2f1465e2d91c728e1acc31
parentfda2b7ff47c6cd35f2fdf673125a834d0ffe0593 (diff)
downloadbusybox-w32-db1df5ebebc574bdc02adecf703a89d049b744ac.tar.gz
busybox-w32-db1df5ebebc574bdc02adecf703a89d049b744ac.tar.bz2
busybox-w32-db1df5ebebc574bdc02adecf703a89d049b744ac.zip
last_patch64 from vodz:0_60_5
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.c32
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);
39 39
40#include "busybox.h" 40#include "busybox.h"
41 41
42static int whichApp; 42static int whichApp; /* default SWAPON_APP */
43 43
44static const int SWAPON_APP = 1; 44static const int SWAPON_APP = 0;
45static const int SWAPOFF_APP = 2; 45static const int SWAPOFF_APP = 1;
46 46
47 47
48static void swap_enable_disable(char *device) 48static int swap_enable_disable(const char *device)
49{ 49{
50 int status; 50 int status;
51 51
@@ -54,32 +54,35 @@ static void swap_enable_disable(char *device)
54 else 54 else
55 status = swapoff(device); 55 status = swapoff(device);
56 56
57 if (status != 0) 57 if (status != 0) {
58 perror_msg_and_die(applet_name); 58 perror_msg("%s", device);
59 return EXIT_FAILURE;
60 }
61 return EXIT_SUCCESS;
59} 62}
60 63
61static void do_em_all(void) 64static int do_em_all(void)
62{ 65{
63 struct mntent *m; 66 struct mntent *m;
64 FILE *f = setmntent("/etc/fstab", "r"); 67 FILE *f = setmntent("/etc/fstab", "r");
68 int err = 0;
65 69
66 if (f == NULL) 70 if (f == NULL)
67 perror_msg_and_die("/etc/fstab"); 71 perror_msg_and_die("/etc/fstab");
68 while ((m = getmntent(f)) != NULL) { 72 while ((m = getmntent(f)) != NULL) {
69 if (strcmp(m->mnt_type, MNTTYPE_SWAP)==0) { 73 if (strcmp(m->mnt_type, MNTTYPE_SWAP)==0) {
70 swap_enable_disable(m->mnt_fsname); 74 if(swap_enable_disable(m->mnt_fsname) == EXIT_FAILURE)
75 err++;
71 } 76 }
72 } 77 }
73 endmntent(f); 78 endmntent(f);
74 exit(EXIT_SUCCESS); 79 return err;
75} 80}
76 81
77 82
78extern int swap_on_off_main(int argc, char **argv) 83extern int swap_on_off_main(int argc, char **argv)
79{ 84{
80 if (strcmp(applet_name, "swapon") == 0) { 85 if (applet_name[5] == 'f') { /* "swapoff" */
81 whichApp = SWAPON_APP;
82 } else {
83 whichApp = SWAPOFF_APP; 86 whichApp = SWAPOFF_APP;
84 } 87 }
85 88
@@ -100,14 +103,13 @@ extern int swap_on_off_main(int argc, char **argv)
100 if (stat("/etc/fstab", &statBuf) < 0) 103 if (stat("/etc/fstab", &statBuf) < 0)
101 error_msg_and_die("/etc/fstab file missing"); 104 error_msg_and_die("/etc/fstab file missing");
102 } 105 }
103 do_em_all(); 106 return do_em_all();
104 break; 107 break;
105 default: 108 default:
106 goto usage_and_exit; 109 goto usage_and_exit;
107 } 110 }
108 } 111 }
109 swap_enable_disable(*argv); 112 return swap_enable_disable(*argv);
110 return EXIT_SUCCESS;
111 113
112 usage_and_exit: 114 usage_and_exit:
113 show_usage(); 115 show_usage();