]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/namespace: split out create_temporary_mount_point()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 11 Oct 2023 10:20:53 +0000 (19:20 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 19 Oct 2023 09:45:51 +0000 (18:45 +0900)
No functional change, preparation for later commits.

src/core/namespace.c

index 273eb962b5358973e13d136de84ea34e32a111ba..cae082c655c8d807d69aea2a481fbfd8bdd722c1 100644 (file)
@@ -974,6 +974,26 @@ static char *settle_runtime_dir(RuntimeScope scope) {
         return runtime_dir;
 }
 
+static int create_temporary_mount_point(RuntimeScope scope, char **ret) {
+        _cleanup_free_ char *runtime_dir = NULL, *temporary_mount = NULL;
+
+        assert(ret);
+
+        runtime_dir = settle_runtime_dir(scope);
+        if (!runtime_dir)
+                return log_oom_debug();
+
+        temporary_mount = path_join(runtime_dir, "systemd/namespace-XXXXXX");
+        if (!temporary_mount)
+                return log_oom_debug();
+
+        if (!mkdtemp(temporary_mount))
+                return log_debug_errno(errno, "Failed to create temporary directory '%s': %m", temporary_mount);
+
+        *ret = TAKE_PTR(temporary_mount);
+        return 0;
+}
+
 static int mount_private_dev(MountEntry *m, RuntimeScope scope) {
         static const char devnodes[] =
                 "/dev/null\0"
@@ -983,23 +1003,16 @@ static int mount_private_dev(MountEntry *m, RuntimeScope scope) {
                 "/dev/urandom\0"
                 "/dev/tty\0";
 
-        _cleanup_free_ char *runtime_dir = NULL, *temporary_mount = NULL;
+        _cleanup_free_ char *temporary_mount = NULL;
         const char *dev = NULL, *devpts = NULL, *devshm = NULL, *devhugepages = NULL, *devmqueue = NULL, *devlog = NULL, *devptmx = NULL;
         bool can_mknod = true;
         int r;
 
         assert(m);
 
-        runtime_dir = settle_runtime_dir(scope);
-        if (!runtime_dir)
-                return log_oom_debug();
-
-        temporary_mount = path_join(runtime_dir, "systemd/namespace-dev-XXXXXX");
-        if (!temporary_mount)
-                return log_oom_debug();
-
-        if (!mkdtemp(temporary_mount))
-                return log_debug_errno(errno, "Failed to create temporary directory '%s': %m", temporary_mount);
+        r = create_temporary_mount_point(scope, &temporary_mount);
+        if (r < 0)
+                return r;
 
         dev = strjoina(temporary_mount, "/dev");
         (void) mkdir(dev, 0755);