From: Lennart Poettering Date: Tue, 26 Oct 2021 15:20:56 +0000 (+0200) Subject: homework: rework home_setup_luks() to store its root_fd also in HomeSetup X-Git-Tag: v250-rc1~390^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ae4d05f6496717a5024b64f709d73598e9a60343;p=thirdparty%2Fsystemd.git homework: rework home_setup_luks() to store its root_fd also in HomeSetup --- diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c index cd584b0f45e..0ff16459af3 100644 --- a/src/home/homework-luks.c +++ b/src/home/homework-luks.c @@ -1175,7 +1175,7 @@ int home_setup_luks( sd_id128_t found_partition_uuid, found_luks_uuid, found_fs_uuid; _cleanup_(user_record_unrefp) UserRecord *luks_home = NULL; _cleanup_(erase_and_freep) void *volume_key = NULL; - _cleanup_close_ int opened_image_fd = -1, root_fd = -1; + _cleanup_close_ int opened_image_fd = -1; size_t volume_key_size = 0; bool marked_dirty = false; uint64_t offset, size; @@ -1185,6 +1185,7 @@ int home_setup_luks( assert(setup); assert(setup->dm_name); assert(setup->dm_node); + assert(setup->root_fd < 0); assert(!setup->crypt_device); assert(!setup->loop); @@ -1273,8 +1274,8 @@ int home_setup_luks( log_info("Discovered used loopback device %s.", setup->loop->node); - root_fd = open(user_record_home_directory(h), O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW); - if (root_fd < 0) { + setup->root_fd = open(user_record_home_directory(h), O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW); + if (setup->root_fd < 0) { r = log_error_errno(errno, "Failed to open home directory: %m"); goto fail; } @@ -1359,14 +1360,14 @@ int home_setup_luks( setup->undo_mount = true; - root_fd = open(subdir, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW); - if (root_fd < 0) { + setup->root_fd = open(subdir, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW); + if (setup->root_fd < 0) { r = log_error_errno(errno, "Failed to open home directory: %m"); goto fail; } if (user_record_luks_discard(h)) - (void) run_fitrim(root_fd); + (void) run_fitrim(setup->root_fd); /* And now, fill in everything */ if (opened_image_fd >= 0) { @@ -1378,7 +1379,6 @@ int home_setup_luks( setup->do_mark_clean = marked_dirty; } - setup->root_fd = TAKE_FD(root_fd); setup->found_partition_uuid = found_partition_uuid; setup->found_luks_uuid = found_luks_uuid; setup->found_fs_uuid = found_fs_uuid;