diff options
author | Rob Landley <rob@landley.net> | 2005-09-13 01:30:19 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2005-09-13 01:30:19 +0000 |
commit | bc3d4a175fbbb5fc5a3bc52e79e382351b839aa7 (patch) | |
tree | 4297c45923f8fd201e9c91bb3d5d3915491cb532 /util-linux/swaponoff.c | |
parent | 5d38f5ba898c276759f1e404455aad1f3073e730 (diff) | |
download | busybox-w32-bc3d4a175fbbb5fc5a3bc52e79e382351b839aa7.tar.gz busybox-w32-bc3d4a175fbbb5fc5a3bc52e79e382351b839aa7.tar.bz2 busybox-w32-bc3d4a175fbbb5fc5a3bc52e79e382351b839aa7.zip |
Cleanup patch from Tito.
Diffstat (limited to 'util-linux/swaponoff.c')
-rw-r--r-- | util-linux/swaponoff.c | 47 |
1 files changed, 11 insertions, 36 deletions
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c index 7c7031bce..1e3fe5a43 100644 --- a/util-linux/swaponoff.c +++ b/util-linux/swaponoff.c | |||
@@ -31,12 +31,6 @@ | |||
31 | 31 | ||
32 | #include "busybox.h" | 32 | #include "busybox.h" |
33 | 33 | ||
34 | static int whichApp; /* default SWAPON_APP */ | ||
35 | |||
36 | static const int SWAPON_APP = 0; | ||
37 | static const int SWAPOFF_APP = 1; | ||
38 | |||
39 | |||
40 | static int swap_enable_disable(const char *device) | 34 | static int swap_enable_disable(const char *device) |
41 | { | 35 | { |
42 | int status; | 36 | int status; |
@@ -53,7 +47,7 @@ static int swap_enable_disable(const char *device) | |||
53 | } | 47 | } |
54 | } | 48 | } |
55 | 49 | ||
56 | if (whichApp == SWAPON_APP) | 50 | if (bb_applet_name[5] == 'n') |
57 | status = swapon(device, 0); | 51 | status = swapon(device, 0); |
58 | else | 52 | else |
59 | status = swapoff(device); | 53 | status = swapoff(device); |
@@ -62,6 +56,7 @@ static int swap_enable_disable(const char *device) | |||
62 | bb_perror_msg("%s", device); | 56 | bb_perror_msg("%s", device); |
63 | return EXIT_FAILURE; | 57 | return EXIT_FAILURE; |
64 | } | 58 | } |
59 | /*printf("%s: %s\n", bb_applet_name, device);*/ | ||
65 | return EXIT_SUCCESS; | 60 | return EXIT_SUCCESS; |
66 | } | 61 | } |
67 | 62 | ||
@@ -83,38 +78,18 @@ static int do_em_all(void) | |||
83 | return err; | 78 | return err; |
84 | } | 79 | } |
85 | 80 | ||
81 | #define DO_ALL 1 | ||
86 | 82 | ||
87 | extern int swap_on_off_main(int argc, char **argv) | 83 | extern int swap_on_off_main(int argc, char **argv) |
88 | { | 84 | { |
89 | if (bb_applet_name[5] == 'f') { /* "swapoff" */ | 85 | unsigned long opt = bb_getopt_ulflags (argc, argv, "a"); |
90 | whichApp = SWAPOFF_APP; | 86 | |
91 | } | ||
92 | |||
93 | if (argc != 2) { | 87 | if (argc != 2) { |
94 | goto usage_and_exit; | 88 | bb_show_usage(); |
95 | } | 89 | } |
96 | argc--; | 90 | |
97 | argv++; | 91 | if (opt & DO_ALL) |
98 | 92 | return do_em_all(); | |
99 | /* Parse any options */ | 93 | |
100 | while (**argv == '-') { | 94 | return swap_enable_disable(argv[1]); |
101 | while (*++(*argv)) | ||
102 | switch (**argv) { | ||
103 | case 'a': | ||
104 | { | ||
105 | struct stat statBuf; | ||
106 | |||
107 | if (stat("/etc/fstab", &statBuf) < 0) | ||
108 | bb_error_msg_and_die("/etc/fstab file missing"); | ||
109 | } | ||
110 | return do_em_all(); | ||
111 | break; | ||
112 | default: | ||
113 | goto usage_and_exit; | ||
114 | } | ||
115 | } | ||
116 | return swap_enable_disable(*argv); | ||
117 | |||
118 | usage_and_exit: | ||
119 | bb_show_usage(); | ||
120 | } | 95 | } |