From: Daan De Meyer Date: Mon, 24 Nov 2025 10:53:12 +0000 (+0100) Subject: test-reread-partition-table: Don't keep open fds around X-Git-Tag: v259-rc2~35^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e910f9bc63356ccaca6d87bd62fd79d36b1cccd4;p=thirdparty%2Fsystemd.git test-reread-partition-table: Don't keep open fds around Avoids EBUSY from BLKRRPART when built without libblkid support. --- diff --git a/src/test/test-reread-partition-table.c b/src/test/test-reread-partition-table.c index f6234f0f8a4..f171d1737a8 100644 --- a/src/test/test-reread-partition-table.c +++ b/src/test/test-reread-partition-table.c @@ -97,11 +97,12 @@ TEST(rereadpt) { ASSERT_OK_ZERO_ERRNO(access(p, F_OK)); - _cleanup_close_ int pfd = open(p, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY); - ASSERT_OK_ERRNO(pfd); + _cleanup_close_ int pfd = -EBADF; + ASSERT_OK_ERRNO(pfd = open(p, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY)); uint64_t size; ASSERT_OK(blockdev_get_device_size(pfd, &size)); ASSERT_EQ(size, 20U*1024U*1024U); + pfd = safe_close(pfd); /* No change */ ASSERT_OK(reread_partition_table_fd(loop->fd, /* flags= */ 0)); @@ -122,11 +123,14 @@ TEST(rereadpt) { ASSERT_OK(reread_partition_table_fd(loop->fd, /* flags= */ 0)); ASSERT_OK_ZERO_ERRNO(access(p, F_OK)); + ASSERT_OK_ERRNO(pfd = open(p, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY)); ASSERT_OK(blockdev_get_device_size(pfd, &size)); ASSERT_EQ(size, 30U*1024U*1024U); + pfd = safe_close(pfd); /* No change */ ASSERT_OK(reread_partition_table_fd(loop->fd, /* flags= */ 0)); + ASSERT_OK_ERRNO(pfd = open(p, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY)); /* Move */ log_notice("MOVING BY 50M"); @@ -137,19 +141,19 @@ TEST(rereadpt) { ASSERT_OK_ZERO_ERRNO(access(p, F_OK)); ASSERT_ERROR(reread_partition_table_fd(loop->fd, /* flags= */ 0), EBUSY); - ASSERT_OK_ZERO_ERRNO(access(p, F_OK)); - - safe_close(pfd); + pfd = safe_close(pfd); + ASSERT_OK_ZERO_ERRNO(access(p, F_OK)); ASSERT_OK(reread_partition_table_fd(loop->fd, /* flags= */ 0)); - pfd = open(p, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY); - ASSERT_OK_ERRNO(pfd); + pfd = ASSERT_OK_ERRNO(open(p, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY)); ASSERT_OK(blockdev_get_device_size(pfd, &size)); ASSERT_EQ(size, 15U*1024U*1024U); + pfd = safe_close(pfd); /* No change */ ASSERT_OK(reread_partition_table_fd(loop->fd, /* flags= */ 0)); + pfd = ASSERT_OK_ERRNO(open(p, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY)); /* Remove */ log_notice("REMOVING"); @@ -159,9 +163,9 @@ TEST(rereadpt) { ASSERT_OK_ZERO_ERRNO(access(p, F_OK)); ASSERT_ERROR(reread_partition_table_fd(loop->fd, /* flags= */ 0), EBUSY); + pfd = safe_close(pfd); ASSERT_OK_ZERO_ERRNO(access(p, F_OK)); - pfd = safe_close(pfd); ASSERT_OK(reread_partition_table_fd(loop->fd, /* flags= */ 0)); ASSERT_ERROR_ERRNO(access(p, F_OK), ENOENT); }