fileio: optionally, return discovered path of file in search_and_fopen()

This commit is contained in:
Lennart Poettering
2021-05-07 16:43:26 +02:00
parent ac2c088939
commit 2708160ccd
9 changed files with 146 additions and 71 deletions
+4 -3
View File
@@ -62,12 +62,13 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
static int apply_file(struct kmod_ctx *ctx, const char *path, bool ignore_enoent) {
_cleanup_fclose_ FILE *f = NULL;
_cleanup_free_ char *pp = NULL;
int r;
assert(ctx);
assert(path);
r = search_and_fopen_nulstr(path, "re", NULL, conf_file_dirs, &f);
r = search_and_fopen_nulstr(path, "re", NULL, conf_file_dirs, &f, &pp);
if (r < 0) {
if (ignore_enoent && r == -ENOENT)
return 0;
@@ -75,7 +76,7 @@ static int apply_file(struct kmod_ctx *ctx, const char *path, bool ignore_enoent
return log_error_errno(r, "Failed to open %s: %m", path);
}
log_debug("apply: %s", path);
log_debug("apply: %s", pp);
for (;;) {
_cleanup_free_ char *line = NULL;
char *l;
@@ -83,7 +84,7 @@ static int apply_file(struct kmod_ctx *ctx, const char *path, bool ignore_enoent
k = read_line(f, LONG_LINE_MAX, &line);
if (k < 0)
return log_error_errno(k, "Failed to read file '%s': %m", path);
return log_error_errno(k, "Failed to read file '%s': %m", pp);
if (k == 0)
break;