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

homework: add macro for "/run/systemd/user-home-mount"

We use this work dir a various places, and it's easy to mistype, hence
let the compiler detect this for us, and introduce a macro for it.

No code changes, just some search/replace.
This commit is contained in:
Lennart Poettering 2021-10-22 16:01:42 +02:00
parent 197aec7e79
commit 498abadb8c
5 changed files with 20 additions and 15 deletions

View File

@ -68,7 +68,7 @@ int home_setup_cifs(
if (r == 0) {
/* Child */
execl("/bin/mount", "/bin/mount", "-n", "-t", "cifs",
h->cifs_service, "/run/systemd/user-home-mount",
h->cifs_service, HOME_RUNTIME_WORK_DIR,
"-o", options, NULL);
log_error_errno(errno, "Failed to execute mount: %m");
@ -89,7 +89,7 @@ int home_setup_cifs(
return log_error_errno(SYNTHETIC_ERRNO(ENOKEY),
"Failed to mount home directory with supplied password.");
setup->root_fd = open("/run/systemd/user-home-mount", O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW);
setup->root_fd = open(HOME_RUNTIME_WORK_DIR, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW);
}
if (setup->root_fd < 0)
return log_error_errno(errno, "Failed to open home directory: %m");

View File

@ -1260,7 +1260,7 @@ int home_setup_luks(
ip = force_image_path ?: user_record_image_path(h);
subdir = path_join("/run/systemd/user-home-mount/", user_record_user_name_and_realm(h));
subdir = path_join(HOME_RUNTIME_WORK_DIR, user_record_user_name_and_realm(h));
if (!subdir)
return log_oom();
@ -1374,7 +1374,7 @@ int home_setup_luks(
fail:
if (mounted)
(void) umount_verbose(LOG_ERR, "/run/systemd/user-home-mount", UMOUNT_NOFOLLOW);
(void) umount_verbose(LOG_ERR, HOME_RUNTIME_WORK_DIR, UMOUNT_NOFOLLOW);
if (dm_activated)
(void) sym_crypt_deactivate_by_name(cd, setup->dm_name, 0);
@ -2242,7 +2242,7 @@ int home_create_luks(
mounted = true;
subdir = path_join("/run/systemd/user-home-mount/", user_record_user_name_and_realm(h));
subdir = path_join(HOME_RUNTIME_WORK_DIR, user_record_user_name_and_realm(h));
if (!subdir) {
r = log_oom();
goto fail;
@ -2302,7 +2302,7 @@ int home_create_luks(
root_fd = safe_close(root_fd);
r = umount_verbose(LOG_ERR, "/run/systemd/user-home-mount", UMOUNT_NOFOLLOW);
r = umount_verbose(LOG_ERR, HOME_RUNTIME_WORK_DIR, UMOUNT_NOFOLLOW);
if (r < 0)
goto fail;
@ -2372,7 +2372,7 @@ fail:
root_fd = safe_close(root_fd);
if (mounted)
(void) umount_verbose(LOG_WARNING, "/run/systemd/user-home-mount", UMOUNT_NOFOLLOW);
(void) umount_verbose(LOG_WARNING, HOME_RUNTIME_WORK_DIR, UMOUNT_NOFOLLOW);
if (dm_activated)
(void) sym_crypt_deactivate_by_name(cd, dm_name, 0);
@ -2474,7 +2474,7 @@ static int ext4_offline_resize_fs(HomeSetup *setup, uint64_t new_size, bool disc
}
if (setup->undo_mount) {
r = umount_verbose(LOG_ERR, "/run/systemd/user-home-mount", UMOUNT_NOFOLLOW);
r = umount_verbose(LOG_ERR, HOME_RUNTIME_WORK_DIR, UMOUNT_NOFOLLOW);
if (r < 0)
return r;
@ -2542,7 +2542,7 @@ static int ext4_offline_resize_fs(HomeSetup *setup, uint64_t new_size, bool disc
}
if (re_open) {
setup->root_fd = open("/run/systemd/user-home-mount", O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW);
setup->root_fd = open(HOME_RUNTIME_WORK_DIR, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW);
if (setup->root_fd < 0)
return log_error_errno(errno, "Failed to reopen file system: %m");
}

View File

@ -5,6 +5,7 @@
#include "alloc-util.h"
#include "homework-mount.h"
#include "homework.h"
#include "mkdir.h"
#include "mount-util.h"
#include "path-util.h"
@ -38,7 +39,7 @@ int home_mount_node(const char *node, const char *fstype, bool discard, unsigned
} else
options = discard_option;
r = mount_nofollow_verbose(LOG_ERR, node, "/run/systemd/user-home-mount", fstype, flags|MS_RELATIME, strempty(options));
r = mount_nofollow_verbose(LOG_ERR, node, HOME_RUNTIME_WORK_DIR, fstype, flags|MS_RELATIME, strempty(options));
if (r < 0)
return r;
@ -52,11 +53,13 @@ int home_unshare_and_mount(const char *node, const char *fstype, bool discard, u
if (unshare(CLONE_NEWNS) < 0)
return log_error_errno(errno, "Couldn't unshare file system namespace: %m");
assert(path_startswith(HOME_RUNTIME_WORK_DIR, "/run"));
r = mount_nofollow_verbose(LOG_ERR, "/run", "/run", NULL, MS_SLAVE|MS_REC, NULL); /* Mark /run as MS_SLAVE in our new namespace */
if (r < 0)
return r;
(void) mkdir_p("/run/systemd/user-home-mount", 0700);
(void) mkdir_p(HOME_RUNTIME_WORK_DIR, 0700);
if (node)
return home_mount_node(node, fstype, discard, flags);
@ -74,13 +77,13 @@ int home_move_mount(const char *user_name_and_realm, const char *target) {
/* If user_name_and_realm is set, then we'll mount a subdir of the source mount into the host. If
* it's NULL we'll move the mount itself */
if (user_name_and_realm) {
subdir = path_join("/run/systemd/user-home-mount/", user_name_and_realm);
subdir = path_join(HOME_RUNTIME_WORK_DIR, user_name_and_realm);
if (!subdir)
return log_oom();
d = subdir;
} else
d = "/run/systemd/user-home-mount/";
d = HOME_RUNTIME_WORK_DIR;
(void) mkdir_p(target, 0700);
@ -88,7 +91,7 @@ int home_move_mount(const char *user_name_and_realm, const char *target) {
if (r < 0)
return r;
r = umount_verbose(LOG_ERR, "/run/systemd/user-home-mount", UMOUNT_NOFOLLOW);
r = umount_verbose(LOG_ERR, HOME_RUNTIME_WORK_DIR, UMOUNT_NOFOLLOW);
if (r < 0)
return r;

View File

@ -317,7 +317,7 @@ int home_setup_done(HomeSetup *setup) {
}
if (setup->undo_mount) {
q = umount_verbose(LOG_DEBUG, "/run/systemd/user-home-mount", UMOUNT_NOFOLLOW);
q = umount_verbose(LOG_DEBUG, HOME_RUNTIME_WORK_DIR, UMOUNT_NOFOLLOW);
if (q < 0)
r = q;
}

View File

@ -83,3 +83,5 @@ int home_extend_embedded_identity(UserRecord *h, UserRecord *used, HomeSetup *se
int user_record_authenticate(UserRecord *h, UserRecord *secret, PasswordCache *cache, bool strict_verify);
int home_sync_and_statfs(int root_fd, struct statfs *ret);
#define HOME_RUNTIME_WORK_DIR "/run/systemd/user-home-mount"