Merge pull request #30867 from dtardon/udev-conf-dropins

Allow dropins for udev.conf
This commit is contained in:
Yu Watanabe
2024-01-12 06:37:23 +09:00
committed by GitHub
8 changed files with 88 additions and 102 deletions
+6 -4
View File
@@ -598,10 +598,11 @@ static int config_parse_many_files(
return 0;
}
/* Parse one main config file located in /etc/systemd and its drop-ins, which is what all systemd daemons
/* Parse one main config file located in /etc/$pkgdir and its drop-ins, which is what all systemd daemons
* do. */
int config_parse_config_file(
int config_parse_config_file_full(
const char *conf_file,
const char *pkgdir,
const char *sections,
ConfigItemLookup lookup,
const void *table,
@@ -613,6 +614,7 @@ int config_parse_config_file(
int r;
assert(conf_file);
assert(pkgdir);
/* build the dropin dir list */
dropin_dirs = new0(char*, strv_length(conf_paths) + 1);
@@ -626,7 +628,7 @@ int config_parse_config_file(
STRV_FOREACH(p, conf_paths) {
char *d;
d = strjoin(*p, "systemd/", conf_file, ".d");
d = strjoin(*p, pkgdir, "/", conf_file, ".d");
if (!d) {
if (flags & CONFIG_PARSE_WARN)
return log_oom();
@@ -640,7 +642,7 @@ int config_parse_config_file(
if (r < 0)
return r;
const char *sysconf_file = strjoina(PKGSYSCONFDIR, "/", conf_file);
const char *sysconf_file = strjoina(SYSCONF_DIR, "/", pkgdir, "/", conf_file);
return config_parse_many_files(STRV_MAKE_CONST(sysconf_file), dropins,
sections, lookup, table, flags, userdata, NULL);
+12 -1
View File
@@ -93,14 +93,25 @@ int config_parse(
void *userdata,
struct stat *ret_stat); /* possibly NULL */
int config_parse_config_file(
int config_parse_config_file_full(
const char *conf_file,
const char *pkgdir,
const char *sections, /* nulstr */
ConfigItemLookup lookup,
const void *table,
ConfigParseFlags flags,
void *userdata);
static inline int config_parse_config_file(
const char *conf_file,
const char *sections, /* nulstr */
ConfigItemLookup lookup,
const void *table,
ConfigParseFlags flags,
void *userdata) {
return config_parse_config_file_full(conf_file, "systemd", sections, lookup, table, flags, userdata);
}
int config_parse_many(
const char* const* conf_files, /* possibly empty */
const char* const* conf_file_dirs,
+21 -27
View File
@@ -22,43 +22,37 @@
#include "udev-util.h"
#include "utf8.h"
int udev_set_max_log_level(char *str) {
size_t n;
int udev_parse_config_full(const ConfigTableItem config_table[]) {
int r;
/* This may modify input string. */
assert(config_table);
if (isempty(str))
r = config_parse_config_file_full(
"udev.conf",
"udev",
/* sections = */ NULL,
config_item_table_lookup,
config_table,
CONFIG_PARSE_WARN,
/* userdata = */ NULL);
if (r == -ENOENT)
return 0;
/* unquote */
n = strlen(str);
if (n >= 2 &&
((str[0] == '"' && str[n - 1] == '"') ||
(str[0] == '\'' && str[n - 1] == '\''))) {
str[n - 1] = '\0';
str++;
}
/* we set the udev log level here explicitly, this is supposed
* to regulate the code in libudev/ and udev/. */
return log_set_max_level_from_string(str);
return r;
}
int udev_parse_config(void) {
_cleanup_free_ char *log_val = NULL;
int r;
int r, log_val = -1;
const ConfigTableItem config_table[] = {
{ NULL, "udev_log", config_parse_log_level, 0, &log_val },
{}
};
r = parse_env_file(NULL, "/etc/udev/udev.conf",
"udev_log", &log_val);
if (r == -ENOENT)
return 0;
r = udev_parse_config_full(config_table);
if (r < 0)
return r;
r = udev_set_max_log_level(log_val);
if (r < 0)
log_syntax(NULL, LOG_WARNING, "/etc/udev/udev.conf", 0, r,
"Failed to set udev log level '%s', ignoring: %m", log_val);
if (log_val >= 0)
log_set_max_level(log_val);
return 0;
}
+2 -1
View File
@@ -3,10 +3,11 @@
#include "sd-device.h"
#include "conf-parser.h"
#include "hashmap.h"
#include "time-util.h"
int udev_set_max_log_level(char *str);
int udev_parse_config_full(const ConfigTableItem config_table[]);
int udev_parse_config(void);
int device_wait_for_initialization(sd_device *device, const char *subsystem, usec_t timeout_usec, sd_device **ret);