From 88530f9f24fba89fb8f0b9f014a1bf945caa9312 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 2 Mar 2009 11:24:03 +0100 Subject: [PATCH] swapon: do_swapon() refactoring (move stat() checks) It's better to do stat() based checks immediately after the stat() call. Signed-off-by: Karel Zak --- mount/swapon.c | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/mount/swapon.c b/mount/swapon.c index 8cdb7fb1..d68e3965 100644 --- a/mount/swapon.c +++ b/mount/swapon.c @@ -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; -- 2.39.5