]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - sys-utils/swapoff.c
Merge branch 'topic/wdctl'
[thirdparty/util-linux.git] / sys-utils / swapoff.c
index e20c502bde608abda61cb13e6379a6872177be62..a13d4f1e582385af7f2bd44e9fadd3e914720d9f 100644 (file)
@@ -14,8 +14,7 @@
 #include "swapprober.h"
 #include "swapon-common.h"
 
-#ifndef SWAPON_HAS_TWO_ARGS
-/* libc is insane, let's call the kernel */
+#if !defined(HAVE_SWAPOFF) && defined(SYS_swapoff)
 # include <sys/syscall.h>
 # define swapoff(path) syscall(SYS_swapoff, path)
 #endif
@@ -116,8 +115,9 @@ static int swapoff_by(const char *name, const char *value, int quiet)
        return special ? do_swapoff(special, quiet, CANONIC) : cannot_find(value);
 }
 
-static void __attribute__ ((__noreturn__)) usage(FILE * out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
        fputs(USAGE_HEADER, out);
        fprintf(out, _(" %s [options] [<spec>]\n"), program_invocation_short_name);
 
@@ -129,8 +129,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
                " -v, --verbose          verbose mode\n"), out);
 
        fputs(USAGE_SEPARATOR, out);
-       fputs(USAGE_HELP, out);
-       fputs(USAGE_VERSION, out);
+       printf(USAGE_HELP_OPTIONS(24));
 
        fputs(_("\nThe <spec> parameter:\n" \
                " -L <label>             LABEL of device to be used\n" \
@@ -140,8 +139,8 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
                " <device>               name of device to be used\n" \
                " <file>                 name of file to be used\n"), out);
 
-       fprintf(out, USAGE_MAN_TAIL("swapoff(8)"));
-       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+       printf(USAGE_MAN_TAIL("swapoff(8)"));
+       exit(EXIT_SUCCESS);
 }
 
 static int swapoff_all(void)
@@ -188,17 +187,17 @@ int main(int argc, char *argv[])
        size_t i;
 
        static const struct option long_opts[] = {
-               { "all", 0, 0, 'a' },
-               { "help", 0, 0, 'h' },
-               { "verbose", 0, 0, 'v' },
-               { "version", 0, 0, 'V' },
-               { NULL, 0, 0, 0 }
+               { "all",     no_argument, NULL, 'a' },
+               { "help",    no_argument, NULL, 'h' },
+               { "verbose", no_argument, NULL, 'v' },
+               { "version", no_argument, NULL, 'V' },
+               { NULL, 0, NULL, 0 }
        };
 
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
-       atexit(close_stdout);
+       close_stdout_atexit();
 
        while ((c = getopt_long(argc, argv, "ahvVL:U:",
                                 long_opts, NULL)) != -1) {
@@ -206,29 +205,30 @@ int main(int argc, char *argv[])
                case 'a':               /* all */
                        ++all;
                        break;
-               case 'h':               /* help */
-                       usage(stdout);
-                       break;
                case 'v':               /* be chatty */
                        ++verbose;
                        break;
-               case 'V':               /* version */
-                       printf(UTIL_LINUX_VERSION);
-                       return EXIT_SUCCESS;
                case 'L':
                        add_label(optarg);
                        break;
                case 'U':
                        add_uuid(optarg);
                        break;
+
+               case 'h':               /* help */
+                       usage();
+               case 'V':               /* version */
+                       print_version(EXIT_SUCCESS);
                default:
                        errtryhelp(EXIT_FAILURE);
                }
        }
        argv += optind;
 
-       if (!all && !numof_labels() && !numof_uuids() && *argv == NULL)
-               usage(stderr);
+       if (!all && !numof_labels() && !numof_uuids() && *argv == NULL) {
+               warnx(_("bad usage"));
+               errtryhelp(EXIT_FAILURE);
+       }
 
        mnt_init_debug(0);
        mntcache = mnt_new_cache();