From: Lennart Poettering Date: Tue, 5 Apr 2022 21:34:44 +0000 (+0200) Subject: loop-util: explicitly close loopback block device before sleeping X-Git-Tag: v251-rc2~165^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3e9210577dbe78b3c0cc9a8b0488c51f7339dd02;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c index 257af7340f0..073755fb9e2 100644 --- a/src/shared/loop-util.c +++ b/src/shared/loop-util.c @@ -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