summaryrefslogtreecommitdiff
path: root/src/shared/loop-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-09-05 03:04:07 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-09-05 04:31:47 +0900
commite42270b6a695b4aaf324d4570744f4b289184718 (patch)
tree3d3f2f06747b541153342f5daf6700fe34d9af70 /src/shared/loop-util.c
parent9bf8600774689d34cfa5172c6eaba2093e095e23 (diff)
downloadsystemd-e42270b6a695b4aaf324d4570744f4b289184718.tar.gz
loop-util: lock_fd must be closed before calling LOOP_CLR_FD
Follow-up for 7f52206a2bc128f9ae8306db43aa6e2f7d916f82. C.f. 87862cc2b4abb9564f7e0365ac515dc9020a54e4.
Diffstat (limited to 'src/shared/loop-util.c')
-rw-r--r--src/shared/loop-util.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c
index 3cc72b65a0..ed237c6f20 100644
--- a/src/shared/loop-util.c
+++ b/src/shared/loop-util.c
@@ -357,7 +357,7 @@ static int loop_device_make_internal(
int lock_op,
LoopDevice **ret) {
- _cleanup_close_ int direct_io_fd = -1, lock_fd = -1;
+ _cleanup_close_ int direct_io_fd = -1;
_cleanup_free_ char *node = NULL;
bool try_loop_configure = true;
struct loop_config config;
@@ -410,8 +410,10 @@ static int loop_device_make_internal(
fd = direct_io_fd; /* From now on, operate on our new O_DIRECT fd */
}
+ /* On failure, lock_fd must be closed at first, otherwise LOOP_CLR_FD will fail. */
_cleanup_close_ int control = -1;
_cleanup_(cleanup_clear_loop_close) int loop_with_fd = -1;
+ _cleanup_close_ int lock_fd = -1;
control = open("/dev/loop-control", O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
if (control < 0)