From: Lennart Poettering Date: Fri, 22 Oct 2021 14:08:26 +0000 (+0200) Subject: homework: split home_unshare_and_mount() in two X-Git-Tag: v250-rc1~447^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F21093%2Fhead;p=thirdparty%2Fsystemd.git homework: split home_unshare_and_mount() in two 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. --- 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);