fd-util: add wildcard_fd_is_valid() helper and use it tree-wide
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.
This commit is contained in:
committed by
Luca Boccassi
parent
d35fa257eb
commit
eb3799a373
@@ -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);
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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)
|
||||
|
||||
+4
-4
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user