]> err.no Git - util-linux/commitdiff
swapon: do_swapon() refactoring (move stat() checks)
authorKarel Zak <kzak@redhat.com>
Mon, 2 Mar 2009 10:24:03 +0000 (11:24 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 2 Mar 2009 10:24:03 +0000 (11:24 +0100)
It's better to do stat() based checks immediately after the stat()
call.

Signed-off-by: Karel Zak <kzak@redhat.com>
mount/swapon.c

index 8cdb7fb1813fc03421aa61335c09034f8974b02d..d68e396530505ca82996c6c6fdd298559e694e26 100644 (file)
@@ -375,6 +375,31 @@ do_swapon(const char *orig_special, int prio, int canonic) {
                return -1;
        }
 
+       /* people generally dislike this warning - now it is printed
+          only when `verbose' is set */
+       if (verbose) {
+               int permMask = (S_ISBLK(st.st_mode) ? 07007 : 07077);
+
+               if ((st.st_mode & permMask) != 0) {
+                       fprintf(stderr, _("%s: warning: %s has "
+                                         "insecure permissions %04o, "
+                                         "%04o suggested\n"),
+                               progname, special, st.st_mode & 07777,
+                               ~permMask & 0666);
+               }
+       }
+
+       /* test for holes by LBT */
+       if (S_ISREG(st.st_mode)) {
+               if (st.st_blocks * 512 < st.st_size) {
+                       fprintf(stderr,
+                               _("%s: Skipping file %s - it appears "
+                                 "to have holes.\n"),
+                               progname, special);
+                       return -1;
+               }
+       }
+
        swap_pagesize = swap_get_pagesize(special);
        if (swap_pagesize && (getpagesize() != swap_pagesize)) {
                if (verbose)
@@ -400,30 +425,6 @@ do_swapon(const char *orig_special, int prio, int canonic) {
                        return -1;
        }
 
-       /* people generally dislike this warning - now it is printed
-          only when `verbose' is set */
-       if (verbose) {
-               int permMask = (S_ISBLK(st.st_mode) ? 07007 : 07077);
-
-               if ((st.st_mode & permMask) != 0) {
-                       fprintf(stderr, _("%s: warning: %s has "
-                                         "insecure permissions %04o, "
-                                         "%04o suggested\n"),
-                               progname, special, st.st_mode & 07777,
-                               ~permMask & 0666);
-               }
-       }
-
-       /* test for holes by LBT */
-       if (S_ISREG(st.st_mode)) {
-               if (st.st_blocks * 512 < st.st_size) {
-                       fprintf(stderr,
-                               _("%s: Skipping file %s - it appears "
-                                 "to have holes.\n"),
-                               progname, special);
-                       return -1;
-               }
-       }
 
        {
                int flags = 0;