*: remove "Options:" string from help texts
[oweals/busybox.git] / util-linux / swaponoff.c
index 33ad00ac13c8a3f4bab6f33850b54bd9c805bce7..dbefa4cf2cab9884b4bef7b25f4cd249856813e7 100644 (file)
@@ -4,9 +4,24 @@
  *
  * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  *
- * Licensed under the GPL version 2, see the file LICENSE in this tarball.
+ * Licensed under GPLv2, see file LICENSE in this source tree.
  */
 
+//usage:#define swapon_trivial_usage
+//usage:       "[-a]" IF_FEATURE_SWAPON_PRI(" [-p PRI]") " [DEVICE]"
+//usage:#define swapon_full_usage "\n\n"
+//usage:       "Start swapping on DEVICE\n"
+//usage:     "\n       -a      Start swapping on all swap devices"
+//usage:       IF_FEATURE_SWAPON_PRI(
+//usage:     "\n       -p PRI  Set swap device priority"
+//usage:       )
+//usage:
+//usage:#define swapoff_trivial_usage
+//usage:       "[-a] [DEVICE]"
+//usage:#define swapoff_full_usage "\n\n"
+//usage:       "Stop swapping on DEVICE\n"
+//usage:     "\n       -a      Stop swapping on all swap devices"
+
 #include "libbb.h"
 #include <mntent.h>
 #include <sys/swap.h>
@@ -20,7 +35,7 @@
 #if ENABLE_FEATURE_SWAPON_PRI
 struct globals {
        int flags;
-};
+} FIX_ALIASING;
 #define G (*(struct globals*)&bb_common_bufsiz1)
 #define g_flags (G.flags)
 #else
@@ -66,11 +81,20 @@ static int do_em_all(void)
                bb_perror_msg_and_die("/etc/fstab");
 
        err = 0;
-       while ((m = getmntent(f)) != NULL)
-               if (strcmp(m->mnt_type, MNTTYPE_SWAP) == 0)
-                       err += swap_enable_disable(m->mnt_fsname);
+       while ((m = getmntent(f)) != NULL) {
+               if (strcmp(m->mnt_type, MNTTYPE_SWAP) == 0) {
+                       /* swapon -a should ignore entries with noauto,
+                        * but swapoff -a should process them */
+                       if (applet_name[5] != 'n'
+                        || hasmntopt(m, MNTOPT_NOAUTO) == NULL
+                       ) {
+                               err += swap_enable_disable(m->mnt_fsname);
+                       }
+               }
+       }
 
-       endmntent(f);
+       if (ENABLE_FEATURE_CLEAN_UP)
+               endmntent(f);
 
        return err;
 }