Skip to contentSkip to conversation

dmsetup: detect write failure

PATCH New Jim Meyering 1 participant 1 message Mar 12, 2007 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dmsetup: detect write failure

Since "fd" may be open on a writable file handle, it's important to test for close failure. Otherwise, the code could fail to detect a write error.

2007-03-11 Jim Meyering <[email protected]>

* dmsetup/dmsetup.c (_loop_table): Detect close failure.

Index: dmsetup/dmsetup.c
===================================================================
RCS file: /cvs/dm/device-mapper/dmsetup/dmsetup.c,v retrieving revision 1.87

dmsetup.c +4 -1
diff -u -p -r1.87 dmsetup.c
@@ -1920,7 +1920,10 @@ static int _loop_table(char *table, size
 	blksize = fsbuf.f_frsize;
 #endif
 
-	close(fd);
+	if (close(fd)) {
+		fd = -1;
+		goto error;
+	}
 
 	if (dm_snprintf(table, tlen, "%llu %llu loop %s %llu\n", 0ULL,
 			(long long unsigned)sectors, file, off) < 0)