*
* 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>
#if ENABLE_FEATURE_SWAPON_PRI
struct globals {
int flags;
-};
+} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
#define g_flags (G.flags)
#else
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;
}