From 95f1bdeee42cd7b9ac49d64b27bcec49557a991e Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 7 Dec 2006 00:26:05 +0100 Subject: Imported from util-linux-2.11x tarball. --- mount/swapon.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'mount/swapon.c') diff --git a/mount/swapon.c b/mount/swapon.c index c2ae20a9e..443ae3c57 100644 --- a/mount/swapon.c +++ b/mount/swapon.c @@ -8,8 +8,12 @@ * - added Native Language Support * 1999-03-21 Arnaldo Carvalho de Melo * - fixed strerr(errno) in gettext calls + * 2001-03-22 Erik Troan + * - added -e option for -a + * - -a shouldn't try to add swaps that are already enabled */ +#include #include #include #include @@ -34,12 +38,16 @@ int all = 0; int verbose = 0; int priority = -1; /* non-prioritized swap by default */ +/* If true, don't complain if the device/file doesn't exist */ +int ifexists = 0; + extern char version[]; static char *program_name; static struct option longswaponopts[] = { /* swapon only */ { "priority", required_argument, 0, 'p' }, + { "ifexists", 0, 0, 'e' }, { "summary", 0, 0, 's' }, /* also for swapoff */ { "all", 0, 0, 'a' }, @@ -54,7 +62,7 @@ static struct option *longswapoffopts = &longswaponopts[2]; static void swapon_usage(FILE *fp, int n) { fprintf(fp, _("usage: %s [-hV]\n" - " %s -a [-v]\n" + " %s -a [-e] [-v]\n" " %s [-v] [-p priority] special ...\n" " %s [-s]\n"), program_name, program_name, program_name, program_name); @@ -256,7 +264,7 @@ main_swapon(int argc, char *argv[]) { int status = 0; int c; - while ((c = getopt_long(argc, argv, "ahp:svV", + while ((c = getopt_long(argc, argv, "ahep:svV", longswaponopts, NULL)) != -1) { switch (c) { case 'a': /* all */ @@ -268,6 +276,9 @@ main_swapon(int argc, char *argv[]) { case 'p': /* priority */ priority = atoi(optarg); break; + case 'e': /* ifexists */ + ifexists = 1; + break; case 's': /* status report */ status = display_summary(); exit(status); @@ -289,6 +300,9 @@ main_swapon(int argc, char *argv[]) { if (!all && *argv == NULL) swapon_usage(stderr, 2); + if (ifexists && (!all || strcmp(program_name, "swapon"))) + swapon_usage(stderr, 1); + if (all) { read_proc_swaps(); @@ -303,7 +317,8 @@ main_swapon(int argc, char *argv[]) { char *special = fstab->mnt_fsname; if (streq(fstab->mnt_type, MNTTYPE_SWAP) && - !is_in_proc_swaps(special)) { + !is_in_proc_swaps(special) + && (!ifexists || !access(special, R_OK))) { /* parse mount options; */ char *opt, *opts = strdup(fstab->mnt_opts); -- cgit v1.2.3-55-g7522