From e42270b6a695b4aaf324d4570744f4b289184718 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 5 Sep 2022 03:04:07 +0900 Subject: loop-util: lock_fd must be closed before calling LOOP_CLR_FD Follow-up for 7f52206a2bc128f9ae8306db43aa6e2f7d916f82. C.f. 87862cc2b4abb9564f7e0365ac515dc9020a54e4. --- src/shared/loop-util.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/shared/loop-util.c') 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) -- cgit v1.2.1