From 7cb791bcac6240f2f3aab1438aa11c9b4cfaa658 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 22 Oct 2021 16:08:26 +0200 Subject: [PATCH] homework: split home_unshare_and_mount() in two MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Previously the call did two things, and the second thing was optional (depending on first arg being NULL). Let's simplify this and just make it two distinct functions, where one calls the other. This should make things a bit more readable, given that we called a function called "…and_mount()" which didn't actually mount... No actual code changes, just some refactoring. --- src/home/homework-cifs.c | 2 +- src/home/homework-mount.c | 20 ++++++++++++++++---- src/home/homework-mount.h | 1 + 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/home/homework-cifs.c b/src/home/homework-cifs.c index 34cc3bbc9ac..0a95b886b36 100644 --- a/src/home/homework-cifs.c +++ b/src/home/homework-cifs.c @@ -28,7 +28,7 @@ int home_setup_cifs( char **pw; int r; - r = home_unshare_and_mount(NULL, NULL, false, user_record_mount_flags(h)); + r = home_unshare_and_mkdir(); if (r < 0) return r; diff --git a/src/home/homework-mount.c b/src/home/homework-mount.c index 89ae58e25fc..47345eb8391 100644 --- a/src/home/homework-mount.c +++ b/src/home/homework-mount.c @@ -26,6 +26,9 @@ int home_mount_node(const char *node, const char *fstype, bool discard, unsigned const char *options, *discard_option; int r; + assert(node); + assert(fstype); + options = mount_options_for_fstype(fstype); discard_option = discard ? "discard" : "nodiscard"; @@ -47,7 +50,7 @@ int home_mount_node(const char *node, const char *fstype, bool discard, unsigned return 0; } -int home_unshare_and_mount(const char *node, const char *fstype, bool discard, unsigned long flags) { +int home_unshare_and_mkdir(void) { int r; if (unshare(CLONE_NEWNS) < 0) @@ -60,11 +63,20 @@ int home_unshare_and_mount(const char *node, const char *fstype, bool discard, u return r; (void) mkdir_p(HOME_RUNTIME_WORK_DIR, 0700); + return 0; +} - if (node) - return home_mount_node(node, fstype, discard, flags); +int home_unshare_and_mount(const char *node, const char *fstype, bool discard, unsigned long flags) { + int r; - return 0; + assert(node); + assert(fstype); + + r = home_unshare_and_mkdir(); + if (r < 0) + return r; + + return home_mount_node(node, fstype, discard, flags); } int home_move_mount(const char *user_name_and_realm, const char *target) { diff --git a/src/home/homework-mount.h b/src/home/homework-mount.h index 2a4591c1f42..893ecdc5869 100644 --- a/src/home/homework-mount.h +++ b/src/home/homework-mount.h @@ -4,5 +4,6 @@ #include int home_mount_node(const char *node, const char *fstype, bool discard, unsigned long flags); +int home_unshare_and_mkdir(void); int home_unshare_and_mount(const char *node, const char *fstype, bool discard, unsigned long flags); int home_move_mount(const char *user_name_and_realm, const char *target); -- 2.47.3