diff options
author | Mike Yuan <me@yhndnzj.com> | 2024-10-04 12:57:23 +0200 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2024-10-06 19:27:11 +0200 |
commit | feae34d64ea3e037a2a6b631b768ea36c90d30bb (patch) | |
tree | 8930ac7e2fd276cfd8e598bfb3e6b7c024ab5307 /src | |
parent | path-lookup: move NETWORK_DIRS to network-util.h (diff) | |
download | systemd-feae34d64ea3e037a2a6b631b768ea36c90d30bb.tar.xz systemd-feae34d64ea3e037a2a6b631b768ea36c90d30bb.zip |
path-lookup: move find_portable_profile() to portable-util
Diffstat (limited to 'src')
-rw-r--r-- | src/analyze/analyze-security.c | 1 | ||||
-rw-r--r-- | src/basic/path-lookup.c | 28 | ||||
-rw-r--r-- | src/basic/path-lookup.h | 5 | ||||
-rw-r--r-- | src/portable/portable.c | 1 | ||||
-rw-r--r-- | src/shared/meson.build | 1 | ||||
-rw-r--r-- | src/shared/portable-util.c | 34 | ||||
-rw-r--r-- | src/shared/portable-util.h | 9 |
7 files changed, 46 insertions, 33 deletions
diff --git a/src/analyze/analyze-security.c b/src/analyze/analyze-security.c index f7e9b94213..fb4fd654f5 100644 --- a/src/analyze/analyze-security.c +++ b/src/analyze/analyze-security.c @@ -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" diff --git a/src/basic/path-lookup.c b/src/basic/path-lookup.c index 234b197394..d4d888c362 100644 --- a/src/basic/path-lookup.c +++ b/src/basic/path-lookup.c @@ -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; -} diff --git a/src/basic/path-lookup.h b/src/basic/path-lookup.h index fab6edd6ca..1176ad8871 100644 --- a/src/basic/path-lookup.h +++ b/src/basic/path-lookup.h @@ -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); diff --git a/src/portable/portable.c b/src/portable/portable.c index f0c508c306..b1055aa8c3 100644 --- a/src/portable/portable.c +++ b/src/portable/portable.c @@ -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" diff --git a/src/shared/meson.build b/src/shared/meson.build index 7b519e9ee8..e759293364 100644 --- a/src/shared/meson.build +++ b/src/shared/meson.build @@ -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 index 0000000000..85c128a1b4 --- /dev/null +++ b/src/shared/portable-util.c @@ -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 index 0000000000..2c89fe3eb8 --- /dev/null +++ b/src/shared/portable-util.h @@ -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); |