aboutsummaryrefslogtreecommitdiff
path: root/util-linux/swaponoff.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-05-18 23:05:34 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-05-18 23:05:34 +0000
commitee56e013cfb6304f66129afee7978b0864699419 (patch)
tree367b176fc97757fea9322871d8aaf629239e2038 /util-linux/swaponoff.c
parent5599502a550a7f892d4b73dceb2105a6916f83e6 (diff)
downloadbusybox-w32-ee56e013cfb6304f66129afee7978b0864699419.tar.gz
busybox-w32-ee56e013cfb6304f66129afee7978b0864699419.tar.bz2
busybox-w32-ee56e013cfb6304f66129afee7978b0864699419.zip
swapon: optional -p PRIO support (by Francois Barel <frabar666 AT gmail.com>)
function old new delta swap_on_off_main 153 216 +63 packed_usage 24190 24214 +24 swap_enable_disable 127 131 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 91/0) Total: 91 bytes
Diffstat (limited to 'util-linux/swaponoff.c')
-rw-r--r--util-linux/swaponoff.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c
index beefac030..6eafa3e21 100644
--- a/util-linux/swaponoff.c
+++ b/util-linux/swaponoff.c
@@ -11,6 +11,16 @@
11#include <mntent.h> 11#include <mntent.h>
12#include <sys/swap.h> 12#include <sys/swap.h>
13 13
14#if ENABLE_FEATURE_SWAPON_PRI
15struct globals {
16 int flags;
17};
18#define G (*(struct globals*)&bb_common_bufsiz1)
19#define g_flags (G.flags)
20#else
21#define g_flags 0
22#endif
23
14static int swap_enable_disable(char *device) 24static int swap_enable_disable(char *device)
15{ 25{
16 int status; 26 int status;
@@ -26,7 +36,7 @@ static int swap_enable_disable(char *device)
26#endif 36#endif
27 37
28 if (applet_name[5] == 'n') 38 if (applet_name[5] == 'n')
29 status = swapon(device, 0); 39 status = swapon(device, g_flags);
30 else 40 else
31 status = swapoff(device); 41 status = swapoff(device);
32 42
@@ -63,15 +73,30 @@ int swap_on_off_main(int argc ATTRIBUTE_UNUSED, char **argv)
63{ 73{
64 int ret; 74 int ret;
65 75
66 if (!argv[1]) 76#if !ENABLE_FEATURE_SWAPON_PRI
67 bb_show_usage();
68
69 ret = getopt32(argv, "a"); 77 ret = getopt32(argv, "a");
70 if (ret) 78#else
79 opt_complementary = "p+";
80 ret = getopt32(argv, (applet_name[5] == 'n') ? "ap:" : "a", &g_flags);
81
82 if (ret & 2) { // -p
83 g_flags = SWAP_FLAG_PREFER |
84 ((g_flags & SWAP_FLAG_PRIO_MASK) << SWAP_FLAG_PRIO_SHIFT);
85 ret &= 1;
86 }
87#endif
88
89 if (ret /* & 1: not needed */) // -a
71 return do_em_all(); 90 return do_em_all();
72 91
92 argv += optind;
93 if (!*argv)
94 bb_show_usage();
95
73 /* ret = 0; redundant */ 96 /* ret = 0; redundant */
74 while (*++argv) 97 do {
75 ret += swap_enable_disable(*argv); 98 ret += swap_enable_disable(*argv);
99 } while (*++argv);
100
76 return ret; 101 return ret;
77} 102}