mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 00:14:32 +09:00
Make new sd-path configuration search functionality generic (#39684)
Reverts systemd/systemd#38680 After taking a closer look I'm not convinced by the approach, see below. First of all, all other SD_PATH_SEARCH_* are either somewhat generic, i.e. encode the common prefix for configurations, binaries, etc., or are subdirectories under systemd/ hence in our own "domain". The tmpfiles/sysctl/binfmt we don't prefix with "systemd" precisely because the concept is generic and there're actually other impls of them. A specific SD_PATH_SEARCH_SYSCTL doesn't fit into our existing scheme. Instead something along the lines of "SEARCH_SYSTEM_CONFIGURATION" shall be introduced, and consumers will just suffix sysctl.d/tmpfiles.d/binfmt.d for the final result. And secondly, I don't grok why systemd-sysctl now unnecessarily calls into sd-path to obtain the fixed search path. None of our other tools do that. ----------- An alternate approach, SD_PATH_SYSTEM_SEARCH_CONFIGURATION, which does exactly above, will be introduced instead. It provides a universal interface for querying any system config with our idiomatic /etc/:/run/:/usr/local/lib/:/usr/lib/ hierarchy.
This commit is contained in:
@@ -41,6 +41,7 @@
|
||||
<constant>SD_PATH_SYSTEM_STATE_FACTORY</constant>,
|
||||
|
||||
<constant>SD_PATH_SYSTEM_CONFIGURATION</constant>,
|
||||
<constant>SD_PATH_SYSTEM_SEARCH_CONFIGURATION</constant>,
|
||||
<constant>SD_PATH_SYSTEM_RUNTIME</constant>,
|
||||
<constant>SD_PATH_SYSTEM_RUNTIME_LOGS</constant>,
|
||||
<constant>SD_PATH_SYSTEM_STATE_PRIVATE</constant>,
|
||||
@@ -76,7 +77,6 @@
|
||||
<constant>SD_PATH_SEARCH_CONFIGURATION_FACTORY</constant>,
|
||||
<constant>SD_PATH_SEARCH_STATE_FACTORY</constant>,
|
||||
<constant>SD_PATH_SEARCH_CONFIGURATION</constant>,
|
||||
<constant>SD_PATH_SEARCH_SYSCTL</constant>,
|
||||
|
||||
<constant>SD_PATH_SYSTEMD_UTIL</constant>,
|
||||
<constant>SD_PATH_SYSTEMD_SYSTEM_UNIT</constant>,
|
||||
|
||||
@@ -524,6 +524,9 @@ static int get_search(uint64_t type, char ***ret) {
|
||||
|
||||
switch (type) {
|
||||
|
||||
case SD_PATH_SYSTEM_SEARCH_CONFIGURATION:
|
||||
return strv_from_nulstr(ret, CONF_PATHS_NULSTR(""));
|
||||
|
||||
case SD_PATH_SEARCH_BINARIES:
|
||||
return search_from_environment(ret,
|
||||
NULL,
|
||||
@@ -683,11 +686,7 @@ static int get_search(uint64_t type, char ***ret) {
|
||||
|
||||
*ret = TAKE_PTR(l);
|
||||
return 0;
|
||||
}
|
||||
|
||||
case SD_PATH_SEARCH_SYSCTL:
|
||||
return strv_from_nulstr(ret, CONF_PATHS_NULSTR("sysctl.d"));
|
||||
}
|
||||
}}
|
||||
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ static const char* const path_table[_SD_PATH_MAX] = {
|
||||
[SD_PATH_TEMPORARY] = "temporary",
|
||||
[SD_PATH_TEMPORARY_LARGE] = "temporary-large",
|
||||
|
||||
[SD_PATH_SYSTEM_SEARCH_CONFIGURATION] = "system-search-configuration",
|
||||
|
||||
[SD_PATH_SYSTEM_BINARIES] = "system-binaries",
|
||||
[SD_PATH_SYSTEM_INCLUDE] = "system-include",
|
||||
[SD_PATH_SYSTEM_LIBRARY_PRIVATE] = "system-library-private",
|
||||
@@ -66,7 +68,6 @@ static const char* const path_table[_SD_PATH_MAX] = {
|
||||
[SD_PATH_SEARCH_CONFIGURATION_FACTORY] = "search-configuration-factory",
|
||||
[SD_PATH_SEARCH_STATE_FACTORY] = "search-state-factory",
|
||||
[SD_PATH_SEARCH_CONFIGURATION] = "search-configuration",
|
||||
[SD_PATH_SEARCH_SYSCTL] = "search-sysctl",
|
||||
|
||||
[SD_PATH_SYSTEMD_UTIL] = "systemd-util",
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "sd-path.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "build.h"
|
||||
#include "conf-files.h"
|
||||
@@ -281,10 +279,10 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_file(OrderedHashmap **sysctl_options, const char *path, bool ignore_enoent, const char **search_paths) {
|
||||
static int parse_file(OrderedHashmap **sysctl_options, const char *path, bool ignore_enoent) {
|
||||
return conf_file_read(
|
||||
/* root = */ NULL,
|
||||
search_paths,
|
||||
(const char**) CONF_PATHS_STRV("sysctl.d"),
|
||||
path,
|
||||
parse_line,
|
||||
sysctl_options,
|
||||
@@ -307,7 +305,7 @@ static int read_credential_lines(OrderedHashmap **sysctl_options) {
|
||||
if (!j)
|
||||
return log_oom();
|
||||
|
||||
return parse_file(sysctl_options, j, /* ignore_enoent= */ true, /* search_paths= */ NULL);
|
||||
return parse_file(sysctl_options, j, /* ignore_enoent= */ true);
|
||||
}
|
||||
|
||||
static int cat_config(char **files) {
|
||||
@@ -442,13 +440,8 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
|
||||
static int run(int argc, char *argv[]) {
|
||||
_cleanup_ordered_hashmap_free_ OrderedHashmap *sysctl_options = NULL;
|
||||
_cleanup_strv_free_ char **search_paths = NULL;
|
||||
int r;
|
||||
|
||||
r = sd_path_lookup_strv(SD_PATH_SEARCH_SYSCTL, /* suffix= */ NULL, &search_paths);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to get sysctl.d/ search paths: %m");
|
||||
|
||||
r = parse_argv(argc, argv);
|
||||
if (r <= 0)
|
||||
return r;
|
||||
@@ -465,12 +458,12 @@ static int run(int argc, char *argv[]) {
|
||||
/* Use (argument):n, where n==1 for the first positional arg */
|
||||
RET_GATHER(r, parse_line("(argument)", ++pos, *arg, /* invalid_config = */ NULL, &sysctl_options));
|
||||
else
|
||||
RET_GATHER(r, parse_file(&sysctl_options, *arg, /* ignore_enoent= */ false, (const char**) search_paths));
|
||||
RET_GATHER(r, parse_file(&sysctl_options, *arg, false));
|
||||
}
|
||||
} else {
|
||||
_cleanup_strv_free_ char **files = NULL;
|
||||
|
||||
r = conf_files_list_strv(&files, ".conf", NULL, 0, (const char**) search_paths);
|
||||
r = conf_files_list_strv(&files, ".conf", NULL, 0, (const char**) CONF_PATHS_STRV("sysctl.d"));
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to enumerate sysctl.d files: %m");
|
||||
|
||||
@@ -478,7 +471,7 @@ static int run(int argc, char *argv[]) {
|
||||
return cat_config(files);
|
||||
|
||||
STRV_FOREACH(f, files)
|
||||
RET_GATHER(r, parse_file(&sysctl_options, *f, /* ignore_enoent= */ true, /* search_paths= */ NULL));
|
||||
RET_GATHER(r, parse_file(&sysctl_options, *f, true));
|
||||
|
||||
RET_GATHER(r, read_credential_lines(&sysctl_options));
|
||||
}
|
||||
|
||||
@@ -44,6 +44,9 @@ __extension__ enum {
|
||||
SD_PATH_SYSTEM_STATE_CACHE,
|
||||
SD_PATH_SYSTEM_STATE_SPOOL,
|
||||
|
||||
/* generic system configuration */
|
||||
SD_PATH_SYSTEM_SEARCH_CONFIGURATION,
|
||||
|
||||
/* Vendor supplied data */
|
||||
SD_PATH_USER_BINARIES,
|
||||
SD_PATH_USER_LIBRARY_PRIVATE,
|
||||
@@ -129,8 +132,6 @@ __extension__ enum {
|
||||
SD_PATH_USER_CREDENTIAL_STORE_ENCRYPTED,
|
||||
SD_PATH_USER_SEARCH_CREDENTIAL_STORE_ENCRYPTED,
|
||||
|
||||
SD_PATH_SEARCH_SYSCTL,
|
||||
|
||||
_SD_PATH_MAX,
|
||||
_SD_PATH_INVALID = UINT64_MAX
|
||||
};
|
||||
|
||||
@@ -51,6 +51,8 @@ assert_eq "$(systemd-path --suffix='' system-runtime)" "/run"
|
||||
assert_eq "$(systemd-path --suffix='🤔' system-runtime)" "/run/🤔"
|
||||
assert_eq "$(systemd-path --suffix=hello system-runtime)" "/run/hello"
|
||||
|
||||
assert_eq "$(systemd-path system-search-configuration --suffix=sysctl.d)" "/etc/sysctl.d:/run/sysctl.d:/usr/local/lib/sysctl.d:/usr/lib/sysctl.d"
|
||||
|
||||
# Note for the stuff below: everything defaults to $HOME, only the desktop
|
||||
# directory defaults to $HOME/Desktop.
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user