1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-03-13 12:58:20 +03:00

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.
This commit is contained in:
Lennart Poettering 2021-10-22 16:08:26 +02:00
parent baa41cee77
commit 7cb791bcac
3 changed files with 19 additions and 6 deletions

View File

@ -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;

View File

@ -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,13 +63,22 @@ int home_unshare_and_mount(const char *node, const char *fstype, bool discard, u
return r;
(void) mkdir_p(HOME_RUNTIME_WORK_DIR, 0700);
if (node)
return home_mount_node(node, fstype, discard, flags);
return 0;
}
int home_unshare_and_mount(const char *node, const char *fstype, bool discard, unsigned long flags) {
int r;
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) {
_cleanup_free_ char *subdir = NULL;
const char *d;

View File

@ -4,5 +4,6 @@
#include <stdbool.h>
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);