]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
homework: get rid of manual clean up path in home_setup_luks()
authorLennart Poettering <lennart@poettering.net>
Tue, 26 Oct 2021 15:28:51 +0000 (17:28 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 28 Oct 2021 06:17:46 +0000 (08:17 +0200)
Now that we stored all our different objects inside the HomeSetup
structure, we can get rid of our manual clean-up path, since
home_setup_done() will clean up everything stored therein anyway, in the
right order.

This is the main reason we moved everything into HomeSetup in the
previous commits: so that we can share clean-up paths for these objects
with everything else.

src/home/homework-luks.c

index d20df172fbfd9ac6f44a6869f47673e6102e31e6..1ff4d504177cda12a148ec46380527b1384dbe01 100644 (file)
@@ -1273,10 +1273,8 @@ int home_setup_luks(
                 log_info("Discovered used loopback device %s.", setup->loop->node);
 
                 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;
-                }
+                if (setup->root_fd < 0)
+                        return log_error_errno(errno, "Failed to open home directory: %m");
         } else {
                 _cleanup_free_ char *fstype = NULL, *subdir = NULL;
                 const char *ip;
@@ -1340,27 +1338,25 @@ int home_setup_luks(
 
                 r = luks_validate_home_record(setup->crypt_device, h, volume_key, cache, &luks_home);
                 if (r < 0)
-                        goto fail;
+                        return r;
 
                 r = fs_validate(setup->dm_node, h->file_system_uuid, &fstype, &found_fs_uuid);
                 if (r < 0)
-                        goto fail;
+                        return r;
 
                 r = run_fsck(setup->dm_node, fstype);
                 if (r < 0)
-                        goto fail;
+                        return r;
 
                 r = home_unshare_and_mount(setup->dm_node, fstype, user_record_luks_discard(h), user_record_mount_flags(h));
                 if (r < 0)
-                        goto fail;
+                        return r;
 
                 setup->undo_mount = true;
 
                 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 (setup->root_fd < 0)
+                        return log_error_errno(errno, "Failed to open home directory: %m");
 
                 if (user_record_luks_discard(h))
                         (void) run_fitrim(setup->root_fd);
@@ -1380,16 +1376,6 @@ int home_setup_luks(
                 *ret_luks_home = TAKE_PTR(luks_home);
 
         return 0;
-
-fail:
-        setup->root_fd = safe_close(setup->root_fd);
-        home_setup_undo_mount(setup, LOG_ERR);
-        home_setup_undo_dm(setup, LOG_ERR);
-
-        if (setup->image_fd >= 0 && setup->do_mark_clean)
-                (void) run_mark_dirty(setup->image_fd, false);
-
-        return r;
 }
 
 static void print_size_summary(uint64_t host_size, uint64_t encrypted_size, struct statfs *sfs) {