diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-12-03 15:28:52 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2024-02-09 17:57:41 +0100 |
commit | 376d0495f5b9170435824cf9fb067c1077b6cc7e (patch) | |
tree | 6ea5dc37c78e8649a46ffdbaea245939e60589d4 /src/tmpfiles/tmpfiles.c | |
parent | tmpfiles: adjust vertical whitespace (diff) | |
download | systemd-376d0495f5b9170435824cf9fb067c1077b6cc7e.tar.xz systemd-376d0495f5b9170435824cf9fb067c1077b6cc7e.zip |
tmpfiles: only populate uid and gid caches once
a3451c2c4ce7d3c02451f6ace4ee9f873880f78f added offline uid/gid support in a way
where the <root>/etc/passwd and <root>/etc/group would be read anew for each
configuration file that was parsed. The result would always be the same, so I
assume that this was an oversight. Let's use a global cache and and read the
file just once.
Diffstat (limited to 'src/tmpfiles/tmpfiles.c')
-rw-r--r-- | src/tmpfiles/tmpfiles.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index e4e113b402..4e245e3668 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -214,8 +214,11 @@ static ImagePolicy *arg_image_policy = NULL; #define MAX_DEPTH 256 typedef struct Context { - OrderedHashmap *items, *globs; + OrderedHashmap *items; + OrderedHashmap *globs; Set *unix_sockets; + Hashmap *uid_cache; + Hashmap *gid_cache; } Context; STATIC_DESTRUCTOR_REGISTER(arg_include_prefixes, strv_freep); @@ -239,6 +242,9 @@ static void context_done(Context *c) { ordered_hashmap_free(c->globs); set_free(c->unix_sockets); + + hashmap_free(c->uid_cache); + hashmap_free(c->gid_cache); } /* Different kinds of errors that mean that information is not available in the environment. */ @@ -3461,9 +3467,7 @@ static int parse_line( const char *fname, unsigned line, const char *buffer, - bool *invalid_config, - Hashmap **uid_cache, - Hashmap **gid_cache) { + bool *invalid_config) { _cleanup_free_ char *action = NULL, *mode = NULL, *user = NULL, *group = NULL, *age = NULL, *path = NULL; _cleanup_(item_free_contents) Item i = { @@ -3823,7 +3827,7 @@ static int parse_line( else u = user; - r = find_uid(u, &i.uid, uid_cache); + r = find_uid(u, &i.uid, &c->uid_cache); if (r == -ESRCH && arg_graceful) { log_syntax(NULL, LOG_DEBUG, fname, line, r, "%s: user '%s' not found, not adjusting ownership.", i.path, u); @@ -3844,7 +3848,7 @@ static int parse_line( else g = group; - r = find_gid(g, &i.gid, gid_cache); + r = find_gid(g, &i.gid, &c->gid_cache); if (r == -ESRCH && arg_graceful) { log_syntax(NULL, LOG_DEBUG, fname, line, r, "%s: group '%s' not found, not adjusting ownership.", i.path, g); @@ -4221,7 +4225,6 @@ static int read_config_file( bool ignore_enoent, bool *invalid_config) { - _cleanup_hashmap_free_ Hashmap *uid_cache = NULL, *gid_cache = NULL; _cleanup_fclose_ FILE *_f = NULL; _cleanup_free_ char *pp = NULL; unsigned v = 0; @@ -4268,7 +4271,7 @@ static int read_config_file( if (IN_SET(line[0], 0, '#')) continue; - k = parse_line(c, fn, v, line, &invalid_line, &uid_cache, &gid_cache); + k = parse_line(c, fn, v, line, &invalid_line); if (k < 0) { if (invalid_line) /* Allow reporting with a special code if the caller requested this */ |