]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fd-util: add wildcard_fd_is_valid() helper and use it tree-wide
authorLennart Poettering <lennart@amutable.com>
Thu, 28 May 2026 10:42:12 +0000 (12:42 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 28 May 2026 12:33:08 +0000 (13:33 +0100)
Many *at()-style helpers accept a directory fd that may be either a
regular, valid fd (>= 0) or one of the special AT_FDCWD/XAT_FDROOT
wildcard values, and open-code that check in their assertions. Add a
wildcard_fd_is_valid() helper for it and use it tree-wide.

21 files changed:
src/basic/btrfs-util.c
src/basic/chase.c
src/basic/conf-files.c
src/basic/fd-util.c
src/basic/fd-util.h
src/basic/fileio.c
src/basic/fs-util.c
src/basic/mountpoint-util.c
src/basic/os-util.c
src/basic/socket-util.c
src/basic/stat-util.c
src/kernel-install/kernel-install.c
src/libsystemd/sd-id128/id128-util.c
src/libsystemd/sd-id128/sd-id128.c
src/shared/boot-entry.c
src/shared/btrfs-util.c
src/shared/conf-parser.c
src/shared/find-esp.c
src/shared/kernel-config.c
src/shared/kernel-image.c
src/shared/vpick.c

index 941d66c93cf1121a74de1296dd2c1a0d2143196a..1c605a9ef2f60f093294448c4dadc11560cbd17a 100644 (file)
@@ -48,7 +48,7 @@ int btrfs_subvol_make(int dir_fd, const char *path) {
         _cleanup_close_ int fd = -EBADF;
         int r;
 
-        assert(dir_fd >= 0 || IN_SET(dir_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(dir_fd));
         assert(!isempty(path));
 
         r = extract_subvolume_name(path, &subvolume);
index 66c78fc8ddb5609dc7289d9f80b73d2707b9b41a..23a523798eb2b9a1310fff5252491d49bb01f8d5 100644 (file)
@@ -62,7 +62,7 @@ static int chase_openat2(int root_fd, int dir_fd, const char *path, ChaseFlags c
         int r;
 
         assert(path);
-        assert(dir_fd >= 0 || IN_SET(dir_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(dir_fd));
 
         if (!can_openat2)
                 return -EOPNOTSUPP;
@@ -241,8 +241,8 @@ int chaseat(int root_fd, int dir_fd, const char *path, ChaseFlags flags, char **
         assert(!FLAGS_SET(flags, CHASE_PREFIX_ROOT));
         assert(!FLAGS_SET(flags, CHASE_STEP|CHASE_EXTRACT_FILENAME));
         assert(!FLAGS_SET(flags, CHASE_NO_AUTOFS|CHASE_TRIGGER_AUTOFS));
-        assert(dir_fd >= 0 || IN_SET(dir_fd, AT_FDCWD, XAT_FDROOT));
-        assert(root_fd >= 0 || IN_SET(root_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(dir_fd));
+        assert(wildcard_fd_is_valid(root_fd));
         /* AT_FDCWD for dir_fd is only allowed when there is no chroot boundary: otherwise the current
          * working directory might live outside root_fd's subtree. */
         assert(dir_fd != AT_FDCWD || IN_SET(root_fd, AT_FDCWD, XAT_FDROOT));
index d4ff194d4cce45aaf8dd293353f97f2d1d483819..8a934a41b46b7e07269be912b27eb69c863c58c1 100644 (file)
@@ -155,7 +155,7 @@ static int conf_file_chase_and_verify(
         struct stat st = {};
         int r;
 
-        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(rfd));
         assert(original_path);
         assert(path);
         assert(name);
@@ -274,7 +274,7 @@ int conf_file_new_at(
         int r;
 
         assert(path);
-        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(rfd));
         assert(ret);
 
         int log_level = conf_files_log_level(flags);
@@ -390,7 +390,7 @@ static int files_add(
         assert(dir);
         assert(original_dirpath);
         assert(resolved_dirpath);
-        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(rfd));
         assert(files);
         assert(masked);
 
@@ -622,7 +622,7 @@ static int conf_files_list_impl(
         const ConfFile *inserted = NULL;
         int r;
 
-        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(rfd));
         assert(ret);
 
         root = empty_to_root(root);
@@ -736,7 +736,7 @@ int conf_files_list_strv_at(
         _cleanup_free_ char *root = NULL;
         int r;
 
-        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(rfd));
         assert(ret);
 
         if (DEBUG_LOGGING)
@@ -761,7 +761,7 @@ int conf_files_list_strv_at_full(
         _cleanup_free_ char *root = NULL;
         int r;
 
-        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(rfd));
         assert(ret_files);
         assert(ret_n_files);
 
index c2d46aae155a26ec06504d39c418b4bb2075a666..c6e78c59b6954074d3e553f90f4752b327b1a4ff 100644 (file)
@@ -581,7 +581,7 @@ bool fdname_is_valid(const char *s) {
 int fd_get_path(int fd, char **ret) {
         int r;
 
-        assert(fd >= 0 || IN_SET(fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(fd));
 
         if (fd == AT_FDCWD)
                 return safe_getcwd(ret);
@@ -781,7 +781,7 @@ finish:
 }
 
 int fd_reopen(int fd, int flags) {
-        assert(fd >= 0 || IN_SET(fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(fd));
         assert(!FLAGS_SET(flags, O_CREAT));
 
         /* Reopens the specified fd with new flags. This is useful for convert an O_PATH fd into a regular one, or to
@@ -1052,7 +1052,7 @@ static bool is_literal_root(const char *p) {
 }
 
 int path_is_root_at(int dir_fd, const char *path) {
-        assert(dir_fd >= 0 || IN_SET(dir_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(dir_fd));
 
         if (dir_fd == XAT_FDROOT && isempty(path))
                 return true;
@@ -1086,8 +1086,8 @@ int fds_inode_and_mount_same(int fd1, int fd2) {
         struct statx sx1, sx2;
         int r;
 
-        assert(fd1 >= 0 || IN_SET(fd1, AT_FDCWD, XAT_FDROOT));
-        assert(fd2 >= 0 || IN_SET(fd2, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(fd1));
+        assert(wildcard_fd_is_valid(fd2));
 
         r = xstatx(fd1, /* path = */ NULL, AT_EMPTY_PATH,
                    STATX_TYPE|STATX_INO|STATX_MNT_ID,
index c15ce7fddde4a74c37cbdce50bd7ec298c73fb81..86bddb6dac4473785b913278e3655f7d426f9e24 100644 (file)
 assert_cc(XAT_FDROOT != AT_FDCWD);
 assert_cc(XAT_FDROOT < -ERRNO_MAX);
 
+/* Checks whether the specified fd is acceptable as a *at() directory fd that supports the two "wildcard"
+ * values: it's either a regular, valid fd (i.e. >= 0), or one of the special AT_FDCWD/XAT_FDROOT values. */
+static inline bool wildcard_fd_is_valid(int fd) {
+        return fd >= 0 || IN_SET(fd, AT_FDCWD, XAT_FDROOT);
+}
+
 int close_nointr(int fd);
 int safe_close(int fd);
 void safe_close_pair(int p[static 2]);
index de2ac6af726e7a16b774f77d0674fb448d73e24f..1f2143e88548d7e2c974037d42a41f126c06d7e6 100644 (file)
@@ -420,7 +420,7 @@ int read_one_line_file_at(int dir_fd, const char *filename, char **ret) {
         _cleanup_fclose_ FILE *f = NULL;
         int r;
 
-        assert(dir_fd >= 0 || IN_SET(dir_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(dir_fd));
         assert(filename);
         assert(ret);
 
@@ -435,7 +435,7 @@ int read_boolean_file_at(int dir_fd, const char *filename) {
         _cleanup_free_ char *s = NULL;
         int r;
 
-        assert(dir_fd >= 0 || IN_SET(dir_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(dir_fd));
         assert(filename);
 
         r = read_one_line_file_at(dir_fd, filename, &s);
@@ -1024,7 +1024,7 @@ static int xfopenat_regular(int dir_fd, const char *path, const char *mode, int
 
         /* A combination of fopen() with openat() */
 
-        assert(dir_fd >= 0 || IN_SET(dir_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(dir_fd));
         assert(mode);
         assert(ret);
 
@@ -1071,7 +1071,7 @@ static int xfopenat_unix_socket(int dir_fd, const char *path, const char *bind_n
         FILE *f;
         int r;
 
-        assert(dir_fd >= 0 || IN_SET(dir_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(dir_fd));
         assert(ret);
 
         sk = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
@@ -1119,7 +1119,7 @@ int xfopenat_full(
         FILE *f = NULL;  /* avoid false maybe-uninitialized warning */
         int r;
 
-        assert(dir_fd >= 0 || IN_SET(dir_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(dir_fd));
         assert(mode);
         assert(ret);
 
@@ -1689,7 +1689,7 @@ int write_data_file_atomic_at(
 
         int r;
 
-        assert(dir_fd >= 0 || IN_SET(dir_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(dir_fd));
 
         /* This is a cousin of write_string_file_atomic(), but operates with arbitrary struct iovec binary
          * data (rather than strings), works without FILE* streams, and does direct syscalls instead. */
index b51d63089823971fdaa5241b9615f646a0f8dfaf..2e9a27f2a855af1c7e29997269dd080fbb2b04b1 100644 (file)
@@ -1176,7 +1176,7 @@ int xopenat_full(int dir_fd, const char *path, int open_flags, XOpenFlags xopen_
         bool made_dir = false, made_file = false;
         int r;
 
-        assert(dir_fd >= 0 || IN_SET(dir_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(dir_fd));
 
         /* An inode can only be one of a directory, a regular file or a socket at the same time. */
         assert(FLAGS_SET(open_flags, O_DIRECTORY) + FLAGS_SET(xopen_flags, XO_REGULAR) + FLAGS_SET(xopen_flags, XO_SOCKET) <= 1);
index 7c043bb54a4b9b4b0a2866e4f6e4565f6e0ea649..7aa14f7cd20422089e7a406547bcbb06614466d4 100644 (file)
@@ -242,7 +242,7 @@ struct file_handle* file_handle_dup(const struct file_handle *fh) {
 int is_mount_point_at(int dir_fd, const char *path, int flags) {
         int r;
 
-        assert(dir_fd >= 0 || IN_SET(dir_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(dir_fd));
         assert((flags & ~AT_SYMLINK_FOLLOW) == 0);
 
         if (path_equal(path, "/"))
@@ -306,7 +306,7 @@ static int path_get_mnt_id_at_internal(int dir_fd, const char *path, bool unique
         struct statx sx;
         int r;
 
-        assert(dir_fd >= 0 || IN_SET(dir_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(dir_fd));
         assert(ret);
 
         r = xstatx(dir_fd, path,
index bb87fe371c2166d2df42137efb55dc1f433d66e6..0bcd49cf5f69c9dabf84aa28b8c58310bbc088f9 100644 (file)
@@ -170,7 +170,7 @@ int open_os_release_at(int rfd, char **ret_path, int *ret_fd) {
         const char *e;
         int r;
 
-        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(rfd));
 
         e = secure_getenv("SYSTEMD_OS_RELEASE");
         if (e)
@@ -227,7 +227,7 @@ int open_extension_release_at(
         const char *p;
         int r;
 
-        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(rfd));
         assert(!extension || (image_class >= 0 && image_class < _IMAGE_CLASS_MAX));
 
         if (!extension)
@@ -372,7 +372,7 @@ static int parse_extension_release_atv(
         _cleanup_free_ char *p = NULL;
         int r;
 
-        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(rfd));
 
         r = open_extension_release_at(rfd, image_class, extension, relax_extension_release_check, &p, &fd);
         if (r < 0)
@@ -391,7 +391,7 @@ int parse_extension_release_at_sentinel(
         va_list ap;
         int r;
 
-        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(rfd));
 
         va_start(ap, extension);
         r = parse_extension_release_atv(rfd, image_class, extension, relax_extension_release_check, ap);
index d84537bf4413a4788df24c391b1810d140152b5d..c48ffbc3d0e59eff915951fccdcaeb233480c729 100644 (file)
@@ -1621,7 +1621,7 @@ int connect_unix_path(int fd, int dir_fd, const char *path) {
         _cleanup_close_ int inode_fd = -EBADF;
 
         assert(fd >= 0);
-        assert(IN_SET(dir_fd, AT_FDCWD, XAT_FDROOT) || dir_fd >= 0);
+        assert(wildcard_fd_is_valid(dir_fd));
 
         /* Connects to the specified AF_UNIX socket in the file system. Works around the 108 byte size limit
          * in sockaddr_un, by going via O_PATH if needed. This hence works for any kind of path. */
index bbfb8a9d1879b6de2e924d2e2b1d80304a819be7..bec84487f7280527fc4513a331466739023257a7 100644 (file)
@@ -32,7 +32,7 @@ static int verify_stat_at(
         struct stat st;
         int r;
 
-        assert(fd >= 0 || IN_SET(fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(fd));
         assert(!isempty(path) || !follow);
         assert(verify_func);
 
@@ -418,7 +418,7 @@ int xstatx_full(int fd,
          *    STATX_MNT_ID if not.
          */
 
-        assert(fd >= 0 || IN_SET(fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(fd));
         assert((mandatory_mask & optional_mask) == 0);
         assert(!FLAGS_SET(xstatx_flags, XSTATX_MNT_ID_BEST) || !((mandatory_mask|optional_mask) & (STATX_MNT_ID|STATX_MNT_ID_UNIQUE)));
         assert(ret);
@@ -480,7 +480,7 @@ static int xfstatfs(int fd, struct statfs *ret) {
 int xstatfsat(int dir_fd, const char *path, struct statfs *ret) {
         _cleanup_close_ int fd = -EBADF;
 
-        assert(dir_fd >= 0 || IN_SET(dir_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(dir_fd));
         assert(ret);
 
         if (!isempty(path)) {
index ff93a80c0867ac2570b365c9609d59539f78c60c..c77b23d4bc0f8ada71d12841c57c51028b72acba 100644 (file)
@@ -153,7 +153,7 @@ static int context_copy(const Context *source, Context *ret) {
 
         assert(source);
         assert(ret);
-        assert(source->rfd >= 0 || source->rfd == AT_FDCWD || source->rfd == XAT_FDROOT);
+        assert(wildcard_fd_is_valid(source->rfd));
 
         _cleanup_(context_done) Context copy = (Context) {
                 .rfd = source->rfd,
index 700c9268edac5e855dc6134a94a2ba49021efde7..b961be0659d97014864bfab73746e77e5995171e 100644 (file)
@@ -142,7 +142,7 @@ int id128_read_fd(int fd, Id128Flag f, sd_id128_t *ret) {
 int id128_read_at(int dir_fd, const char *path, Id128Flag f, sd_id128_t *ret) {
         _cleanup_close_ int fd = -EBADF;
 
-        assert(dir_fd >= 0 || IN_SET(dir_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(dir_fd));
         assert(path);
 
         fd = xopenat(dir_fd, path, O_RDONLY|O_CLOEXEC|O_NOCTTY);
index 852b01ab1a3f5e4ed6b56e9aaa5131b7fe65960e..ba3e47dd8d5c1bda9dcedded75a9e1f7e355dffc 100644 (file)
@@ -138,7 +138,7 @@ _public_ int sd_id128_get_machine(sd_id128_t *ret) {
 int id128_get_machine_at(int rfd, sd_id128_t *ret) {
         int r;
 
-        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(rfd));
 
         r = dir_fd_is_root_or_cwd(rfd);
         if (r < 0)
index b8665d7abbaffd0ff9c39ef02e35540a073ac18d..2e86ba8b318292352db647f83c88408a985df5d5 100644 (file)
@@ -21,7 +21,7 @@ static int entry_token_load_one(int rfd, const char *dir, BootEntryTokenType *ty
         _cleanup_fclose_ FILE *f = NULL;
         int r;
 
-        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(rfd));
         assert(dir);
         assert(type);
         assert(*type == BOOT_ENTRY_TOKEN_AUTO);
@@ -57,7 +57,7 @@ static int entry_token_load_one(int rfd, const char *dir, BootEntryTokenType *ty
 static int entry_token_load(int rfd, const char *conf_root, BootEntryTokenType *type, char **token) {
         int r;
 
-        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(rfd));
         assert(type);
         assert(*type == BOOT_ENTRY_TOKEN_AUTO);
         assert(token);
@@ -97,7 +97,7 @@ static int entry_token_from_os_release(int rfd, BootEntryTokenType *type, char *
         _cleanup_free_ char *id = NULL, *image_id = NULL;
         int r;
 
-        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(rfd));
         assert(type);
         assert(IN_SET(*type, BOOT_ENTRY_TOKEN_AUTO, BOOT_ENTRY_TOKEN_OS_IMAGE_ID, BOOT_ENTRY_TOKEN_OS_ID));
         assert(token);
@@ -150,7 +150,7 @@ int boot_entry_token_ensure_at(
 
         int r;
 
-        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(rfd));
         assert(type);
         assert(token);
 
index daa67e6f5cfe32adfa59ff3bc7820310a67974f7..f721e68753ab2a2912e5914d8da03d089caa384c 100644 (file)
@@ -109,7 +109,7 @@ int btrfs_get_block_device_at_full(int dir_fd, const char *path, uint64_t *ret_d
          * ret - the returned block device
          */
 
-        assert(dir_fd >= 0 || IN_SET(dir_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(dir_fd));
 
         fd = xopenat(dir_fd, path, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
         if (fd < 0)
index bfba85564f834f6fbdc8f92d35050b32db15d03f..f9f113eadc0258875d037a14c6bcdb77fe71cd4c 100644 (file)
@@ -603,7 +603,7 @@ static int normalize_root_fd(const char *root, int *root_fd, int *ret_opened_fd)
         /* Normalizes a root dir specification: if root_fd is already valid, keep it. Otherwise, we open the
          * specified dir */
 
-        if (*root_fd >= 0 || IN_SET(*root_fd, AT_FDCWD, XAT_FDROOT)) {
+        if (wildcard_fd_is_valid(*root_fd)) {
                 *ret_opened_fd = -EBADF;
                 return 0;
         }
index 7337d9f99901870c298198bb56878be0d82b6364..201222e10e5b2dc6253e4eb9f6acd58af6642b30 100644 (file)
@@ -323,7 +323,7 @@ static int verify_esp(
                 unprivileged_mode = FLAGS_SET(flags, VERIFY_ESP_UNPRIVILEGED_MODE);
         int r;
 
-        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(rfd));
         assert(path);
 
         /* This logs about all errors, except:
@@ -420,7 +420,7 @@ int find_esp_and_warn_at_full(
         VerifyESPFlags flags;
         int r;
 
-        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(rfd));
 
         /* This logs about all errors except:
          *
@@ -733,7 +733,7 @@ static int verify_xbootldr(
                 unprivileged_mode = FLAGS_SET(flags, VERIFY_ESP_UNPRIVILEGED_MODE);
         int r;
 
-        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(rfd));
         assert(path);
 
         _cleanup_free_ char *p = NULL;
@@ -796,7 +796,7 @@ int find_xbootldr_and_warn_at_full(
 
         /* Similar to find_esp_and_warn(), but finds the XBOOTLDR partition. Returns the same errors. */
 
-        assert(rfd >= 0 || IN_SET(rfd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(rfd));
 
         flags = verify_esp_flags_init(unprivileged_mode, "SYSTEMD_RELAX_XBOOTLDR_CHECKS");
 
index 415730bf1a39f59fda8bd4206f13252f1f0ebdfb..3f575439a784058328d31f11fd522b31a09e4127 100644 (file)
@@ -28,7 +28,7 @@ int load_kernel_install_conf_at(
         };
         int r;
 
-        assert(root_fd >= 0 || IN_SET(root_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(root_fd));
 
         if (conf_root) {
                 _cleanup_free_ char *conf = path_join(conf_root, "install.conf");
index e2db555cb4491ebda05b4fb0f42331ec4d1fe6c2..406c3e89cfd7d0633c7317d35b203a284a66379e 100644 (file)
@@ -130,7 +130,7 @@ int inspect_kernel_full(
         _cleanup_close_ int fd = -EBADF;
         int r;
 
-        assert(dir_fd >= 0 || IN_SET(dir_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(dir_fd));
 
         fd = xopenat(dir_fd, filename, O_RDONLY|O_CLOEXEC);
         if (fd < 0)
index b68991cda19b67d93884ec1f7002c68b66815637..7890fb1708830b2db3b5feb4fdcd99684b43eab1 100644 (file)
@@ -190,7 +190,7 @@ static int pin_choice(
         _cleanup_free_ char *resolved_path = NULL;
         int r;
 
-        assert(toplevel_fd >= 0 || IN_SET(toplevel_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(toplevel_fd));
         assert(inode_path);
         assert(filter);
         assert(ret);
@@ -322,7 +322,7 @@ static int make_choice(
         _cleanup_close_ int inode_fd = TAKE_FD(_inode_fd);
         int r;
 
-        assert(toplevel_fd >= 0 || IN_SET(toplevel_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(toplevel_fd));
         assert(inode_path);
         assert(filter);
         assert(ret);
@@ -513,7 +513,7 @@ static int path_pick_one(
         uint32_t filter_type_mask;
         int r;
 
-        assert(toplevel_fd >= 0 || IN_SET(toplevel_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(toplevel_fd));
         assert(path);
         assert(filter);
         assert(ret);
@@ -662,7 +662,7 @@ int path_pick(const char *toplevel_path,
         _cleanup_(pick_result_done) PickResult best = PICK_RESULT_NULL;
         int r;
 
-        assert(toplevel_fd >= 0 || IN_SET(toplevel_fd, AT_FDCWD, XAT_FDROOT));
+        assert(wildcard_fd_is_valid(toplevel_fd));
         assert(path);
         assert(filters || n_filters == 0);
         assert(ret);