]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mkswap: unify write check to a file descriptor
authorSami Kerola <kerolasa@iki.fi>
Sat, 13 Apr 2013 19:54:56 +0000 (20:54 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 26 Apr 2013 11:26:07 +0000 (13:26 +0200)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
disk-utils/mkswap.c

index ec6fc5f9934c0fe37c9bc1ee188ed4b3fdca493c..71503f4462a025387798393bc0d40f311a23d38c 100644 (file)
@@ -625,15 +625,6 @@ main(int argc, char **argv) {
                        _("%s: unable to write signature page"),
                        device_name);
 
-       /*
-        * A subsequent swapon() will fail if the signature
-        * is not actually on disk. (This is a kernel bug.)
-        */
-#ifdef HAVE_FSYNC
-       if (fsync(DEV))
-               errx(EXIT_FAILURE, _("fsync failed"));
-#endif
-
 #ifdef HAVE_LIBSELINUX
        if (S_ISREG(statbuf.st_mode) && is_selinux_enabled() > 0) {
                security_context_t context_string;
@@ -664,5 +655,12 @@ main(int argc, char **argv) {
                freecon(oldcontext);
        }
 #endif
+       /*
+        * A subsequent swapon() will fail if the signature
+        * is not actually on disk. (This is a kernel bug.)
+        * The fsync() in close_fd() will take care of writing.
+        */
+       if (close_fd(DEV) != 0)
+               err(EXIT_FAILURE, _("write failed"));
        return EXIT_SUCCESS;
 }