aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-06-25 15:29:12 +0000
committerRob Landley <rob@landley.net>2006-06-25 15:29:12 +0000
commit934da82913f70ea3c68bcbcd7b184be54c2c2061 (patch)
tree38dc2347244d1ace56adae98b04c9055b6ba1cca
parent768945b762b8850691acd2b63116eed18faa1812 (diff)
downloadbusybox-934da82913f70ea3c68bcbcd7b184be54c2c2061.tar.gz
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.
-rw-r--r--libbb/loop.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/libbb/loop.c b/libbb/loop.c
index 2f9d02924..e5b21642e 100644
--- a/libbb/loop.c
+++ b/libbb/loop.c
@@ -118,9 +118,10 @@ int set_loop(char **device, const char *file, int offset)
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