aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/usage.h5
-rw-r--r--util-linux/Config.in7
-rw-r--r--util-linux/swaponoff.c37
3 files changed, 42 insertions, 7 deletions
diff --git a/include/usage.h b/include/usage.h
index 56198cfa5..d5c53a255 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -3809,11 +3809,14 @@
3809 "\n -a Stop swapping on all swap devices" \ 3809 "\n -a Stop swapping on all swap devices" \
3810 3810
3811#define swapon_trivial_usage \ 3811#define swapon_trivial_usage \
3812 "[-a] [DEVICE]" 3812 "[-a]" USE_FEATURE_SWAPON_PRI(" [-p pri]") " [DEVICE]"
3813#define swapon_full_usage "\n\n" \ 3813#define swapon_full_usage "\n\n" \
3814 "Start swapping on DEVICE\n" \ 3814 "Start swapping on DEVICE\n" \
3815 "\nOptions:" \ 3815 "\nOptions:" \
3816 "\n -a Start swapping on all swap devices" \ 3816 "\n -a Start swapping on all swap devices" \
3817 USE_FEATURE_SWAPON_PRI( \
3818 "\n -p pri Set swap device priority" \
3819 ) \
3817 3820
3818#define switch_root_trivial_usage \ 3821#define switch_root_trivial_usage \
3819 "[-c /dev/console] NEW_ROOT NEW_INIT [ARGUMENTS_TO_INIT]" 3822 "[-c /dev/console] NEW_ROOT NEW_INIT [ARGUMENTS_TO_INIT]"
diff --git a/util-linux/Config.in b/util-linux/Config.in
index c30091a7a..3b7630e6b 100644
--- a/util-linux/Config.in
+++ b/util-linux/Config.in
@@ -743,6 +743,13 @@ config SWAPONOFF
743 space. If you are not using any swap space, you can leave this 743 space. If you are not using any swap space, you can leave this
744 option disabled. 744 option disabled.
745 745
746config FEATURE_SWAPON_PRI
747 bool "Support option -p in swapon"
748 default n
749 depends on SWAPONOFF
750 help
751 Enable support for setting swap device priority in swapon.
752
746config SWITCH_ROOT 753config SWITCH_ROOT
747 bool "switch_root" 754 bool "switch_root"
748 default n 755 default n
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}