[git commit] swapon/swapoff: refine the -e (ifexists) option
Mike Frysinger
vapier at gentoo.org
Wed Dec 16 17:59:08 UTC 2015
commit: http://git.busybox.net/busybox/commit/?id=5f11ec3f6a7e4fe6cc2626ccb7cda4ecb5c3938a
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master
The -e option should only apply to swapon, and it should swallow all
errors/warnings when the device does not exist. So delete the flag
from the swapoff patch and unify the check in the swapoff path.
Signed-off-by: Mike Frysinger <vapier at gentoo.org>
---
util-linux/swaponoff.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c
index 5cd1fbe..7e548a4 100644
--- a/util-linux/swaponoff.c
+++ b/util-linux/swaponoff.c
@@ -22,11 +22,10 @@
//usage: )
//usage:
//usage:#define swapoff_trivial_usage
-//usage: "[-a] [-e] [DEVICE]"
+//usage: "[-a] [DEVICE]"
//usage:#define swapoff_full_usage "\n\n"
//usage: "Stop swapping on DEVICE\n"
//usage: "\n -a Stop swapping on all swap devices"
-//usage: "\n -e Silently skip devices that do not exist"
#include "libbb.h"
#include <mntent.h>
@@ -93,15 +92,12 @@ enum {
#define OPT_IFEXISTS (option_mask32 & OPT_e)
#define OPT_PRIO (option_mask32 & OPT_p)
-static int swap_enable_disable(char *device)
+static int swap_enable_disable(const char *device)
{
int err = 0;
int quiet = 0;
- struct stat st;
resolve_mount_spec(&device);
- if (!OPT_IFEXISTS)
- xstat(device, &st);
if (do_swapoff) {
err = swapoff(device);
@@ -109,6 +105,7 @@ static int swap_enable_disable(char *device)
quiet = (OPT_ALL && (errno == EINVAL || errno == ENOENT));
} else {
/* swapon */
+ struct stat st;
err = stat(device, &st);
if (!err) {
if (ENABLE_DESKTOP && S_ISREG(st.st_mode)) {
@@ -119,9 +116,11 @@ static int swap_enable_disable(char *device)
}
err = swapon(device, g_flags);
/* Don't complain on swapon -a if device is already in use */
- /* Don't complain if file does not exist with -e option */
- quiet = (OPT_ALL && errno == EBUSY) || (OPT_IFEXISTS && errno == ENOENT);
+ quiet = (OPT_ALL && errno == EBUSY);
}
+ /* Don't complain if file does not exist with -e option */
+ if (err && OPT_IFEXISTS && errno == ENOENT)
+ err = 0;
}
if (err && !quiet) {
More information about the busybox-cvs
mailing list