]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
conf-files: make conf_file_new() take ConfFilesFlags rather than ChaseFlags
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 13 Jan 2026 06:26:41 +0000 (15:26 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 20 Jan 2026 02:05:54 +0000 (11:05 +0900)
No functional change, preparation for later commit.

(cherry picked from commit 5d0dc9915ca6b1f0b5ed5f37b2d080ae1981a489)

src/basic/basic-forward.h
src/basic/conf-files.c
src/basic/conf-files.h
src/shared/pretty-print.c
src/udev/fuzz-udev-rules.c
src/udev/udevadm-util.c

index d26cc5fe9b2a4afe4ac7058912e3057f65a6ca53..38680ac14a54f8929ef0cf7dfd8eb99720958f82 100644 (file)
@@ -85,6 +85,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;
index a0aeb81803737a9a5d3f12ceae1b01bbacf806e6..12290a564603e8f07fe79e01c6fddadf71f03d12 100644 (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;
         }
index 05a2966e216eac140ea7004182330a79d4c0037d..0e75905b9e4251c7a766aaf1afb79038bc3a0b79 100644 (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);
index 36f552960b70940e62d1d896e6e9ad5ca4e513c4..9829a57cd6dbd8c63b972eb2ff55cd2b2b92dcbd 100644 (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;
                 }
 
index e91954311da66e0a481201e7ab9d06cb4aa2a6c5..b3387e885602f04ab07cbd3985af92382fa021af 100644 (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);
index a171060471a230c4d3def2359444149dcf9bed41..1ab9b0c8ca4b3e1abbc264fb3d80660e33648392 100644 (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();