conf-files: make conf_file_new() take ConfFilesFlags rather than ChaseFlags

No functional change, preparation for later commit.
This commit is contained in:
Yu Watanabe
2026-01-16 23:01:04 +09:00
parent 0c109deda1
commit 5d0dc9915c
6 changed files with 25 additions and 23 deletions
+1
View File
@@ -86,6 +86,7 @@ union sockaddr_union;
typedef enum CGroupFlags CGroupFlags;
typedef enum CGroupMask CGroupMask;
typedef enum ChaseFlags ChaseFlags;
typedef enum ConfFilesFlags ConfFilesFlags;
typedef enum ExtractFlags ExtractFlags;
typedef enum ForkFlags ForkFlags;
typedef enum Glyph Glyph;
+17 -13
View File
@@ -252,7 +252,7 @@ static int conf_file_chase_and_verify(
return 0;
}
int conf_file_new_at(const char *path, int rfd, ChaseFlags chase_flags, ConfFile **ret) {
int conf_file_new_at(const char *path, int rfd, ConfFilesFlags flags, ConfFile **ret) {
int r;
assert(path);
@@ -285,9 +285,7 @@ int conf_file_new_at(const char *path, int rfd, ChaseFlags chase_flags, ConfFile
return log_debug_errno(r, "Failed to extract directory from '%s': %m", path);
if (r >= 0) {
r = chaseat(rfd, dirpath,
CHASE_AT_RESOLVE_IN_ROOT |
CHASE_MUST_BE_DIRECTORY |
(FLAGS_SET(chase_flags, CHASE_NONEXISTENT) ? CHASE_NONEXISTENT : 0),
CHASE_MUST_BE_DIRECTORY | conf_files_chase_flags(flags),
&resolved_dirpath, /* ret_fd= */ NULL);
if (r < 0)
return log_debug_errno(r, "Failed to chase '%s%s': %m", empty_to_root(root), skip_leading_slash(dirpath));
@@ -297,22 +295,28 @@ int conf_file_new_at(const char *path, int rfd, ChaseFlags chase_flags, ConfFile
if (!c->result)
return log_oom_debug();
r = chaseat(rfd, c->result, CHASE_AT_RESOLVE_IN_ROOT | chase_flags, &c->resolved_path, &c->fd);
r = conf_file_chase_and_verify(
rfd,
root,
c->original_path,
c->result,
c->name,
/* masked= */ NULL,
flags,
&c->resolved_path,
&c->fd,
&c->st);
if (r < 0)
return log_debug_errno(r, "Failed to chase '%s%s': %m", empty_to_root(root), skip_leading_slash(c->original_path));
if (c->fd >= 0 && fstat(c->fd, &c->st) < 0)
return log_debug_errno(r, "Failed to stat '%s%s': %m", empty_to_root(root), skip_leading_slash(c->resolved_path));
return r;
*ret = TAKE_PTR(c);
return 0;
}
int conf_file_new(const char *path, const char *root, ChaseFlags chase_flags, ConfFile **ret) {
int conf_file_new(const char *path, const char *root, ConfFilesFlags flags, ConfFile **ret) {
int r;
assert(path);
assert((chase_flags & (CHASE_PREFIX_ROOT | CHASE_STEP)) == 0);
assert(ret);
_cleanup_free_ char *root_abs = NULL;
@@ -331,7 +335,7 @@ int conf_file_new(const char *path, const char *root, ChaseFlags chase_flags, Co
}
_cleanup_(conf_file_freep) ConfFile *c = NULL;
r = conf_file_new_at(path, rfd, chase_flags, &c);
r = conf_file_new_at(path, rfd, flags, &c);
if (r < 0)
return r;
@@ -598,7 +602,7 @@ static int conf_files_list_impl(
root = empty_to_root(root);
if (replacement) {
r = conf_file_new_at(replacement, rfd, CHASE_NONEXISTENT, &c);
r = conf_file_new_at(replacement, rfd, /* flags= */ 0, &c);
if (r < 0)
return r;
}
+2 -2
View File
@@ -29,8 +29,8 @@ ConfFile* conf_file_free(ConfFile *c);
DEFINE_TRIVIAL_CLEANUP_FUNC(ConfFile*, conf_file_free);
void conf_file_free_many(ConfFile **array, size_t n);
int conf_file_new_at(const char *path, int rfd, ChaseFlags chase_flags, ConfFile **ret);
int conf_file_new(const char *path, const char *root, ChaseFlags chase_flags, ConfFile **ret);
int conf_file_new_at(const char *path, int rfd, ConfFilesFlags flags, ConfFile **ret);
int conf_file_new(const char *path, const char *root, ConfFilesFlags flags, ConfFile **ret);
int conf_files_list(char ***ret, const char *suffix, const char *root, ConfFilesFlags flags, const char *dir);
int conf_files_list_at(char ***ret, const char *suffix, int rfd, ConfFilesFlags flags, const char *dir);
+2 -3
View File
@@ -6,7 +6,6 @@
#include <unistd.h>
#include "alloc-util.h"
#include "chase.h"
#include "color-util.h"
#include "conf-files.h"
#include "constants.h"
@@ -325,7 +324,7 @@ static int cat_file_by_path(const char *p, bool *newline, CatFlags flags) {
assert(p);
r = conf_file_new(p, /* root= */ NULL, CHASE_MUST_BE_REGULAR, &c);
r = conf_file_new(p, /* root= */ NULL, CONF_FILES_REGULAR, &c);
if (r < 0)
return log_error_errno(r, "Failed to chase '%s': %m", p);
@@ -458,7 +457,7 @@ int conf_files_cat(const char *root, const char *name, CatFlags flags) {
if (!p)
return log_oom();
if (conf_file_new(p, root, CHASE_MUST_BE_REGULAR, &c) >= 0)
if (conf_file_new(p, root, CONF_FILES_REGULAR, &c) >= 0)
break;
}
+1 -2
View File
@@ -2,7 +2,6 @@
#include <stdio.h>
#include "chase.h"
#include "conf-files.h"
#include "fd-util.h"
#include "fuzz.h"
@@ -29,7 +28,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
assert_se(rules = udev_rules_new(RESOLVE_NAME_EARLY));
_cleanup_(conf_file_freep) ConfFile *c = NULL;
ASSERT_OK(conf_file_new(filename, /* root= */ NULL, CHASE_MUST_BE_REGULAR, &c));
ASSERT_OK(conf_file_new(filename, /* root= */ NULL, CONF_FILES_REGULAR, &c));
r = udev_rules_parse_file(rules, c, /* extra_checks= */ false, /* ret= */ NULL);
log_info_errno(r, "Parsing %s: %m", filename);
+2 -3
View File
@@ -7,7 +7,6 @@
#include "alloc-util.h"
#include "bus-error.h"
#include "bus-util.h"
#include "chase.h"
#include "conf-files.h"
#include "constants.h"
#include "device-private.h"
@@ -249,7 +248,7 @@ static int search_rules_file_in_conf_dirs(const char *s, const char *root, ConfF
return log_oom();
_cleanup_(conf_file_freep) ConfFile *c = NULL;
r = conf_file_new(path, root, CHASE_MUST_BE_REGULAR, &c);
r = conf_file_new(path, root, CONF_FILES_REGULAR, &c);
if (r == -ENOENT)
continue;
if (r < 0)
@@ -279,7 +278,7 @@ static int search_rules_file(const char *s, const char *root, ConfFile ***files,
/* If not found, or if it is a path, then chase it. */
_cleanup_(conf_file_freep) ConfFile *c = NULL;
r = conf_file_new(s, root, CHASE_MUST_BE_REGULAR, &c);
r = conf_file_new(s, root, CONF_FILES_REGULAR, &c);
if (r >= 0) {
if (!GREEDY_REALLOC_APPEND(*files, *n_files, &c, 1))
return log_oom();