diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-03-04 00:36:24 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-03-12 18:21:58 +0100 |
commit | 58a74329f6781f231d0b5a913fb3892446204c11 (patch) | |
tree | 01f301b21d16310c3b52c2f0a5946dbcdb0b8756 | |
parent | 6ba248ef66b669154788676233500659823fe51b (diff) | |
download | systemd-58a74329f6781f231d0b5a913fb3892446204c11.tar.gz |
core: fix mtime calculation of dropin files
Nominally, the bug was in unit_load_dropin(), which just took the last mtime
instead of calculating the maximum. But instead of adding code to wrap the
loop, this patch goes in the other direction.
All (correct) callers of config_parse() followed a very similar pattern to
calculate the maximum mtime. So let's simplify things by making config_parse()
assume that mtime is initialized and update it to the maximum. This makes all
the callers that care about mtime simpler and also fixes the issue in
unit_load_dropin().
config_parse_many_nulstr() and config_parse_many() are different, because it
makes sense to call them just once, and current ret_mtime behaviour make sense.
Fixes #17730, https://bugzilla.redhat.com/show_bug.cgi?id=1933137.
(cherry picked from commit da46a1bc3cd28ac36114002c216196dae004b05c)
(cherry picked from commit b29181eaa50a0fd9cefc4bcfbd0e6949038b65c9)
-rw-r--r-- | src/core/load-dropin.c | 1 | ||||
-rw-r--r-- | src/shared/conf-parser.c | 15 | ||||
-rw-r--r-- | src/shared/conf-parser.h | 2 |
3 files changed, 9 insertions, 9 deletions
diff --git a/src/core/load-dropin.c b/src/core/load-dropin.c index fb3f68561b..9386078b30 100644 --- a/src/core/load-dropin.c +++ b/src/core/load-dropin.c @@ -112,6 +112,7 @@ int unit_load_dropin(Unit *u) { return log_oom(); } + u->dropin_mtime = 0; STRV_FOREACH(f, u->dropin_paths) (void) config_parse( u->id, *f, NULL, diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 0fec79f3d7..7499b3b882 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -261,7 +261,7 @@ int config_parse(const char *unit, const void *table, ConfigParseFlags flags, void *userdata, - usec_t *ret_mtime) { + usec_t *latest_mtime) { _cleanup_free_ char *section = NULL, *continuation = NULL; _cleanup_fclose_ FILE *ours = NULL; @@ -273,6 +273,9 @@ int config_parse(const char *unit, assert(filename); assert(lookup); + /* latest_mtime is an input-output parameter: it will be updated if the mtime of the file we're + * looking at is later than the current *latest_mtime value. */ + if (!f) { f = ours = fopen(filename, "re"); if (!f) { @@ -415,8 +418,8 @@ int config_parse(const char *unit, } } - if (ret_mtime) - *ret_mtime = mtime; + if (latest_mtime) + *latest_mtime = MAX(*latest_mtime, mtime); return 0; } @@ -442,13 +445,9 @@ static int config_parse_many_files( } STRV_FOREACH(fn, files) { - usec_t t; - - r = config_parse(NULL, *fn, NULL, sections, lookup, table, flags, userdata, &t); + r = config_parse(NULL, *fn, NULL, sections, lookup, table, flags, userdata, &mtime); if (r < 0) return r; - if (t > mtime) /* Find the newest */ - mtime = t; } if (ret_mtime) diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h index 7c9f5531b0..73d9bceb9c 100644 --- a/src/shared/conf-parser.h +++ b/src/shared/conf-parser.h @@ -89,7 +89,7 @@ int config_parse( const void *table, ConfigParseFlags flags, void *userdata, - usec_t *ret_mtime); /* possibly NULL */ + usec_t *latest_mtime); /* input/output, possibly NULL */ int config_parse_many_nulstr( const char *conf_file, /* possibly NULL */ |