From: Lennart Poettering Date: Thu, 1 Sep 2022 13:42:32 +0000 (+0200) Subject: loop-util: close lock fd before trying LOOP_CLR_FD in failure path X-Git-Tag: v252-rc1~275^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=87862cc2b4abb9564f7e0365ac515dc9020a54e4;p=thirdparty%2Fsystemd.git loop-util: close lock fd before trying LOOP_CLR_FD in failure path If the loopback device is open more than once LOOP_CLR_FD will fail, hence close the lock fd first explicitly, so there's definitely only one fd left. --- diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c index 81682994de6..6cb370e9507 100644 --- a/src/shared/loop-util.c +++ b/src/shared/loop-util.c @@ -341,6 +341,9 @@ success: return 0; fail: + /* Close the lock fd explicitly before clearing the loopback block device, since an additional open + * fd would block the clearing to succeed */ + lock_fd = safe_close(lock_fd); (void) ioctl(fd, LOOP_CLR_FD); return r; }