diff options
author | René Rhéaume <rene.rheaume@gmail.com> | 2015-01-05 20:35:00 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-01-05 20:35:00 +0100 |
commit | e76957708b6a158fd25f7298a4bf2cc5583a974a (patch) | |
tree | 50389e35f87e15f6c37bdf1f6c61399603daa7a2 /util-linux/swaponoff.c | |
parent | 1ec49732e2b477c45599f1a33953b4390e8c43e5 (diff) | |
download | busybox-w32-e76957708b6a158fd25f7298a4bf2cc5583a974a.tar.gz busybox-w32-e76957708b6a158fd25f7298a4bf2cc5583a974a.tar.bz2 busybox-w32-e76957708b6a158fd25f7298a4bf2cc5583a974a.zip |
swaponoff: add support for -e
Signed-off-by: René Rhéaume <rene.rheaume@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/swaponoff.c')
-rw-r--r-- | util-linux/swaponoff.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c index 75487267b..5cd1fbe70 100644 --- a/util-linux/swaponoff.c +++ b/util-linux/swaponoff.c | |||
@@ -8,7 +8,7 @@ | |||
8 | */ | 8 | */ |
9 | 9 | ||
10 | //usage:#define swapon_trivial_usage | 10 | //usage:#define swapon_trivial_usage |
11 | //usage: "[-a]" IF_FEATURE_SWAPON_DISCARD(" [-d[POL]]") IF_FEATURE_SWAPON_PRI(" [-p PRI]") " [DEVICE]" | 11 | //usage: "[-a] [-e]" IF_FEATURE_SWAPON_DISCARD(" [-d[POL]]") IF_FEATURE_SWAPON_PRI(" [-p PRI]") " [DEVICE]" |
12 | //usage:#define swapon_full_usage "\n\n" | 12 | //usage:#define swapon_full_usage "\n\n" |
13 | //usage: "Start swapping on DEVICE\n" | 13 | //usage: "Start swapping on DEVICE\n" |
14 | //usage: "\n -a Start swapping on all swap devices" | 14 | //usage: "\n -a Start swapping on all swap devices" |
@@ -16,15 +16,17 @@ | |||
16 | //usage: "\n -d[POL] Discard blocks at swapon (POL=once)," | 16 | //usage: "\n -d[POL] Discard blocks at swapon (POL=once)," |
17 | //usage: "\n as freed (POL=pages), or both (POL omitted)" | 17 | //usage: "\n as freed (POL=pages), or both (POL omitted)" |
18 | //usage: ) | 18 | //usage: ) |
19 | //usage: "\n -e Silently skip devices that do not exist" | ||
19 | //usage: IF_FEATURE_SWAPON_PRI( | 20 | //usage: IF_FEATURE_SWAPON_PRI( |
20 | //usage: "\n -p PRI Set swap device priority" | 21 | //usage: "\n -p PRI Set swap device priority" |
21 | //usage: ) | 22 | //usage: ) |
22 | //usage: | 23 | //usage: |
23 | //usage:#define swapoff_trivial_usage | 24 | //usage:#define swapoff_trivial_usage |
24 | //usage: "[-a] [DEVICE]" | 25 | //usage: "[-a] [-e] [DEVICE]" |
25 | //usage:#define swapoff_full_usage "\n\n" | 26 | //usage:#define swapoff_full_usage "\n\n" |
26 | //usage: "Stop swapping on DEVICE\n" | 27 | //usage: "Stop swapping on DEVICE\n" |
27 | //usage: "\n -a Stop swapping on all swap devices" | 28 | //usage: "\n -a Stop swapping on all swap devices" |
29 | //usage: "\n -e Silently skip devices that do not exist" | ||
28 | 30 | ||
29 | #include "libbb.h" | 31 | #include "libbb.h" |
30 | #include <mntent.h> | 32 | #include <mntent.h> |
@@ -77,15 +79,18 @@ struct globals { | |||
77 | /* Command line options */ | 79 | /* Command line options */ |
78 | enum { | 80 | enum { |
79 | OPTBIT_a, /* -a all */ | 81 | OPTBIT_a, /* -a all */ |
82 | OPTBIT_e, /* -e ifexists */ | ||
80 | IF_FEATURE_SWAPON_DISCARD( OPTBIT_d ,) /* -d discard */ | 83 | IF_FEATURE_SWAPON_DISCARD( OPTBIT_d ,) /* -d discard */ |
81 | IF_FEATURE_SWAPON_PRI ( OPTBIT_p ,) /* -p priority */ | 84 | IF_FEATURE_SWAPON_PRI ( OPTBIT_p ,) /* -p priority */ |
82 | OPT_a = 1 << OPTBIT_a, | 85 | OPT_a = 1 << OPTBIT_a, |
86 | OPT_e = 1 << OPTBIT_e, | ||
83 | OPT_d = IF_FEATURE_SWAPON_DISCARD((1 << OPTBIT_d)) + 0, | 87 | OPT_d = IF_FEATURE_SWAPON_DISCARD((1 << OPTBIT_d)) + 0, |
84 | OPT_p = IF_FEATURE_SWAPON_PRI ((1 << OPTBIT_p)) + 0, | 88 | OPT_p = IF_FEATURE_SWAPON_PRI ((1 << OPTBIT_p)) + 0, |
85 | }; | 89 | }; |
86 | 90 | ||
87 | #define OPT_ALL (option_mask32 & OPT_a) | 91 | #define OPT_ALL (option_mask32 & OPT_a) |
88 | #define OPT_DISCARD (option_mask32 & OPT_d) | 92 | #define OPT_DISCARD (option_mask32 & OPT_d) |
93 | #define OPT_IFEXISTS (option_mask32 & OPT_e) | ||
89 | #define OPT_PRIO (option_mask32 & OPT_p) | 94 | #define OPT_PRIO (option_mask32 & OPT_p) |
90 | 95 | ||
91 | static int swap_enable_disable(char *device) | 96 | static int swap_enable_disable(char *device) |
@@ -95,6 +100,8 @@ static int swap_enable_disable(char *device) | |||
95 | struct stat st; | 100 | struct stat st; |
96 | 101 | ||
97 | resolve_mount_spec(&device); | 102 | resolve_mount_spec(&device); |
103 | if (!OPT_IFEXISTS) | ||
104 | xstat(device, &st); | ||
98 | 105 | ||
99 | if (do_swapoff) { | 106 | if (do_swapoff) { |
100 | err = swapoff(device); | 107 | err = swapoff(device); |
@@ -112,7 +119,8 @@ static int swap_enable_disable(char *device) | |||
112 | } | 119 | } |
113 | err = swapon(device, g_flags); | 120 | err = swapon(device, g_flags); |
114 | /* Don't complain on swapon -a if device is already in use */ | 121 | /* Don't complain on swapon -a if device is already in use */ |
115 | quiet = (OPT_ALL && errno == EBUSY); | 122 | /* Don't complain if file does not exist with -e option */ |
123 | quiet = (OPT_ALL && errno == EBUSY) || (OPT_IFEXISTS && errno == ENOENT); | ||
116 | } | 124 | } |
117 | } | 125 | } |
118 | 126 | ||
@@ -229,7 +237,7 @@ static int do_all_in_proc_swaps(void) | |||
229 | return err; | 237 | return err; |
230 | } | 238 | } |
231 | 239 | ||
232 | #define OPTSTR_SWAPON "a" \ | 240 | #define OPTSTR_SWAPON "ae" \ |
233 | IF_FEATURE_SWAPON_DISCARD("d::") \ | 241 | IF_FEATURE_SWAPON_DISCARD("d::") \ |
234 | IF_FEATURE_SWAPON_PRI("p:") | 242 | IF_FEATURE_SWAPON_PRI("p:") |
235 | 243 | ||
@@ -242,7 +250,7 @@ int swap_on_off_main(int argc UNUSED_PARAM, char **argv) | |||
242 | 250 | ||
243 | INIT_G(); | 251 | INIT_G(); |
244 | 252 | ||
245 | getopt32(argv, do_swapoff ? "a" : OPTSTR_SWAPON | 253 | getopt32(argv, do_swapoff ? "ae" : OPTSTR_SWAPON |
246 | IF_FEATURE_SWAPON_DISCARD(, &discard) | 254 | IF_FEATURE_SWAPON_DISCARD(, &discard) |
247 | IF_FEATURE_SWAPON_PRI(, &prio) | 255 | IF_FEATURE_SWAPON_PRI(, &prio) |
248 | ); | 256 | ); |