summaryrefslogtreecommitdiffstats
path: root/src/tmpfiles/tmpfiles.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-12-03 14:53:49 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2024-02-09 17:57:41 +0100
commitf6a1346e4e738f77afec5c10454edb833a502ba6 (patch)
tree1ff6e1d0c04dd88abadf6897e747f093ac6383f7 /src/tmpfiles/tmpfiles.c
parenttmpfiles: only populate uid and gid caches once (diff)
downloadsystemd-f6a1346e4e738f77afec5c10454edb833a502ba6.tar.xz
systemd-f6a1346e4e738f77afec5c10454edb833a502ba6.zip
tmpfiles: split out helper to open and read a "config file"
No functional change. Note that this function will be modified in subsequent commits, and the API will change.
Diffstat (limited to 'src/tmpfiles/tmpfiles.c')
-rw-r--r--src/tmpfiles/tmpfiles.c66
1 files changed, 7 insertions, 59 deletions
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 4e245e3668..a2eb05c6a6 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -3463,12 +3463,13 @@ static bool is_duplicated_item(ItemArray *existing, const Item *i) {
}
static int parse_line(
- Context *c,
const char *fname,
unsigned line,
const char *buffer,
- bool *invalid_config) {
+ bool *invalid_config,
+ void *context) {
+ Context *c = ASSERT_PTR(context);
_cleanup_free_ char *action = NULL, *mode = NULL, *user = NULL, *group = NULL, *age = NULL, *path = NULL;
_cleanup_(item_free_contents) Item i = {
/* The "age-by" argument considers all file timestamp types by default. */
@@ -3481,7 +3482,6 @@ static int parse_line(
bool append_or_force = false, boot = false, allow_failure = false, try_replace = false,
unbase64 = false, from_cred = false, missing_user_or_group = false;
- assert(c);
assert(fname);
assert(line >= 1);
assert(buffer);
@@ -4225,62 +4225,16 @@ static int read_config_file(
bool ignore_enoent,
bool *invalid_config) {
- _cleanup_fclose_ FILE *_f = NULL;
- _cleanup_free_ char *pp = NULL;
- unsigned v = 0;
- FILE *f;
ItemArray *ia;
int r = 0;
assert(c);
assert(fn);
- if (streq(fn, "-")) {
- log_debug("Reading config from stdin%s", special_glyph(SPECIAL_GLYPH_ELLIPSIS));
- fn = "<stdin>";
- f = stdin;
- } else {
- r = search_and_fopen(fn, "re", arg_root, (const char**) config_dirs, &_f, &pp);
- if (r < 0) {
- if (ignore_enoent && r == -ENOENT) {
- log_debug_errno(r, "Failed to open \"%s\", ignoring: %m", fn);
- return 0;
- }
-
- return log_error_errno(r, "Failed to open '%s': %m", fn);
- }
-
- log_debug("Reading config file \"%s\"%s", pp, special_glyph(SPECIAL_GLYPH_ELLIPSIS));
- fn = pp;
- f = _f;
- }
-
- for (;;) {
- _cleanup_free_ char *line = NULL;
- bool invalid_line = false;
- int k;
-
- k = read_stripped_line(f, LONG_LINE_MAX, &line);
- if (k < 0)
- return log_error_errno(k, "Failed to read '%s': %m", fn);
- if (k == 0)
- break;
-
- v++;
-
- if (IN_SET(line[0], 0, '#'))
- continue;
-
- 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 */
- *invalid_config = true;
- else if (r == 0)
- /* The first error becomes our return value */
- r = k;
- }
- }
+ r = conf_file_read(arg_root, (const char**) config_dirs, fn,
+ parse_line, c, ignore_enoent, invalid_config);
+ if (r <= 0)
+ return r;
/* we have to determine age parameter for each entry of type X */
ORDERED_HASHMAP_FOREACH(ia, c->globs)
@@ -4319,12 +4273,6 @@ static int read_config_file(
}
}
- if (ferror(f)) {
- log_error_errno(errno, "Failed to read from file %s: %m", fn);
- if (r == 0)
- r = -EIO;
- }
-
return r;
}