diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-11-05 15:27:56 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-11-12 22:22:06 +0100 |
commit | 2e0001c2819b47572c70508f3df988a0c3447ccb (patch) | |
tree | deef9ce8a7208e0d7ff93b0c8fff835d0ef86676 /src/home/homework-mount.c | |
parent | man: run ninja -C build update-man-rules (diff) | |
download | systemd-2e0001c2819b47572c70508f3df988a0c3447ccb.tar.xz systemd-2e0001c2819b47572c70508f3df988a0c3447ccb.zip |
homework: also add a way to configure additional mount options via a JSON user record field
Fixes: #15120
Diffstat (limited to 'src/home/homework-mount.c')
-rw-r--r-- | src/home/homework-mount.c | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/src/home/homework-mount.c b/src/home/homework-mount.c index 82b461a987..fadd5aae86 100644 --- a/src/home/homework-mount.c +++ b/src/home/homework-mount.c @@ -29,28 +29,35 @@ static const char *mount_options_for_fstype(const char *fstype) { return NULL; } -int home_mount_node(const char *node, const char *fstype, bool discard, unsigned long flags) { +int home_mount_node( + const char *node, + const char *fstype, + bool discard, + unsigned long flags, + const char *extra_mount_options) { + _cleanup_free_ char *joined = NULL; - const char *options, *discard_option; + const char *default_options; int r; assert(node); assert(fstype); - options = mount_options_for_fstype(fstype); + default_options = mount_options_for_fstype(fstype); + if (default_options) { + if (!strextend_with_separator(&joined, ",", default_options)) + return log_oom(); + } - discard_option = discard ? "discard" : "nodiscard"; + if (!strextend_with_separator(&joined, ",", discard ? "discard" : "nodiscard")) + return log_oom(); - if (options) { - joined = strjoin(options, ",", discard_option); - if (!joined) + if (extra_mount_options) { + if (!strextend_with_separator(&joined, ",", extra_mount_options)) return log_oom(); + } - options = joined; - } else - options = discard_option; - - r = mount_nofollow_verbose(LOG_ERR, node, HOME_RUNTIME_WORK_DIR, fstype, flags|MS_RELATIME, strempty(options)); + r = mount_nofollow_verbose(LOG_ERR, node, HOME_RUNTIME_WORK_DIR, fstype, flags|MS_RELATIME, joined); if (r < 0) return r; @@ -74,7 +81,13 @@ int home_unshare_and_mkdir(void) { return 0; } -int home_unshare_and_mount(const char *node, const char *fstype, bool discard, unsigned long flags) { +int home_unshare_and_mount( + const char *node, + const char *fstype, + bool discard, + unsigned long flags, + const char *extra_mount_options) { + int r; assert(node); @@ -84,7 +97,7 @@ int home_unshare_and_mount(const char *node, const char *fstype, bool discard, u if (r < 0) return r; - r = home_mount_node(node, fstype, discard, flags); + r = home_mount_node(node, fstype, discard, flags, extra_mount_options); if (r < 0) return r; |