loop-util: explicitly close loopback block device before sleeping

attach_empty() file takes a BSD file lock on the device, and we really
should release that before going to sleep. hence explicitly close the
block device before the sleep instead of relying on _cleanup_ to close
it after the sleep.
This commit is contained in:
Lennart Poettering
2022-04-07 18:55:58 +02:00
parent 49043f8115
commit 3e9210577d
+3
View File
@@ -561,6 +561,9 @@ static int loop_device_make_internal(
if (++n_attempts >= 64) /* Give up eventually */
return -EBUSY;
/* Now close the loop device explicitly. This will release any lock acquired by
* attach_empty_file() or similar, while we sleep below. */
loop = safe_close(loop);
loopdev = mfree(loopdev);
/* Wait some random time, to make collision less likely. Let's pick a random time in the