aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--util-linux/swaponoff.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c
index 5cd1fbe70..7e548a464 100644
--- a/util-linux/swaponoff.c
+++ b/util-linux/swaponoff.c
@@ -22,11 +22,10 @@
22//usage: ) 22//usage: )
23//usage: 23//usage:
24//usage:#define swapoff_trivial_usage 24//usage:#define swapoff_trivial_usage
25//usage: "[-a] [-e] [DEVICE]" 25//usage: "[-a] [DEVICE]"
26//usage:#define swapoff_full_usage "\n\n" 26//usage:#define swapoff_full_usage "\n\n"
27//usage: "Stop swapping on DEVICE\n" 27//usage: "Stop swapping on DEVICE\n"
28//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"
30 29
31#include "libbb.h" 30#include "libbb.h"
32#include <mntent.h> 31#include <mntent.h>
@@ -93,15 +92,12 @@ enum {
93#define OPT_IFEXISTS (option_mask32 & OPT_e) 92#define OPT_IFEXISTS (option_mask32 & OPT_e)
94#define OPT_PRIO (option_mask32 & OPT_p) 93#define OPT_PRIO (option_mask32 & OPT_p)
95 94
96static int swap_enable_disable(char *device) 95static int swap_enable_disable(const char *device)
97{ 96{
98 int err = 0; 97 int err = 0;
99 int quiet = 0; 98 int quiet = 0;
100 struct stat st;
101 99
102 resolve_mount_spec(&device); 100 resolve_mount_spec(&device);
103 if (!OPT_IFEXISTS)
104 xstat(device, &st);
105 101
106 if (do_swapoff) { 102 if (do_swapoff) {
107 err = swapoff(device); 103 err = swapoff(device);
@@ -109,6 +105,7 @@ static int swap_enable_disable(char *device)
109 quiet = (OPT_ALL && (errno == EINVAL || errno == ENOENT)); 105 quiet = (OPT_ALL && (errno == EINVAL || errno == ENOENT));
110 } else { 106 } else {
111 /* swapon */ 107 /* swapon */
108 struct stat st;
112 err = stat(device, &st); 109 err = stat(device, &st);
113 if (!err) { 110 if (!err) {
114 if (ENABLE_DESKTOP && S_ISREG(st.st_mode)) { 111 if (ENABLE_DESKTOP && S_ISREG(st.st_mode)) {
@@ -119,9 +116,11 @@ static int swap_enable_disable(char *device)
119 } 116 }
120 err = swapon(device, g_flags); 117 err = swapon(device, g_flags);
121 /* Don't complain on swapon -a if device is already in use */ 118 /* Don't complain on swapon -a if device is already in use */
122 /* Don't complain if file does not exist with -e option */ 119 quiet = (OPT_ALL && errno == EBUSY);
123 quiet = (OPT_ALL && errno == EBUSY) || (OPT_IFEXISTS && errno == ENOENT);
124 } 120 }
121 /* Don't complain if file does not exist with -e option */
122 if (err && OPT_IFEXISTS && errno == ENOENT)
123 err = 0;
125 } 124 }
126 125
127 if (err && !quiet) { 126 if (err && !quiet) {