summaryrefslogtreecommitdiffstats
path: root/src/basic/path-lookup.c
diff options
context:
space:
mode:
authorLuca Boccassi <luca.boccassi@microsoft.com>2021-11-26 18:50:34 +0100
committerLuca Boccassi <luca.boccassi@microsoft.com>2021-11-26 18:50:59 +0100
commit13c02e7bd54e4420c392bd76c0fcf1846c10f99c (patch)
tree50702e984b7de43b34bf8da4429d58315ea8abeb /src/basic/path-lookup.c
parentupdate TODO (diff)
downloadsystemd-13c02e7bd54e4420c392bd76c0fcf1846c10f99c.tar.xz
systemd-13c02e7bd54e4420c392bd76c0fcf1846c10f99c.zip
portable: move profile search helper to path-lookup
Will be used in systemd-analyze later
Diffstat (limited to 'src/basic/path-lookup.c')
-rw-r--r--src/basic/path-lookup.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/basic/path-lookup.c b/src/basic/path-lookup.c
index 1969aa9882..6fb8c40e7a 100644
--- a/src/basic/path-lookup.c
+++ b/src/basic/path-lookup.c
@@ -8,6 +8,7 @@
#include "fs-util.h"
#include "log.h"
#include "macro.h"
+#include "nulstr-util.h"
#include "path-lookup.h"
#include "path-util.h"
#include "stat-util.h"
@@ -864,3 +865,30 @@ char **env_generator_binary_paths(bool is_system) {
return TAKE_PTR(paths);
}
+
+int find_portable_profile(const char *name, const char *unit, char **ret_path) {
+ const char *p, *dot;
+
+ 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;
+
+ if (laccess(joined, F_OK) >= 0) {
+ *ret_path = TAKE_PTR(joined);
+ return 0;
+ }
+
+ if (errno != ENOENT)
+ return -errno;
+ }
+
+ return -ENOENT;
+}