diff options
-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); | |||
39 | 39 | ||
40 | #include "busybox.h" | 40 | #include "busybox.h" |
41 | 41 | ||
42 | static int whichApp; | 42 | static int whichApp; /* default SWAPON_APP */ |
43 | 43 | ||
44 | static const int SWAPON_APP = 1; | 44 | static const int SWAPON_APP = 0; |
45 | static const int SWAPOFF_APP = 2; | 45 | static const int SWAPOFF_APP = 1; |
46 | 46 | ||
47 | 47 | ||
48 | static void swap_enable_disable(char *device) | 48 | static 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 | ||
61 | static void do_em_all(void) | 64 | static 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 | ||
78 | extern int swap_on_off_main(int argc, char **argv) | 83 | extern 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(); |