mount: handle EDQUOT > 255 properly. closes bug 1579
[oweals/busybox.git] / util-linux / swaponoff.c
index 6eafa3e2116e638e6ad9c79dc02b3141dddd1635..f2f52fb88ebc144a22b2df224c1073ad67d2f647 100644 (file)
 #include <mntent.h>
 #include <sys/swap.h>
 
+#if ENABLE_FEATURE_MOUNT_LABEL
+# include "volume_id.h"
+#else
+# define resolve_mount_spec(fsname) ((void)0)
+#endif
+
 #if ENABLE_FEATURE_SWAPON_PRI
 struct globals {
        int flags;
-};
+} FIX_ALIASING;
 #define G (*(struct globals*)&bb_common_bufsiz1)
 #define g_flags (G.flags)
 #else
@@ -26,6 +32,7 @@ static int swap_enable_disable(char *device)
        int status;
        struct stat st;
 
+       resolve_mount_spec(&device);
        xstat(device, &st);
 
 #if ENABLE_DESKTOP
@@ -59,17 +66,26 @@ 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;
 }
 
 int swap_on_off_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int swap_on_off_main(int argc ATTRIBUTE_UNUSED, char **argv)
+int swap_on_off_main(int argc UNUSED_PARAM, char **argv)
 {
        int ret;