summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-07-23 08:02:48 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-07-23 08:03:48 +0200
commit3f4dfd9d8791d488835e6bf262254fa1d28866a2 (patch)
treee28db53521fb668472a1ca121e52dfc7377e3ef8
parentudev: delay to start queued events on `udevadm control --start-exec-queue` (diff)
downloadsystemd-3f4dfd9d8791d488835e6bf262254fa1d28866a2.tar.xz
systemd-3f4dfd9d8791d488835e6bf262254fa1d28866a2.zip
conf-parser: add a boolean flag for config_get_stats_by_path() to control if drop-in configs are checked
Preparation for later commits.
-rw-r--r--src/shared/conf-parser.c48
-rw-r--r--src/shared/conf-parser.h1
-rw-r--r--src/udev/net/link-config.c4
3 files changed, 30 insertions, 23 deletions
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index 6bd3ab38db..9a888eec21 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -605,22 +605,19 @@ int config_parse_many(
return config_parse_many_files(conf_files, files, sections, lookup, table, flags, userdata, ret_stats_by_path);
}
-static int config_get_stats_by_path_one(
+static int dropins_get_stats_by_path(
const char* conf_file,
const char* const* conf_file_dirs,
- Hashmap *stats_by_path) {
+ Hashmap **stats_by_path) {
_cleanup_strv_free_ char **files = NULL;
_cleanup_free_ char *dropin_dirname = NULL;
- struct stat st;
int r;
assert(conf_file);
assert(conf_file_dirs);
assert(stats_by_path);
- /* Unlike config_parse(), this does not support stream. */
-
r = path_extract_filename(conf_file, &dropin_dirname);
if (r < 0)
return r;
@@ -634,17 +631,9 @@ static int config_get_stats_by_path_one(
if (r < 0)
return r;
- /* First read the main config file. */
- r = RET_NERRNO(stat(conf_file, &st));
- if (r >= 0) {
- r = hashmap_put_stats_by_path(&stats_by_path, conf_file, &st);
- if (r < 0)
- return r;
- } else if (r != -ENOENT)
- return r;
-
- /* Then read all the drop-ins. */
STRV_FOREACH(fn, files) {
+ struct stat st;
+
if (stat(*fn, &st) < 0) {
if (errno == ENOENT)
continue;
@@ -652,7 +641,7 @@ static int config_get_stats_by_path_one(
return -errno;
}
- r = hashmap_put_stats_by_path(&stats_by_path, *fn, &st);
+ r = hashmap_put_stats_by_path(stats_by_path, *fn, &st);
if (r < 0)
return r;
}
@@ -665,6 +654,7 @@ int config_get_stats_by_path(
const char *root,
unsigned flags,
const char* const* dirs,
+ bool check_dropins,
Hashmap **ret) {
_cleanup_hashmap_free_ Hashmap *stats_by_path = NULL;
@@ -675,16 +665,32 @@ int config_get_stats_by_path(
assert(dirs);
assert(ret);
+ /* Unlike config_parse(), this does not support stream. */
+
r = conf_files_list_strv(&files, suffix, root, flags, dirs);
if (r < 0)
return r;
- stats_by_path = hashmap_new(&path_hash_ops_free_free);
- if (!stats_by_path)
- return -ENOMEM;
-
STRV_FOREACH(f, files) {
- r = config_get_stats_by_path_one(*f, dirs, stats_by_path);
+ struct stat st;
+
+ /* First read the main config file. */
+ if (stat(*f, &st) < 0) {
+ if (errno == ENOENT)
+ continue;
+
+ return -errno;
+ }
+
+ r = hashmap_put_stats_by_path(&stats_by_path, *f, &st);
+ if (r < 0)
+ return r;
+
+ if (!check_dropins)
+ continue;
+
+ /* Then read all the drop-ins if requested. */
+ r = dropins_get_stats_by_path(*f, dirs, &stats_by_path);
if (r < 0)
return r;
}
diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h
index 07b6490165..15616adf3b 100644
--- a/src/shared/conf-parser.h
+++ b/src/shared/conf-parser.h
@@ -119,6 +119,7 @@ int config_get_stats_by_path(
const char *root,
unsigned flags,
const char* const* dirs,
+ bool check_dropins,
Hashmap **ret);
bool stats_by_path_equal(Hashmap *a, Hashmap *b);
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index 8fdb48f315..693f5cd3a6 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -347,9 +347,9 @@ bool link_config_should_reload(LinkConfigContext *ctx) {
assert(ctx);
- r = config_get_stats_by_path(".link", NULL, 0, NETWORK_DIRS, &stats_by_path);
+ r = config_get_stats_by_path(".link", NULL, 0, NETWORK_DIRS, /* check_dropins = */ true, &stats_by_path);
if (r < 0) {
- log_warning_errno(r, "Failed to get stats of .link files: %m");
+ log_warning_errno(r, "Failed to get stats of .link files, ignoring: %m");
return true;
}