diff options
author | Pino Toscano <toscano.pino@tiscali.it> | 2013-07-01 12:19:49 +0200 |
---|---|---|
committer | Pino Toscano <toscano.pino@tiscali.it> | 2013-07-01 12:19:49 +0200 |
commit | 99a035e0d824aaddea8b9064f7035f29f26ceaa0 (patch) | |
tree | 61e5a65966733a68ffde0c96bec711a4e613cf76 /sutils | |
parent | b82f12741cffd5498b5ea2e87cc4fb809969d2ee (diff) |
swapon: add -e/--ifexists option
Add the same command line option as in util-linux' swapon to not
consider an error if the device/file of a swap entry in fstab does not
exist (and not when activating a device specified as argument to
`swapon').
* sutils/swapon.c (ifexists): New variable.
(options): Add the 'e' option.
(parse_opt) <'e'>: Handle case.
(swaponoff): New argument skipnotexisting.
Return 0 if open_store fails with ENOENT and SKIPNOTEXISTING is on.
(main): Adapt swaponoff calls with 0 as parameter for command line
arguments, and IFEXISTS for swap entries from fstab.
Diffstat (limited to 'sutils')
-rw-r--r-- | sutils/swapon.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/sutils/swapon.c b/sutils/swapon.c index c0c773bd..03b17de8 100644 --- a/sutils/swapon.c +++ b/sutils/swapon.c @@ -42,12 +42,14 @@ const char *argp_program_version = STANDARD_HURD_VERSION (swapoff); const char *argp_program_version = STANDARD_HURD_VERSION (swapon); #endif -static int ignore_signature, require_signature, quiet; +static int ignore_signature, require_signature, quiet, ifexists; static struct argp_option options[] = { {"standard", 'a', 0, 0, "Use all devices marked as `swap' in " _PATH_MNTTAB}, + {"ifexists", 'e', 0, 0, + "Silently skip devices that do not exist"}, {"no-signature",'n', 0, 0, "Do not check for a Linux swap signature page"}, {"require-signature", 's', 0, 0, @@ -319,7 +321,7 @@ check_signature (const char *name, struct store **storep, int no_remap, /* Process a single argument file. */ static int -swaponoff (const char *file, int add) +swaponoff (const char *file, int add, int skipnotexisting) { error_t err; struct store *store; @@ -332,6 +334,10 @@ swaponoff (const char *file, int add) err = store_open (file, 0, 0, &store); if (err) { + /* If the device does not exist but we were told to ignore such error, + return cleanly. */ + if (err == ENOENT && skipnotexisting) + return 0; error (0, err, "%s", file); return err; } @@ -467,6 +473,10 @@ main (int argc, char *argv[]) do_all = 1; break; + case 'e': + ifexists = 1; + break; + case 'n': ignore_signature = 1; break; @@ -486,7 +496,7 @@ main (int argc, char *argv[]) #else #define ONOFF 1 #endif - swaponoff (arg, ONOFF); + swaponoff (arg, ONOFF, 0); break; default: @@ -523,7 +533,7 @@ main (int argc, char *argv[]) { done = 1; - err |= swaponoff (me->mnt_fsname, ONOFF); + err |= swaponoff (me->mnt_fsname, ONOFF, ifexists); } if (done == 0) error (2, 0, "No swap partitions found in %s", _PATH_MNTTAB); |