chase-symlinks: Rename chase_symlinks() to chase()

Chasing symlinks is a core function that's used in a lot of places
so it deservers a less verbose names so let's rename it to chase()
and chaseat().

We also slightly change the pattern used for the chaseat() helpers
so we get chase_and_openat() and similar.
This commit is contained in:
Daan De Meyer
2023-03-24 13:43:51 +01:00
committed by Zbigniew Jędrzejewski-Szmek
parent 0da2780c8a
commit f461a28da7
64 changed files with 374 additions and 384 deletions
+5 -5
View File
@@ -4,7 +4,7 @@
#include "bootspec-fundamental.h"
#include "bootspec.h"
#include "chase-symlinks.h"
#include "chase.h"
#include "conf-files.h"
#include "devnum-util.h"
#include "dirent-util.h"
@@ -507,7 +507,7 @@ static int boot_loader_read_conf_path(BootConfig *config, const char *root, cons
assert(config);
assert(path);
r = chase_symlinks_and_fopen_unlocked(path, root, CHASE_PREFIX_ROOT|CHASE_PROHIBIT_SYMLINKS, "re", &full, &f);
r = chase_and_fopen_unlocked(path, root, CHASE_PREFIX_ROOT|CHASE_PROHIBIT_SYMLINKS, "re", &full, &f);
if (r == -ENOENT)
return 0;
if (r < 0)
@@ -592,7 +592,7 @@ static int boot_entries_find_type1(
assert(root);
assert(dir);
dir_fd = chase_symlinks_and_open(dir, root, CHASE_PREFIX_ROOT|CHASE_PROHIBIT_SYMLINKS, O_DIRECTORY|O_CLOEXEC, &full);
dir_fd = chase_and_open(dir, root, CHASE_PREFIX_ROOT|CHASE_PROHIBIT_SYMLINKS, O_DIRECTORY|O_CLOEXEC, &full);
if (dir_fd == -ENOENT)
return 0;
if (dir_fd < 0)
@@ -854,7 +854,7 @@ static int boot_entries_find_unified(
assert(config);
assert(dir);
r = chase_symlinks_and_opendir(dir, root, CHASE_PREFIX_ROOT|CHASE_PROHIBIT_SYMLINKS, &full, &d);
r = chase_and_opendir(dir, root, CHASE_PREFIX_ROOT|CHASE_PROHIBIT_SYMLINKS, &full, &d);
if (r == -ENOENT)
return 0;
if (r < 0)
@@ -1269,7 +1269,7 @@ static void boot_entry_file_list(
assert(p);
assert(ret_status);
int status = chase_symlinks_and_access(p, root, CHASE_PREFIX_ROOT|CHASE_PROHIBIT_SYMLINKS, F_OK, NULL);
int status = chase_and_access(p, root, CHASE_PREFIX_ROOT|CHASE_PROHIBIT_SYMLINKS, F_OK, NULL);
/* Note that this shows two '/' between the root and the file. This is intentional to highlight (in
* the absence of color support) to the user that the boot loader is only interested in the second
+6 -6
View File
@@ -14,7 +14,7 @@
#include "alloc-util.h"
#include "btrfs-util.h"
#include "chase-symlinks.h"
#include "chase.h"
#include "chattr-util.h"
#include "copy.h"
#include "dirent-util.h"
@@ -459,7 +459,7 @@ int image_find(ImageClass class,
struct stat st;
int flags;
r = chase_symlinks_and_opendir(path, root, CHASE_PREFIX_ROOT, &resolved, &d);
r = chase_and_opendir(path, root, CHASE_PREFIX_ROOT, &resolved, &d);
if (r == -ENOENT)
continue;
if (r < 0)
@@ -556,7 +556,7 @@ int image_discover(
_cleanup_free_ char *resolved = NULL;
_cleanup_closedir_ DIR *d = NULL;
r = chase_symlinks_and_opendir(path, root, CHASE_PREFIX_ROOT, &resolved, &d);
r = chase_and_opendir(path, root, CHASE_PREFIX_ROOT, &resolved, &d);
if (r == -ENOENT)
continue;
if (r < 0)
@@ -1149,7 +1149,7 @@ int image_read_metadata(Image *i) {
_cleanup_free_ char *hostname = NULL;
_cleanup_free_ char *path = NULL;
r = chase_symlinks("/etc/hostname", i->path, CHASE_PREFIX_ROOT|CHASE_TRAIL_SLASH, &path, NULL);
r = chase("/etc/hostname", i->path, CHASE_PREFIX_ROOT|CHASE_TRAIL_SLASH, &path, NULL);
if (r < 0 && r != -ENOENT)
log_debug_errno(r, "Failed to chase /etc/hostname in image %s: %m", i->name);
else if (r >= 0) {
@@ -1160,7 +1160,7 @@ int image_read_metadata(Image *i) {
path = mfree(path);
r = chase_symlinks("/etc/machine-id", i->path, CHASE_PREFIX_ROOT|CHASE_TRAIL_SLASH, &path, NULL);
r = chase("/etc/machine-id", i->path, CHASE_PREFIX_ROOT|CHASE_TRAIL_SLASH, &path, NULL);
if (r < 0 && r != -ENOENT)
log_debug_errno(r, "Failed to chase /etc/machine-id in image %s: %m", i->name);
else if (r >= 0) {
@@ -1178,7 +1178,7 @@ int image_read_metadata(Image *i) {
path = mfree(path);
r = chase_symlinks("/etc/machine-info", i->path, CHASE_PREFIX_ROOT|CHASE_TRAIL_SLASH, &path, NULL);
r = chase("/etc/machine-info", i->path, CHASE_PREFIX_ROOT|CHASE_TRAIL_SLASH, &path, NULL);
if (r < 0 && r != -ENOENT)
log_debug_errno(r, "Failed to chase /etc/machine-info in image %s: %m", i->name);
else if (r >= 0) {
+6 -6
View File
@@ -26,7 +26,7 @@
#include "blkid-util.h"
#include "blockdev-util.h"
#include "btrfs-util.h"
#include "chase-symlinks.h"
#include "chase.h"
#include "conf-files.h"
#include "constants.h"
#include "copy.h"
@@ -1650,7 +1650,7 @@ static int mount_partition(
if (r < 0 && r != -EROFS)
return r;
r = chase_symlinks(directory, where, CHASE_PREFIX_ROOT, &chased, NULL);
r = chase(directory, where, CHASE_PREFIX_ROOT, &chased, NULL);
if (r < 0)
return r;
@@ -1828,7 +1828,7 @@ int dissected_image_mount(
/* Mount the ESP to /efi if it exists. If it doesn't exist, use /boot instead, but only if it
* exists and is empty, and we didn't already mount the XBOOTLDR partition into it. */
r = chase_symlinks("/efi", where, CHASE_PREFIX_ROOT, NULL, NULL);
r = chase("/efi", where, CHASE_PREFIX_ROOT, NULL, NULL);
if (r < 0) {
if (r != -ENOENT)
return r;
@@ -1838,7 +1838,7 @@ int dissected_image_mount(
if (!xbootldr_mounted) {
_cleanup_free_ char *p = NULL;
r = chase_symlinks("/boot", where, CHASE_PREFIX_ROOT, &p, NULL);
r = chase("/boot", where, CHASE_PREFIX_ROOT, &p, NULL);
if (r < 0) {
if (r != -ENOENT)
return r;
@@ -3062,7 +3062,7 @@ int dissected_image_acquire_metadata(DissectedImage *m, DissectImageFlags extra_
"/lib/systemd/systemd", /* systemd on /usr non-merged systems */
"/sbin/init") { /* traditional path the Linux kernel invokes */
r = chase_symlinks(init, t, CHASE_PREFIX_ROOT, NULL, NULL);
r = chase(init, t, CHASE_PREFIX_ROOT, NULL, NULL);
if (r < 0) {
if (r != -ENOENT)
log_debug_errno(r, "Failed to resolve %s, ignoring: %m", init);
@@ -3081,7 +3081,7 @@ int dissected_image_acquire_metadata(DissectedImage *m, DissectImageFlags extra_
default:
NULSTR_FOREACH(p, paths[k]) {
fd = chase_symlinks_and_open(p, t, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC|O_NOCTTY, NULL);
fd = chase_and_open(p, t, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC|O_NOCTTY, NULL);
if (fd >= 0)
break;
}
+2 -2
View File
@@ -6,7 +6,7 @@
#include <stdlib.h>
#include "alloc-util.h"
#include "chase-symlinks.h"
#include "chase.h"
#include "conf-files.h"
#include "dirent-util.h"
#include "dropin.h"
@@ -105,7 +105,7 @@ static int unit_file_add_dir(
/* This adds [original_root]/path to dirs, if it exists. */
r = chase_symlinks(path, original_root, 0, &chased, NULL);
r = chase(path, original_root, 0, &chased, NULL);
if (r == -ENOENT) /* Ignore -ENOENT, after all most units won't have a drop-in dir. */
return 0;
if (r == -ENAMETOOLONG) {
+7 -7
View File
@@ -9,7 +9,7 @@
#include "alloc-util.h"
#include "blkid-util.h"
#include "btrfs-util.h"
#include "chase-symlinks.h"
#include "chase.h"
#include "device-util.h"
#include "devnum-util.h"
#include "env-util.h"
@@ -457,7 +457,7 @@ int find_esp_and_warn(
*/
if (path) {
r = chase_symlinks(path, root, CHASE_PREFIX_ROOT, &p, NULL);
r = chase(path, root, CHASE_PREFIX_ROOT, &p, NULL);
if (r < 0)
return log_error_errno(r,
"Failed to resolve path %s%s%s: %m",
@@ -476,7 +476,7 @@ int find_esp_and_warn(
if (path) {
struct stat st;
r = chase_symlinks(path, root, CHASE_PREFIX_ROOT, &p, NULL);
r = chase(path, root, CHASE_PREFIX_ROOT, &p, NULL);
if (r < 0)
return log_error_errno(r,
"Failed to resolve path %s%s%s: %m",
@@ -513,7 +513,7 @@ int find_esp_and_warn(
}
FOREACH_STRING(dir, "/efi", "/boot", "/boot/efi") {
r = chase_symlinks(dir, root, CHASE_PREFIX_ROOT, &p, NULL);
r = chase(dir, root, CHASE_PREFIX_ROOT, &p, NULL);
if (r == -ENOENT)
continue;
if (r < 0)
@@ -759,7 +759,7 @@ int find_xbootldr_and_warn(
/* Similar to find_esp_and_warn(), but finds the XBOOTLDR partition. Returns the same errors. */
if (path) {
r = chase_symlinks(path, root, CHASE_PREFIX_ROOT, &p, NULL);
r = chase(path, root, CHASE_PREFIX_ROOT, &p, NULL);
if (r < 0)
return log_error_errno(r,
"Failed to resolve path %s%s%s: %m",
@@ -778,7 +778,7 @@ int find_xbootldr_and_warn(
if (path) {
struct stat st;
r = chase_symlinks(path, root, CHASE_PREFIX_ROOT, &p, NULL);
r = chase(path, root, CHASE_PREFIX_ROOT, &p, NULL);
if (r < 0)
return log_error_errno(r,
"Failed to resolve path %s%s%s: %m",
@@ -804,7 +804,7 @@ int find_xbootldr_and_warn(
goto found;
}
r = chase_symlinks("/boot", root, CHASE_PREFIX_ROOT, &p, NULL);
r = chase("/boot", root, CHASE_PREFIX_ROOT, &p, NULL);
if (r == -ENOENT)
return -ENOKEY;
if (r < 0)
+4 -4
View File
@@ -10,7 +10,7 @@
#include <unistd.h>
#include "alloc-util.h"
#include "chase-symlinks.h"
#include "chase.h"
#include "conf-files.h"
#include "conf-parser.h"
#include "constants.h"
@@ -686,7 +686,7 @@ static int remove_marked_symlinks_fd(
if (!found) {
_cleanup_free_ char *dest = NULL;
q = chase_symlinks(p, lp->root_dir, CHASE_NONEXISTENT, &dest, NULL);
q = chase(p, lp->root_dir, CHASE_NONEXISTENT, &dest, NULL);
if (q == -ENOENT)
continue;
if (q < 0) {
@@ -1379,7 +1379,7 @@ static int unit_file_load(
if (!(flags & SEARCH_LOAD))
return 0;
fd = chase_symlinks_and_open(path, root_dir, 0, O_RDONLY|O_CLOEXEC|O_NOCTTY, NULL);
fd = chase_and_open(path, root_dir, 0, O_RDONLY|O_CLOEXEC|O_NOCTTY, NULL);
if (fd < 0)
return fd;
}
@@ -1918,7 +1918,7 @@ static int install_info_symlink_alias(
if (!alias_path)
return -ENOMEM;
q = chase_symlinks(alias_path, lp->root_dir, CHASE_NONEXISTENT, NULL, NULL);
q = chase(alias_path, lp->root_dir, CHASE_NONEXISTENT, NULL, NULL);
if (q < 0 && q != -ENOENT) {
r = r < 0 ? r : q;
continue;
+2 -2
View File
@@ -12,7 +12,7 @@
#endif
#include "alloc-util.h"
#include "chase-symlinks.h"
#include "chase.h"
#include "dissect-image.h"
#include "exec-util.h"
#include "extract-word.h"
@@ -844,7 +844,7 @@ static int mount_in_namespace(
if (r < 0)
return log_debug_errno(r == -ENOENT ? SYNTHETIC_ERRNO(EOPNOTSUPP) : r, "Target does not allow propagation of mount points");
r = chase_symlinks(src, NULL, 0, &chased_src_path, &chased_src_fd);
r = chase(src, NULL, 0, &chased_src_path, &chased_src_fd);
if (r < 0)
return log_debug_errno(r, "Failed to resolve source path of %s: %m", src);
log_debug("Chased source path of %s to %s", src, chased_src_path);
+3 -3
View File
@@ -10,7 +10,7 @@
#include "alloc-util.h"
#include "architecture.h"
#include "chase-symlinks.h"
#include "chase.h"
#include "fd-util.h"
#include "format-util.h"
#include "fs-util.h"
@@ -134,7 +134,7 @@ int specifier_real_path(char specifier, const void *data, const char *root, cons
if (!path)
return -ENOENT;
return chase_symlinks(path, root, 0, ret, NULL);
return chase(path, root, 0, ret, NULL);
}
int specifier_real_directory(char specifier, const void *data, const char *root, const void *userdata, char **ret) {
@@ -190,7 +190,7 @@ int specifier_machine_id(char specifier, const void *data, const char *root, con
if (root) {
_cleanup_close_ int fd = -EBADF;
fd = chase_symlinks_and_open("/etc/machine-id", root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC|O_NOCTTY, NULL);
fd = chase_and_open("/etc/machine-id", root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC|O_NOCTTY, NULL);
if (fd < 0)
/* Translate error for missing os-release file to EUNATCH. */
return fd == -ENOENT ? -EUNATCH : fd;
+3 -3
View File
@@ -9,7 +9,7 @@
#include <unistd.h>
#include "base-filesystem.h"
#include "chase-symlinks.h"
#include "chase.h"
#include "fd-util.h"
#include "initrd-util.h"
#include "log.h"
@@ -53,7 +53,7 @@ int switch_root(const char *new_root,
old_root_fd = safe_close(old_root_fd);
/* Determine where we shall place the old root after the transition */
r = chase_symlinks(old_root_after, new_root, CHASE_PREFIX_ROOT|CHASE_NONEXISTENT, &resolved_old_root_after, NULL);
r = chase(old_root_after, new_root, CHASE_PREFIX_ROOT|CHASE_NONEXISTENT, &resolved_old_root_after, NULL);
if (r < 0)
return log_error_errno(r, "Failed to resolve %s/%s: %m", new_root, old_root_after);
if (r == 0) /* Doesn't exist yet. Let's create it */
@@ -69,7 +69,7 @@ int switch_root(const char *new_root,
FOREACH_STRING(path, "/sys", "/dev", "/run", "/proc") {
_cleanup_free_ char *chased = NULL;
r = chase_symlinks(path, new_root, CHASE_PREFIX_ROOT|CHASE_NONEXISTENT, &chased, NULL);
r = chase(path, new_root, CHASE_PREFIX_ROOT|CHASE_NONEXISTENT, &chased, NULL);
if (r < 0)
return log_error_errno(r, "Failed to resolve %s/%s: %m", new_root, path);
if (r > 0) {
+2 -2
View File
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "chase-symlinks.h"
#include "chase.h"
#include "fd-util.h"
#include "fileio.h"
#include "missing_threads.h"
@@ -40,7 +40,7 @@ int read_login_defs(UGIDAllocationRange *ret_defs, const char *path, const char
if (!path)
path = "/etc/login.defs";
r = chase_symlinks_and_fopen_unlocked(path, root, CHASE_PREFIX_ROOT, "re", NULL, &f);
r = chase_and_fopen_unlocked(path, root, CHASE_PREFIX_ROOT, "re", NULL, &f);
if (r == -ENOENT)
goto defaults;
if (r < 0)