From b13154de3eca5ba28fbb4854d916cd0be5febeed Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Fri, 2 Nov 2012 20:15:39 +0400 Subject: Imported Upstream version 2.22 --- sys-utils/swapoff.c | 196 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 sys-utils/swapoff.c (limited to 'sys-utils/swapoff.c') diff --git a/sys-utils/swapoff.c b/sys-utils/swapoff.c new file mode 100644 index 0000000..0bd85ac --- /dev/null +++ b/sys-utils/swapoff.c @@ -0,0 +1,196 @@ +#include +#include +#include + +#ifdef HAVE_SYS_SWAP_H +# include +#endif + +#include "nls.h" +#include "c.h" +#include "closestream.h" + +#include "swapon-common.h" + +#ifndef SWAPON_HAS_TWO_ARGS +/* libc is insane, let's call the kernel */ +# include +# define swapoff(path) syscall(SYS_swapoff, path) +#endif + +static int verbose; +static int all; + +#define QUIET 1 +#define CANONIC 1 + +static int do_swapoff(const char *orig_special, int quiet, int canonic) +{ + const char *special = orig_special; + + if (verbose) + printf(_("swapoff %s\n"), orig_special); + + if (!canonic) { + special = mnt_resolve_spec(orig_special, mntcache); + if (!special) + return cannot_find(orig_special); + } + + if (swapoff(special) == 0) + return 0; /* success */ + + if (errno == EPERM) + errx(EXIT_FAILURE, _("Not superuser.")); + + if (!quiet || errno == ENOMEM) + warn(_("%s: swapoff failed"), orig_special); + + return -1; +} + +static int swapoff_by_label(const char *label, int quiet) +{ + const char *special = mnt_resolve_tag("LABEL", label, mntcache); + return special ? do_swapoff(special, quiet, CANONIC) : cannot_find(label); +} + +static int swapoff_by_uuid(const char *uuid, int quiet) +{ + const char *special = mnt_resolve_tag("UUID", uuid, mntcache); + return special ? do_swapoff(special, quiet, CANONIC) : cannot_find(uuid); +} + +static void __attribute__ ((__noreturn__)) usage(FILE * out) +{ + fputs(USAGE_HEADER, out); + + fprintf(out, _(" %s [options] []\n"), program_invocation_short_name); + + fputs(USAGE_OPTIONS, out); + fputs(_(" -a, --all disable all swaps from /proc/swaps\n" + " -v, --verbose verbose mode\n"), out); + + fputs(USAGE_SEPARATOR, out); + fputs(USAGE_HELP, out); + fputs(USAGE_VERSION, out); + + fputs(_("\nThe parameter:\n" \ + " -L