Karel Zak 18b0e4
From f02e9004303df5ab3d9b868f6f60af44663cce69 Mon Sep 17 00:00:00 2001
Karel Zak 18b0e4
From: Karel Zak <kzak@redhat.com>
Karel Zak 18b0e4
Date: Tue, 19 Apr 2022 09:44:07 +0200
Karel Zak 18b0e4
Subject: libblkid: check fsync() return code
Karel Zak 18b0e4
Karel Zak 18b0e4
Since 39f5af25982d8b0244000e92a9d0e0e6557d0e17 libblkid uses
Karel Zak 18b0e4
O_NONBLOCK. Now it's more obvious that check fsync() (and close())
Karel Zak 18b0e4
return value after write() is always a good idea ...
Karel Zak 18b0e4
Karel Zak 18b0e4
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2074486
Karel Zak 18b0e4
Upstream: http://github.com/util-linux/util-linux/commit/133a0d70f637b4f4e4337811e452153b04f2bdcf
Karel Zak 18b0e4
Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak 18b0e4
---
Karel Zak 18b0e4
 libblkid/src/probe.c | 5 ++++-
Karel Zak 18b0e4
 misc-utils/wipefs.c  | 8 ++++++--
Karel Zak 18b0e4
 2 files changed, 10 insertions(+), 3 deletions(-)
Karel Zak 18b0e4
Karel Zak 18b0e4
diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c
Karel Zak 18b0e4
index 5f01bc3b3..d317dc19a 100644
Karel Zak 18b0e4
--- a/libblkid/src/probe.c
Karel Zak 18b0e4
+++ b/libblkid/src/probe.c
Karel Zak 18b0e4
@@ -1298,7 +1298,10 @@ int blkid_do_wipe(blkid_probe pr, int dryrun)
Karel Zak 18b0e4
 		/* wipen on device */
Karel Zak 18b0e4
 		if (write_all(fd, buf, len))
Karel Zak 18b0e4
 			return -1;
Karel Zak 18b0e4
-		fsync(fd);
Karel Zak 18b0e4
+
Karel Zak 18b0e4
+		if (fsync(fd) != 0)
Karel Zak 18b0e4
+			return -1;
Karel Zak 18b0e4
+
Karel Zak 18b0e4
 		pr->flags &= ~BLKID_FL_MODIF_BUFF;	/* be paranoid */
Karel Zak 18b0e4
 
Karel Zak 18b0e4
 		return blkid_probe_step_back(pr);
Karel Zak 18b0e4
diff --git a/misc-utils/wipefs.c b/misc-utils/wipefs.c
Karel Zak 18b0e4
index 78dc63ee7..f08a9ba4f 100644
Karel Zak 18b0e4
--- a/misc-utils/wipefs.c
Karel Zak 18b0e4
+++ b/misc-utils/wipefs.c
Karel Zak 18b0e4
@@ -615,7 +615,9 @@ static int do_wipe(struct wipe_control *ctl)
Karel Zak 18b0e4
 	if (need_force)
Karel Zak 18b0e4
 		warnx(_("Use the --force option to force erase."));
Karel Zak 18b0e4
 
Karel Zak 18b0e4
-	fsync(blkid_probe_get_fd(pr));
Karel Zak 18b0e4
+	if (fsync(blkid_probe_get_fd(pr)) != 0)
Karel Zak 18b0e4
+		err(EXIT_FAILURE, _("%s: cannot flush modified buffers"),
Karel Zak 18b0e4
+				ctl->devname);
Karel Zak 18b0e4
 
Karel Zak 18b0e4
 #ifdef BLKRRPART
Karel Zak 18b0e4
 	if (reread && (mode & O_EXCL)) {
Karel Zak 18b0e4
@@ -635,7 +637,9 @@ static int do_wipe(struct wipe_control *ctl)
Karel Zak 18b0e4
 	}
Karel Zak 18b0e4
 #endif
Karel Zak 18b0e4
 
Karel Zak 18b0e4
-	close(blkid_probe_get_fd(pr));
Karel Zak 18b0e4
+	if (close(blkid_probe_get_fd(pr)) != 0)
Karel Zak 18b0e4
+		err(EXIT_FAILURE, _("%s: close device failed"), ctl->devname);
Karel Zak 18b0e4
+
Karel Zak 18b0e4
 	blkid_free_probe(pr);
Karel Zak 18b0e4
 	free(backup);
Karel Zak 18b0e4
 	return 0;
Karel Zak 18b0e4
-- 
Karel Zak 18b0e4
2.36.1
Karel Zak 18b0e4