]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
path-lookup: move find_portable_profile() to portable-util
authorMike Yuan <me@yhndnzj.com>
Fri, 4 Oct 2024 10:57:23 +0000 (12:57 +0200)
committerMike Yuan <me@yhndnzj.com>
Sun, 6 Oct 2024 17:27:11 +0000 (19:27 +0200)
src/analyze/analyze-security.c
src/basic/path-lookup.c
src/basic/path-lookup.h
src/portable/portable.c
src/shared/meson.build
src/shared/portable-util.c [new file with mode: 0644]
src/shared/portable-util.h [new file with mode: 0644]

index f7e9b9421325246fb3a042e4689930d3d4c1086d..fb4fd654f52262902b6a7372232b5a0fd114cbd8 100644 (file)
@@ -26,6 +26,7 @@
 #include "nulstr-util.h"
 #include "parse-util.h"
 #include "path-util.h"
+#include "portable-util.h"
 #include "pretty-print.h"
 #include "seccomp-util.h"
 #include "service.h"
index 234b1973948e2962708c00e56a1745870d60e11b..d4d888c362085dcc968376f198a06de92b14393c 100644 (file)
@@ -901,31 +901,3 @@ char **env_generator_binary_paths(RuntimeScope runtime_scope) {
 
         return TAKE_PTR(paths);
 }
-
-int find_portable_profile(const char *name, const char *unit, char **ret_path) {
-        const char *dot;
-        int r;
-
-        assert(name);
-        assert(ret_path);
-
-        assert_se(dot = strrchr(unit, '.'));
-
-        NULSTR_FOREACH(p, PORTABLE_PROFILE_DIRS) {
-                _cleanup_free_ char *joined = NULL;
-
-                joined = strjoin(p, "/", name, "/", dot + 1, ".conf");
-                if (!joined)
-                        return -ENOMEM;
-
-                r = access_nofollow(joined, F_OK);
-                if (r >= 0) {
-                        *ret_path = TAKE_PTR(joined);
-                        return 0;
-                }
-                if (r != -ENOENT)
-                        return r;
-        }
-
-        return -ENOENT;
-}
index fab6edd6ca173218a94710e2b7e62e1b917a0829..1176ad8871cadd7c81d112f83aa0f5d9bf74ab69 100644 (file)
@@ -3,8 +3,6 @@
 
 #include <stdbool.h>
 
-#include "constants.h"
-#include "macro.h"
 #include "runtime-scope.h"
 
 typedef enum LookupPathsFlags {
@@ -69,6 +67,3 @@ void lookup_paths_done(LookupPaths *p);
 
 char **generator_binary_paths(RuntimeScope scope);
 char **env_generator_binary_paths(RuntimeScope scope);
-
-#define PORTABLE_PROFILE_DIRS CONF_PATHS_NULSTR("systemd/portable/profile")
-int find_portable_profile(const char *name, const char *unit, char **ret_path);
index f0c508c306f3a9c751cc35eefbfcc9031f28c990..b1055aa8c365ef4fcf17ca04003d40db8d751f33 100644 (file)
@@ -32,6 +32,7 @@
 #include "os-util.h"
 #include "path-lookup.h"
 #include "portable.h"
+#include "portable-util.h"
 #include "process-util.h"
 #include "rm-rf.h"
 #include "selinux-util.h"
index 7b519e9ee81d32120c013bd87b073ce249e01fec..e759293364df7c92a05b38c92ca3e94a1fbf8395 100644 (file)
@@ -144,6 +144,7 @@ shared_sources = files(
         'pkcs11-util.c',
         'plymouth-util.c',
         'polkit-agent.c',
+        'portable-util.c',
         'pretty-print.c',
         'capsule-util.c',
         'ptyfwd.c',
diff --git a/src/shared/portable-util.c b/src/shared/portable-util.c
new file mode 100644 (file)
index 0000000..85c128a
--- /dev/null
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "fs-util.h"
+#include "nulstr-util.h"
+#include "portable-util.h"
+#include "string-util.h"
+
+int find_portable_profile(const char *name, const char *unit, char **ret_path) {
+        const char *dot;
+        int r;
+
+        assert(name);
+        assert(ret_path);
+
+        assert_se(dot = strrchr(unit, '.'));
+
+        NULSTR_FOREACH(p, PORTABLE_PROFILE_DIRS) {
+                _cleanup_free_ char *joined = NULL;
+
+                joined = strjoin(p, "/", name, "/", dot + 1, ".conf");
+                if (!joined)
+                        return -ENOMEM;
+
+                r = access_nofollow(joined, F_OK);
+                if (r >= 0) {
+                        *ret_path = TAKE_PTR(joined);
+                        return 0;
+                }
+                if (r != -ENOENT)
+                        return r;
+        }
+
+        return -ENOENT;
+}
diff --git a/src/shared/portable-util.h b/src/shared/portable-util.h
new file mode 100644 (file)
index 0000000..2c89fe3
--- /dev/null
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include "constants.h"
+#include "macro.h"
+
+#define PORTABLE_PROFILE_DIRS CONF_PATHS_NULSTR("systemd/portable/profile")
+
+int find_portable_profile(const char *name, const char *unit, char **ret_path);