Hi, Alle sabato 28 gennaio 2012, Pino Toscano ha scritto: > I implemented in swapon the -e/--ifexists option close as to what's > in util-linux' swapon. It basically ignores unexisting devices/files > when doing `swapon -a`, i.e. only for the devices found in fstab > (not for the ones passed as arguments to `swapon'. > > What do you think? > Could it be making our tools like swapon/mount/etc a bit more > compatible (in term of command line options) with the other OSes' > ones a (low priority) goal?
Patch updated (mostly improved the changelog bit in commit log). May I push it, if it is ok? Thanks, -- Pino Toscano
From 53d6602701e17e7d2ed056a3b08c015561017f22 Mon Sep 17 00:00:00 2001 From: Pino Toscano <toscano.p...@tiscali.it> Date: Mon, 24 Jun 2013 12:56:51 +0200 Subject: [PATCH] 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. --- sutils/swapon.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/sutils/swapon.c b/sutils/swapon.c index c0c773b..03b17de 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); -- 1.7.10.4
signature.asc
Description: This is a digitally signed message part.