]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: add new common make_run_host() helper
authorLennart Poettering <lennart@poettering.net>
Fri, 5 Jan 2024 15:40:45 +0000 (16:40 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 5 Jan 2024 21:34:47 +0000 (22:34 +0100)
This new helper creates the /run/host/ top-level dir inside the
container.

src/nspawn/nspawn-bind-user.c
src/nspawn/nspawn.c
src/nspawn/nspawn.h

index 810ddbb45af2b4d27408d1e5655ad37f549eae78..c7e1a9253c557755e007bda9d060f566271af789 100644 (file)
@@ -388,9 +388,9 @@ int bind_user_setup(
         if (!c || c->n_data == 0)
                 return 0;
 
-        r = userns_mkdir(root, "/run/host", 0755, 0, 0);
+        r = make_run_host(root);
         if (r < 0)
-                return log_error_errno(r, "Failed to create /run/host: %m");
+                return r;
 
         r = userns_mkdir(root, "/run/host/home", 0755, 0, 0);
         if (r < 0)
index 9e53c51f1ac2e295b3ee17ef14fdc08e7c54b974..82c768d89a83a3bea50e04a30d4073c156db45cb 100644 (file)
@@ -2364,6 +2364,18 @@ static int setup_keyring(void) {
         return 0;
 }
 
+int make_run_host(const char *root) {
+        int r;
+
+        assert(root);
+
+        r = userns_mkdir(root, "/run/host", 0755, 0, 0);
+        if (r < 0)
+                return log_error_errno(r, "Failed to create /run/host/: %m");
+
+        return 0;
+}
+
 static int setup_credentials(const char *root) {
         const char *q;
         int r;
@@ -2371,9 +2383,9 @@ static int setup_credentials(const char *root) {
         if (arg_credentials.n_credentials == 0)
                 return 0;
 
-        r = userns_mkdir(root, "/run/host", 0755, 0, 0);
+        r = make_run_host(root);
         if (r < 0)
-                return log_error_errno(r, "Failed to create /run/host: %m");
+                return r;
 
         r = userns_mkdir(root, "/run/host/credentials", 0700, 0, 0);
         if (r < 0)
@@ -2713,9 +2725,9 @@ static int mount_tunnel_dig(const char *root) {
         p = strjoina("/run/systemd/nspawn/propagate/", arg_machine);
         (void) mkdir_p(p, 0600);
 
-        r = userns_mkdir(root, "/run/host", 0755, 0, 0);
+        r = make_run_host(root);
         if (r < 0)
-                return log_error_errno(r, "Failed to create /run/host: %m");
+                return r;
 
         r = userns_mkdir(root, NSPAWN_MOUNT_TUNNEL, 0600, 0, 0);
         if (r < 0)
index 27fb0b44eb942469e8a7e99726c78eab2a138926..556f8ee1aff07d081699a52ba114357ef98ac53b 100644 (file)
@@ -5,3 +5,4 @@
 
 int userns_lchown(const char *p, uid_t uid, gid_t gid);
 int userns_mkdir(const char *root, const char *path, mode_t mode, uid_t uid, gid_t gid);
+int make_run_host(const char *root);