portable: move profile search helper to path-lookup
Will be used in systemd-analyze later
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user