aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-06-25 15:29:12 +0000
committerlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-06-25 15:29:12 +0000
commit8e88ecc32a19c6493ce477f1fd56a76bb7d09fe9 (patch)
tree38dc2347244d1ace56adae98b04c9055b6ba1cca
parent592894bed22253fcdf0c80631cdc6442c4edfa7a (diff)
downloadbusybox-w32-8e88ecc32a19c6493ce477f1fd56a76bb7d09fe9.tar.gz
busybox-w32-8e88ecc32a19c6493ce477f1fd56a76bb7d09fe9.tar.bz2
busybox-w32-8e88ecc32a19c6493ce477f1fd56a76bb7d09fe9.zip
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. git-svn-id: svn://busybox.net/trunk/busybox@15509 69ca8d6d-28ef-0310-b511-8ec308f3f277
-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)
118 safe_strncpy((char *)loopinfo.lo_file_name, file, LO_NAME_SIZE); 118 safe_strncpy((char *)loopinfo.lo_file_name, file, LO_NAME_SIZE);
119 loopinfo.lo_offset = offset; 119 loopinfo.lo_offset = offset;
120 /* Associate free loop device with file. */ 120 /* Associate free loop device with file. */
121 if(!ioctl(dfd, LOOP_SET_FD, ffd) && 121 if(!ioctl(dfd, LOOP_SET_FD, ffd)) {
122 !ioctl(dfd, BB_LOOP_SET_STATUS, &loopinfo)) rc=0; 122 if (!ioctl(dfd, BB_LOOP_SET_STATUS, &loopinfo)) rc=0;
123 else ioctl(dfd, LOOP_CLR_FD, 0); 123 else ioctl(dfd, LOOP_CLR_FD, 0);
124 }
124 125
125 /* If this block device already set up right, re-use it. 126 /* If this block device already set up right, re-use it.
126 (Yes this is racy, but associating two loop devices with the same 127 (Yes this is racy, but associating two loop devices with the same