]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
homework: add macro for "/run/systemd/user-home-mount"
authorLennart Poettering <lennart@poettering.net>
Fri, 22 Oct 2021 14:01:42 +0000 (16:01 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 22 Oct 2021 14:01:42 +0000 (16:01 +0200)
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.

src/home/homework-cifs.c
src/home/homework-luks.c
src/home/homework-mount.c
src/home/homework.c
src/home/homework.h

index 3ac99f20ed35dafbc60eef2a40997e17521b58d0..34cc3bbc9acdcf848a258f7fde588d2621d7cd8a 100644 (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");
index e0b7279c7129eea84104a1c8926dc15b096d6f32..53598165eee793cfdb1463d9a332585122d2c456 100644 (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");
         }
index da4f14e08d8cba35dd520ef993f0230b7655842c..89ae58e25fcfcc2e16dff6247b794d7c5839c81c 100644 (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;
 
index 78ca979fae3fdc481ad7b3f2c4175e5734454e2a..f0ef2def7c5e2233169f917f695eb4c580ab22a9 100644 (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;
         }
index 5fa4b653e2b9dac828964229b47ab67cb816e8c6..df5356454be1cc64307026413bbf2a55cb05d73d 100644 (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"