summaryrefslogtreecommitdiffstats
path: root/src/home/homework-mount.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-10-22 16:08:26 +0200
committerLennart Poettering <lennart@poettering.net>2021-10-22 16:09:50 +0200
commit7cb791bcac6240f2f3aab1438aa11c9b4cfaa658 (patch)
tree1484e6b4a7200fa094b933792cd5a973a9aa9ffd /src/home/homework-mount.c
parenthomework: use bit fields where we deal with lots of separate boolean flags (diff)
downloadsystemd-7cb791bcac6240f2f3aab1438aa11c9b4cfaa658.tar.xz
systemd-7cb791bcac6240f2f3aab1438aa11c9b4cfaa658.zip
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.
Diffstat (limited to 'src/home/homework-mount.c')
-rw-r--r--src/home/homework-mount.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/home/homework-mount.c b/src/home/homework-mount.c
index 89ae58e25f..47345eb839 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) {