]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: check fsync() return code
authorKarel Zak <kzak@redhat.com>
Tue, 19 Apr 2022 07:44:07 +0000 (09:44 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 19 Apr 2022 07:44:07 +0000 (09:44 +0200)
Since 39f5af25982d8b0244000e92a9d0e0e6557d0e17 libblkid uses
O_NONBLOCK. Now it's more obvious that check fsync() (and close())
return value after write() is always a good idea ...

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2074486
Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/probe.c
misc-utils/wipefs.c

index 31706240fc28a722d30478a9d6e88ea433cad5ec..4f6604fa3574a561369671663dc641af0acd4324 100644 (file)
@@ -1414,7 +1414,8 @@ int blkid_do_wipe(blkid_probe pr, int dryrun)
                        /* wipen on device */
                        if (write_all(fd, buf, len))
                                return -1;
-                       fsync(fd);
+                       if (fsync(fd) != 0)
+                               return -1;
                } else {
 #ifdef HAVE_LINUX_BLKZONED_H
                        uint64_t zone_mask = ~(pr->zone_size - 1);
index 8cdc0a7ebe459398bee9533d5a8302a84456bab7..6be470bbbaae3093d49cdd06e730dd22b1407240 100644 (file)
@@ -593,7 +593,9 @@ static int do_wipe(struct wipe_control *ctl)
        if (need_force)
                warnx(_("Use the --force option to force erase."));
 
-       fsync(blkid_probe_get_fd(pr));
+       if (fsync(blkid_probe_get_fd(pr)) != 0)
+               err(EXIT_FAILURE, _("%s: cannot flush modified buffers"),
+                               ctl->devname);
 
 #ifdef BLKRRPART
        if (reread && (mode & O_EXCL)) {
@@ -613,7 +615,9 @@ static int do_wipe(struct wipe_control *ctl)
        }
 #endif
 
-       close(blkid_probe_get_fd(pr));
+       if (close(blkid_probe_get_fd(pr)) != 0)
+               err(EXIT_FAILURE, _("%s: close device failed"), ctl->devname);
+
        blkid_free_probe(pr);
        free(backup);
        return 0;