From: Lennart Poettering Date: Wed, 20 Oct 2021 19:45:51 +0000 (+0200) Subject: homework: port home_create_directory_or_subvolume() to use HomeSetup X-Git-Tag: v250-rc1~404^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1aeaf27f5d537283e6cacd1bb5d2d9fa0860dab;p=thirdparty%2Fsystemd.git homework: port home_create_directory_or_subvolume() to use HomeSetup Let's migrate home_create_directory_or_subvolume() to also use HomeSetup for storing its runtime objects we'd like to destroy in case of failure. In the beginning this is just the root_fd, but later on we can add more. No change in behaviour, just shifting things around. --- diff --git a/src/home/homework-directory.c b/src/home/homework-directory.c index 8f2f512b1bb..876dbd1baad 100644 --- a/src/home/homework-directory.c +++ b/src/home/homework-directory.c @@ -80,16 +80,16 @@ int home_activate_directory( return 0; } -int home_create_directory_or_subvolume(UserRecord *h, UserRecord **ret_home) { +int home_create_directory_or_subvolume(UserRecord *h, HomeSetup *setup, UserRecord **ret_home) { _cleanup_(rm_rf_subvolume_and_freep) char *temporary = NULL; _cleanup_(user_record_unrefp) UserRecord *new_home = NULL; - _cleanup_close_ int root_fd = -1; _cleanup_free_ char *d = NULL; const char *ip; int r; assert(h); assert(IN_SET(user_record_storage(h), USER_DIRECTORY, USER_SUBVOLUME)); + assert(setup); assert(ret_home); assert_se(ip = user_record_image_path(h)); @@ -149,15 +149,15 @@ int home_create_directory_or_subvolume(UserRecord *h, UserRecord **ret_home) { temporary = TAKE_PTR(d); /* Needs to be destroyed now */ - root_fd = open(temporary, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW); - if (root_fd < 0) + setup->root_fd = open(temporary, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW); + if (setup->root_fd < 0) return log_error_errno(errno, "Failed to open temporary home directory: %m"); - r = home_populate(h, root_fd); + r = home_populate(h, setup->root_fd); if (r < 0) return r; - r = home_sync_and_statfs(root_fd, NULL); + r = home_sync_and_statfs(setup->root_fd, NULL); if (r < 0) return r; diff --git a/src/home/homework-directory.h b/src/home/homework-directory.h index 98b18047748..92cc755546c 100644 --- a/src/home/homework-directory.h +++ b/src/home/homework-directory.h @@ -6,5 +6,5 @@ int home_setup_directory(UserRecord *h, HomeSetup *setup); int home_activate_directory(UserRecord *h, HomeSetup *setup, PasswordCache *cache, UserRecord **ret_home); -int home_create_directory_or_subvolume(UserRecord *h, UserRecord **ret_home); +int home_create_directory_or_subvolume(UserRecord *h, HomeSetup *setup, UserRecord **ret_home); int home_resize_directory(UserRecord *h, HomeSetupFlags flags, PasswordCache *cache, HomeSetup *setup, UserRecord **ret_home); diff --git a/src/home/homework.c b/src/home/homework.c index f0ef2def7c5..e739ba93341 100644 --- a/src/home/homework.c +++ b/src/home/homework.c @@ -1232,7 +1232,7 @@ static int home_create(UserRecord *h, UserRecord **ret_home) { case USER_DIRECTORY: case USER_SUBVOLUME: - r = home_create_directory_or_subvolume(h, &new_home); + r = home_create_directory_or_subvolume(h, &setup, &new_home); break; case USER_FSCRYPT: