]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
homework: port home_create_directory_or_subvolume() to use HomeSetup
authorLennart Poettering <lennart@poettering.net>
Wed, 20 Oct 2021 19:45:51 +0000 (21:45 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 27 Oct 2021 15:37:14 +0000 (17:37 +0200)
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.

src/home/homework-directory.c
src/home/homework-directory.h
src/home/homework.c

index 8f2f512b1bba0882d11ebada53c8de0265ee394e..876dbd1baad89a0392882cd9d0328ae70510540b 100644 (file)
@@ -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;
 
index 98b1804774828f9a8f1c4dfe766e2c35e470a063..92cc755546c2754e6e4cc6ff437a663343e030fb 100644 (file)
@@ -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);
index f0ef2def7c5e2233169f917f695eb4c580ab22a9..e739ba9334133c65d48d1a6b97dbeffd2f5c983f 100644 (file)
@@ -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: