portable: move profile search helper to path-lookup

Will be used in systemd-analyze later
This commit is contained in:
Luca Boccassi
2021-11-26 17:50:59 +00:00
parent e6f48be8d4
commit 13c02e7bd5
3 changed files with 33 additions and 31 deletions
+28
View File
@@ -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;
}
+3
View File
@@ -72,3 +72,6 @@ char **env_generator_binary_paths(bool is_system);
#define NETWORK_DIRS ((const char* const*) CONF_PATHS_STRV("systemd/network"))
#define NETWORK_DIRS_NULSTR CONF_PATHS_NULSTR("systemd/network")
#define PORTABLE_PROFILE_DIRS CONF_PATHS_NULSTR("systemd/portable/profile")
int find_portable_profile(const char *name, const char *unit, char **ret_path);