svn commit: trunk/busybox/libbb

landley at busybox.net landley at busybox.net
Sun Jun 25 15:29:15 UTC 2006


Author: landley
Date: 2006-06-25 08:29:12 -0700 (Sun, 25 Jun 2006)
New Revision: 15509

Log:
Fix a possible race condition if two processes try to claim the same loop
device at the same time.  We should only CLR_FD if the set status fails,
not if the SET_FD fails.


Modified:
   trunk/busybox/libbb/loop.c


Changeset:
Modified: trunk/busybox/libbb/loop.c
===================================================================
--- trunk/busybox/libbb/loop.c	2006-06-25 14:31:15 UTC (rev 15508)
+++ trunk/busybox/libbb/loop.c	2006-06-25 15:29:12 UTC (rev 15509)
@@ -118,9 +118,10 @@
 			safe_strncpy((char *)loopinfo.lo_file_name, file, LO_NAME_SIZE);
 			loopinfo.lo_offset = offset;
 			/* Associate free loop device with file.  */
-			if(!ioctl(dfd, LOOP_SET_FD, ffd) &&
-			   !ioctl(dfd, BB_LOOP_SET_STATUS, &loopinfo)) rc=0;
-			else ioctl(dfd, LOOP_CLR_FD, 0);
+			if(!ioctl(dfd, LOOP_SET_FD, ffd)) {
+			   if (!ioctl(dfd, BB_LOOP_SET_STATUS, &loopinfo)) rc=0;
+				else ioctl(dfd, LOOP_CLR_FD, 0);
+			}
 
 		/* If this block device already set up right, re-use it.
 		   (Yes this is racy, but associating two loop devices with the same




More information about the busybox-cvs mailing list