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:
committed by
Zbigniew Jędrzejewski-Szmek
parent
0da2780c8a
commit
f461a28da7
@@ -3,7 +3,7 @@
|
||||
#include <linux/magic.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "chase-symlinks.h"
|
||||
#include "chase.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "fs-util.h"
|
||||
@@ -24,7 +24,7 @@ bool unsafe_transition(const struct stat *a, const struct stat *b) {
|
||||
return a->st_uid != b->st_uid; /* Otherwise we need to stay within the same UID */
|
||||
}
|
||||
|
||||
static int log_unsafe_transition(int a, int b, const char *path, ChaseSymlinksFlags flags) {
|
||||
static int log_unsafe_transition(int a, int b, const char *path, ChaseFlags flags) {
|
||||
_cleanup_free_ char *n1 = NULL, *n2 = NULL, *user_a = NULL, *user_b = NULL;
|
||||
struct stat st;
|
||||
|
||||
@@ -44,7 +44,7 @@ static int log_unsafe_transition(int a, int b, const char *path, ChaseSymlinksFl
|
||||
strna(n1), strna(user_a), special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), strna(n2), strna(user_b), path);
|
||||
}
|
||||
|
||||
static int log_autofs_mount_point(int fd, const char *path, ChaseSymlinksFlags flags) {
|
||||
static int log_autofs_mount_point(int fd, const char *path, ChaseFlags flags) {
|
||||
_cleanup_free_ char *n1 = NULL;
|
||||
|
||||
if (!FLAGS_SET(flags, CHASE_WARN))
|
||||
@@ -57,7 +57,7 @@ static int log_autofs_mount_point(int fd, const char *path, ChaseSymlinksFlags f
|
||||
strna(n1), path);
|
||||
}
|
||||
|
||||
static int log_prohibited_symlink(int fd, ChaseSymlinksFlags flags) {
|
||||
static int log_prohibited_symlink(int fd, ChaseFlags flags) {
|
||||
_cleanup_free_ char *n1 = NULL;
|
||||
|
||||
assert(fd >= 0);
|
||||
@@ -72,16 +72,16 @@ static int log_prohibited_symlink(int fd, ChaseSymlinksFlags flags) {
|
||||
strna(n1));
|
||||
}
|
||||
|
||||
int chase_symlinks_at(
|
||||
int chaseat(
|
||||
int dir_fd,
|
||||
const char *path,
|
||||
ChaseSymlinksFlags flags,
|
||||
ChaseFlags flags,
|
||||
char **ret_path,
|
||||
int *ret_fd) {
|
||||
|
||||
_cleanup_free_ char *buffer = NULL, *done = NULL;
|
||||
_cleanup_close_ int fd = -EBADF, root_fd = -EBADF;
|
||||
unsigned max_follow = CHASE_SYMLINKS_MAX; /* how many symlinks to follow before giving up and returning ELOOP */
|
||||
unsigned max_follow = CHASE_MAX; /* how many symlinks to follow before giving up and returning ELOOP */
|
||||
bool exists = true, append_trail_slash = false;
|
||||
struct stat previous_stat;
|
||||
const char *todo;
|
||||
@@ -107,7 +107,7 @@ int chase_symlinks_at(
|
||||
path = ".";
|
||||
|
||||
/* This function resolves symlinks of the path relative to the given directory file descriptor. If
|
||||
* CHASE_SYMLINKS_RESOLVE_IN_ROOT is specified and a directory file descriptor is provided, symlinks
|
||||
* CHASE_AT_RESOLVE_IN_ROOT is specified and a directory file descriptor is provided, symlinks
|
||||
* are resolved relative to the given directory file descriptor. Otherwise, they are resolved
|
||||
* relative to the root directory of the host.
|
||||
*
|
||||
@@ -471,10 +471,10 @@ chased_one:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int chase_symlinks(
|
||||
int chase(
|
||||
const char *path,
|
||||
const char *original_root,
|
||||
ChaseSymlinksFlags flags,
|
||||
ChaseFlags flags,
|
||||
char **ret_path,
|
||||
int *ret_fd) {
|
||||
|
||||
@@ -531,7 +531,7 @@ int chase_symlinks(
|
||||
flags |= CHASE_AT_RESOLVE_IN_ROOT;
|
||||
flags &= ~CHASE_PREFIX_ROOT;
|
||||
|
||||
r = chase_symlinks_at(fd, path, flags, ret_path ? &p : NULL, ret_fd ? &pfd : NULL);
|
||||
r = chaseat(fd, path, flags, ret_path ? &p : NULL, ret_fd ? &pfd : NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -561,10 +561,10 @@ int chase_symlinks(
|
||||
return r;
|
||||
}
|
||||
|
||||
int chase_symlinks_and_open(
|
||||
int chase_and_open(
|
||||
const char *path,
|
||||
const char *root,
|
||||
ChaseSymlinksFlags chase_flags,
|
||||
ChaseFlags chase_flags,
|
||||
int open_flags,
|
||||
char **ret_path) {
|
||||
|
||||
@@ -583,7 +583,7 @@ int chase_symlinks_and_open(
|
||||
open_flags | (FLAGS_SET(chase_flags, CHASE_NOFOLLOW) ? O_NOFOLLOW : 0),
|
||||
mode));
|
||||
|
||||
r = chase_symlinks(path, root, CHASE_PARENT|chase_flags, &p, &path_fd);
|
||||
r = chase(path, root, CHASE_PARENT|chase_flags, &p, &path_fd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
assert(path_fd >= 0);
|
||||
@@ -609,10 +609,10 @@ int chase_symlinks_and_open(
|
||||
return r;
|
||||
}
|
||||
|
||||
int chase_symlinks_and_opendir(
|
||||
int chase_and_opendir(
|
||||
const char *path,
|
||||
const char *root,
|
||||
ChaseSymlinksFlags chase_flags,
|
||||
ChaseFlags chase_flags,
|
||||
char **ret_path,
|
||||
DIR **ret_dir) {
|
||||
|
||||
@@ -635,7 +635,7 @@ int chase_symlinks_and_opendir(
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = chase_symlinks(path, root, chase_flags, ret_path ? &p : NULL, &path_fd);
|
||||
r = chase(path, root, chase_flags, ret_path ? &p : NULL, &path_fd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
assert(path_fd >= 0);
|
||||
@@ -651,10 +651,10 @@ int chase_symlinks_and_opendir(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int chase_symlinks_and_stat(
|
||||
int chase_and_stat(
|
||||
const char *path,
|
||||
const char *root,
|
||||
ChaseSymlinksFlags chase_flags,
|
||||
ChaseFlags chase_flags,
|
||||
char **ret_path,
|
||||
struct stat *ret_stat) {
|
||||
|
||||
@@ -672,7 +672,7 @@ int chase_symlinks_and_stat(
|
||||
return RET_NERRNO(fstatat(AT_FDCWD, path, ret_stat,
|
||||
FLAGS_SET(chase_flags, CHASE_NOFOLLOW) ? AT_SYMLINK_NOFOLLOW : 0));
|
||||
|
||||
r = chase_symlinks(path, root, chase_flags, ret_path ? &p : NULL, &path_fd);
|
||||
r = chase(path, root, chase_flags, ret_path ? &p : NULL, &path_fd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
assert(path_fd >= 0);
|
||||
@@ -686,10 +686,10 @@ int chase_symlinks_and_stat(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int chase_symlinks_and_access(
|
||||
int chase_and_access(
|
||||
const char *path,
|
||||
const char *root,
|
||||
ChaseSymlinksFlags chase_flags,
|
||||
ChaseFlags chase_flags,
|
||||
int access_mode,
|
||||
char **ret_path) {
|
||||
|
||||
@@ -706,7 +706,7 @@ int chase_symlinks_and_access(
|
||||
return RET_NERRNO(faccessat(AT_FDCWD, path, access_mode,
|
||||
FLAGS_SET(chase_flags, CHASE_NOFOLLOW) ? AT_SYMLINK_NOFOLLOW : 0));
|
||||
|
||||
r = chase_symlinks(path, root, chase_flags, ret_path ? &p : NULL, &path_fd);
|
||||
r = chase(path, root, chase_flags, ret_path ? &p : NULL, &path_fd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
assert(path_fd >= 0);
|
||||
@@ -721,10 +721,10 @@ int chase_symlinks_and_access(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int chase_symlinks_and_fopen_unlocked(
|
||||
int chase_and_fopen_unlocked(
|
||||
const char *path,
|
||||
const char *root,
|
||||
ChaseSymlinksFlags chase_flags,
|
||||
ChaseFlags chase_flags,
|
||||
const char *open_flags,
|
||||
char **ret_path,
|
||||
FILE **ret_file) {
|
||||
@@ -742,7 +742,7 @@ int chase_symlinks_and_fopen_unlocked(
|
||||
if (mode_flags < 0)
|
||||
return mode_flags;
|
||||
|
||||
fd = chase_symlinks_and_open(path, root, chase_flags, mode_flags, ret_path ? &final_path : NULL);
|
||||
fd = chase_and_open(path, root, chase_flags, mode_flags, ret_path ? &final_path : NULL);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
@@ -756,10 +756,10 @@ int chase_symlinks_and_fopen_unlocked(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int chase_symlinks_and_unlink(
|
||||
int chase_and_unlink(
|
||||
const char *path,
|
||||
const char *root,
|
||||
ChaseSymlinksFlags chase_flags,
|
||||
ChaseFlags chase_flags,
|
||||
int unlink_flags,
|
||||
char **ret_path) {
|
||||
|
||||
@@ -770,7 +770,7 @@ int chase_symlinks_and_unlink(
|
||||
assert(path);
|
||||
assert(!(chase_flags & (CHASE_NONEXISTENT|CHASE_STEP|CHASE_PARENT)));
|
||||
|
||||
fd = chase_symlinks_and_open(path, root, chase_flags|CHASE_PARENT|CHASE_NOFOLLOW, O_PATH|O_DIRECTORY|O_CLOEXEC, &p);
|
||||
fd = chase_and_open(path, root, chase_flags|CHASE_PARENT|CHASE_NOFOLLOW, O_PATH|O_DIRECTORY|O_CLOEXEC, &p);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
@@ -787,10 +787,10 @@ int chase_symlinks_and_unlink(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int chase_symlinks_at_and_open(
|
||||
int chase_and_openat(
|
||||
int dir_fd,
|
||||
const char *path,
|
||||
ChaseSymlinksFlags chase_flags,
|
||||
ChaseFlags chase_flags,
|
||||
int open_flags,
|
||||
char **ret_path) {
|
||||
|
||||
@@ -808,7 +808,7 @@ int chase_symlinks_at_and_open(
|
||||
open_flags | (FLAGS_SET(chase_flags, CHASE_NOFOLLOW) ? O_NOFOLLOW : 0),
|
||||
mode));
|
||||
|
||||
r = chase_symlinks_at(dir_fd, path, chase_flags|CHASE_PARENT, &p, &path_fd);
|
||||
r = chaseat(dir_fd, path, chase_flags|CHASE_PARENT, &p, &path_fd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -829,10 +829,10 @@ int chase_symlinks_at_and_open(
|
||||
return r;
|
||||
}
|
||||
|
||||
int chase_symlinks_at_and_opendir(
|
||||
int chase_and_opendirat(
|
||||
int dir_fd,
|
||||
const char *path,
|
||||
ChaseSymlinksFlags chase_flags,
|
||||
ChaseFlags chase_flags,
|
||||
char **ret_path,
|
||||
DIR **ret_dir) {
|
||||
|
||||
@@ -855,7 +855,7 @@ int chase_symlinks_at_and_opendir(
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = chase_symlinks_at(dir_fd, path, chase_flags, ret_path ? &p : NULL, &path_fd);
|
||||
r = chaseat(dir_fd, path, chase_flags, ret_path ? &p : NULL, &path_fd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
assert(path_fd >= 0);
|
||||
@@ -871,10 +871,10 @@ int chase_symlinks_at_and_opendir(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int chase_symlinks_at_and_stat(
|
||||
int chase_and_statat(
|
||||
int dir_fd,
|
||||
const char *path,
|
||||
ChaseSymlinksFlags chase_flags,
|
||||
ChaseFlags chase_flags,
|
||||
char **ret_path,
|
||||
struct stat *ret_stat) {
|
||||
|
||||
@@ -892,7 +892,7 @@ int chase_symlinks_at_and_stat(
|
||||
return RET_NERRNO(fstatat(AT_FDCWD, path, ret_stat,
|
||||
FLAGS_SET(chase_flags, CHASE_NOFOLLOW) ? AT_SYMLINK_NOFOLLOW : 0));
|
||||
|
||||
r = chase_symlinks_at(dir_fd, path, chase_flags, ret_path ? &p : NULL, &path_fd);
|
||||
r = chaseat(dir_fd, path, chase_flags, ret_path ? &p : NULL, &path_fd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
assert(path_fd >= 0);
|
||||
@@ -906,10 +906,10 @@ int chase_symlinks_at_and_stat(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int chase_symlinks_at_and_access(
|
||||
int chase_and_accessat(
|
||||
int dir_fd,
|
||||
const char *path,
|
||||
ChaseSymlinksFlags chase_flags,
|
||||
ChaseFlags chase_flags,
|
||||
int access_mode,
|
||||
char **ret_path) {
|
||||
|
||||
@@ -926,7 +926,7 @@ int chase_symlinks_at_and_access(
|
||||
return RET_NERRNO(faccessat(AT_FDCWD, path, access_mode,
|
||||
FLAGS_SET(chase_flags, CHASE_NOFOLLOW) ? AT_SYMLINK_NOFOLLOW : 0));
|
||||
|
||||
r = chase_symlinks_at(dir_fd, path, chase_flags, ret_path ? &p : NULL, &path_fd);
|
||||
r = chaseat(dir_fd, path, chase_flags, ret_path ? &p : NULL, &path_fd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
assert(path_fd >= 0);
|
||||
@@ -941,10 +941,10 @@ int chase_symlinks_at_and_access(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int chase_symlinks_at_and_fopen_unlocked(
|
||||
int chase_and_fopenat_unlocked(
|
||||
int dir_fd,
|
||||
const char *path,
|
||||
ChaseSymlinksFlags chase_flags,
|
||||
ChaseFlags chase_flags,
|
||||
const char *open_flags,
|
||||
char **ret_path,
|
||||
FILE **ret_file) {
|
||||
@@ -962,7 +962,7 @@ int chase_symlinks_at_and_fopen_unlocked(
|
||||
if (mode_flags < 0)
|
||||
return mode_flags;
|
||||
|
||||
fd = chase_symlinks_at_and_open(dir_fd, path, chase_flags, mode_flags, ret_path ? &final_path : NULL);
|
||||
fd = chase_and_openat(dir_fd, path, chase_flags, mode_flags, ret_path ? &final_path : NULL);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
@@ -976,10 +976,10 @@ int chase_symlinks_at_and_fopen_unlocked(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int chase_symlinks_at_and_unlink(
|
||||
int chase_and_unlinkat(
|
||||
int dir_fd,
|
||||
const char *path,
|
||||
ChaseSymlinksFlags chase_flags,
|
||||
ChaseFlags chase_flags,
|
||||
int unlink_flags,
|
||||
char **ret_path) {
|
||||
|
||||
@@ -990,7 +990,7 @@ int chase_symlinks_at_and_unlink(
|
||||
assert(path);
|
||||
assert(!(chase_flags & (CHASE_NONEXISTENT|CHASE_STEP|CHASE_PARENT)));
|
||||
|
||||
fd = chase_symlinks_at_and_open(dir_fd, path, chase_flags|CHASE_PARENT|CHASE_NOFOLLOW, O_PATH|O_DIRECTORY|O_CLOEXEC, &p);
|
||||
fd = chase_and_openat(dir_fd, path, chase_flags|CHASE_PARENT|CHASE_NOFOLLOW, O_PATH|O_DIRECTORY|O_CLOEXEC, &p);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "stat-util.h"
|
||||
|
||||
typedef enum ChaseSymlinksFlags {
|
||||
typedef enum ChaseFlags {
|
||||
CHASE_PREFIX_ROOT = 1 << 0, /* The specified path will be prefixed by the specified root before beginning the iteration */
|
||||
CHASE_NONEXISTENT = 1 << 1, /* It's OK if the path doesn't actually exist. */
|
||||
CHASE_NO_AUTOFS = 1 << 2, /* Return -EREMOTE if autofs mount point found */
|
||||
@@ -25,27 +25,27 @@ typedef enum ChaseSymlinksFlags {
|
||||
* file descriptor will point to the parent directory. */
|
||||
CHASE_MKDIR_0755 = 1 << 11, /* Create any missing parent directories in the given path. */
|
||||
CHASE_EXTRACT_FILENAME = 1 << 12, /* Only return the last component of the resolved path */
|
||||
} ChaseSymlinksFlags;
|
||||
} ChaseFlags;
|
||||
|
||||
bool unsafe_transition(const struct stat *a, const struct stat *b);
|
||||
|
||||
/* How many iterations to execute before returning -ELOOP */
|
||||
#define CHASE_SYMLINKS_MAX 32
|
||||
#define CHASE_MAX 32
|
||||
|
||||
int chase_symlinks(const char *path_with_prefix, const char *root, ChaseSymlinksFlags chase_flags, char **ret_path, int *ret_fd);
|
||||
int chase(const char *path_with_prefix, const char *root, ChaseFlags chase_flags, char **ret_path, int *ret_fd);
|
||||
|
||||
int chase_symlinks_and_open(const char *path, const char *root, ChaseSymlinksFlags chase_flags, int open_flags, char **ret_path);
|
||||
int chase_symlinks_and_opendir(const char *path, const char *root, ChaseSymlinksFlags chase_flags, char **ret_path, DIR **ret_dir);
|
||||
int chase_symlinks_and_stat(const char *path, const char *root, ChaseSymlinksFlags chase_flags, char **ret_path, struct stat *ret_stat);
|
||||
int chase_symlinks_and_access(const char *path, const char *root, ChaseSymlinksFlags chase_flags, int access_mode, char **ret_path);
|
||||
int chase_symlinks_and_fopen_unlocked(const char *path, const char *root, ChaseSymlinksFlags chase_flags, const char *open_flags, char **ret_path, FILE **ret_file);
|
||||
int chase_symlinks_and_unlink(const char *path, const char *root, ChaseSymlinksFlags chase_flags, int unlink_flags, char **ret_path);
|
||||
int chase_and_open(const char *path, const char *root, ChaseFlags chase_flags, int open_flags, char **ret_path);
|
||||
int chase_and_opendir(const char *path, const char *root, ChaseFlags chase_flags, char **ret_path, DIR **ret_dir);
|
||||
int chase_and_stat(const char *path, const char *root, ChaseFlags chase_flags, char **ret_path, struct stat *ret_stat);
|
||||
int chase_and_access(const char *path, const char *root, ChaseFlags chase_flags, int access_mode, char **ret_path);
|
||||
int chase_and_fopen_unlocked(const char *path, const char *root, ChaseFlags chase_flags, const char *open_flags, char **ret_path, FILE **ret_file);
|
||||
int chase_and_unlink(const char *path, const char *root, ChaseFlags chase_flags, int unlink_flags, char **ret_path);
|
||||
|
||||
int chase_symlinks_at(int dir_fd, const char *path, ChaseSymlinksFlags flags, char **ret_path, int *ret_fd);
|
||||
int chaseat(int dir_fd, const char *path, ChaseFlags flags, char **ret_path, int *ret_fd);
|
||||
|
||||
int chase_symlinks_at_and_open(int dir_fd, const char *path, ChaseSymlinksFlags chase_flags, int open_flags, char **ret_path);
|
||||
int chase_symlinks_at_and_opendir(int dir_fd, const char *path, ChaseSymlinksFlags chase_flags, char **ret_path, DIR **ret_dir);
|
||||
int chase_symlinks_at_and_stat(int dir_fd, const char *path, ChaseSymlinksFlags chase_flags, char **ret_path, struct stat *ret_stat);
|
||||
int chase_symlinks_at_and_access(int dir_fd, const char *path, ChaseSymlinksFlags chase_flags, int access_mode, char **ret_path);
|
||||
int chase_symlinks_at_and_fopen_unlocked(int dir_fd, const char *path, ChaseSymlinksFlags chase_flags, const char *open_flags, char **ret_path, FILE **ret_file);
|
||||
int chase_symlinks_at_and_unlink(int dir_fd, const char *path, ChaseSymlinksFlags chase_flags, int unlink_flags, char **ret_path);
|
||||
int chase_and_openat(int dir_fd, const char *path, ChaseFlags chase_flags, int open_flags, char **ret_path);
|
||||
int chase_and_opendirat(int dir_fd, const char *path, ChaseFlags chase_flags, char **ret_path, DIR **ret_dir);
|
||||
int chase_and_statat(int dir_fd, const char *path, ChaseFlags chase_flags, char **ret_path, struct stat *ret_stat);
|
||||
int chase_and_accessat(int dir_fd, const char *path, ChaseFlags chase_flags, int access_mode, char **ret_path);
|
||||
int chase_and_fopenat_unlocked(int dir_fd, const char *path, ChaseFlags chase_flags, const char *open_flags, char **ret_path, FILE **ret_file);
|
||||
int chase_and_unlinkat(int dir_fd, const char *path, ChaseFlags chase_flags, int unlink_flags, char **ret_path);
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "chase-symlinks.h"
|
||||
#include "chase.h"
|
||||
#include "conf-files.h"
|
||||
#include "constants.h"
|
||||
#include "dirent-util.h"
|
||||
@@ -38,7 +38,7 @@ static int files_add(
|
||||
assert(masked);
|
||||
assert(path);
|
||||
|
||||
r = chase_symlinks_and_opendir(path, root, CHASE_PREFIX_ROOT, &dirpath, &dir);
|
||||
r = chase_and_opendir(path, root, CHASE_PREFIX_ROOT, &dirpath, &dir);
|
||||
if (r == -ENOENT)
|
||||
return 0;
|
||||
if (r < 0)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "chase-symlinks.h"
|
||||
#include "chase.h"
|
||||
#include "devnum-util.h"
|
||||
#include "parse-util.h"
|
||||
#include "path-util.h"
|
||||
@@ -92,7 +92,7 @@ int device_path_make_canonical(mode_t mode, dev_t devnum, char **ret) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return chase_symlinks(p, NULL, 0, ret, NULL);
|
||||
return chase(p, NULL, 0, ret, NULL);
|
||||
}
|
||||
|
||||
int device_path_parse_major_minor(const char *path, mode_t *ret_mode, dev_t *ret_devnum) {
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "chase-symlinks.h"
|
||||
#include "chase.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "fs-util.h"
|
||||
|
||||
@@ -14,7 +14,7 @@ basic_sources = files(
|
||||
'cap-list.c',
|
||||
'capability-util.c',
|
||||
'cgroup-util.c',
|
||||
'chase-symlinks.c',
|
||||
'chase.c',
|
||||
'chattr-util.c',
|
||||
'conf-files.c',
|
||||
'devnum-util.c',
|
||||
|
||||
+3
-3
@@ -5,7 +5,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "chase-symlinks.h"
|
||||
#include "chase.h"
|
||||
#include "fd-util.h"
|
||||
#include "format-util.h"
|
||||
#include "fs-util.h"
|
||||
@@ -47,7 +47,7 @@ int mkdirat_safe_internal(
|
||||
if ((flags & MKDIR_FOLLOW_SYMLINK) && S_ISLNK(st.st_mode)) {
|
||||
_cleanup_free_ char *p = NULL;
|
||||
|
||||
r = chase_symlinks_at(dir_fd, path, CHASE_NONEXISTENT, &p, NULL);
|
||||
r = chaseat(dir_fd, path, CHASE_NONEXISTENT, &p, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0)
|
||||
@@ -234,7 +234,7 @@ int mkdir_p_root(const char *root, const char *p, uid_t uid, gid_t gid, mode_t m
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
dfd = chase_symlinks_and_open(pp, root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC|O_DIRECTORY, NULL);
|
||||
dfd = chase_and_open(pp, root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC|O_DIRECTORY, NULL);
|
||||
if (dfd < 0)
|
||||
return dfd;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#endif
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "chase-symlinks.h"
|
||||
#include "chase.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "filesystems.h"
|
||||
@@ -341,7 +341,7 @@ int path_is_mount_point(const char *t, const char *root, int flags) {
|
||||
* /bin -> /usr/bin/ and /usr is a mount point, then the parent that we
|
||||
* look at needs to be /usr, not /. */
|
||||
if (flags & AT_SYMLINK_FOLLOW) {
|
||||
r = chase_symlinks(t, root, CHASE_TRAIL_SLASH, &canonical, NULL);
|
||||
r = chase(t, root, CHASE_TRAIL_SLASH, &canonical, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
+6
-12
@@ -1,7 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "chase-symlinks.h"
|
||||
#include "chase.h"
|
||||
#include "dirent-util.h"
|
||||
#include "env-file.h"
|
||||
#include "env-util.h"
|
||||
@@ -108,9 +108,7 @@ int open_extension_release(const char *root, const char *extension, bool relax_e
|
||||
"The extension name %s is invalid.", extension);
|
||||
|
||||
extension_full_path = strjoina("/usr/lib/extension-release.d/extension-release.", extension);
|
||||
r = chase_symlinks(extension_full_path, root, CHASE_PREFIX_ROOT,
|
||||
ret_path ? &q : NULL,
|
||||
ret_fd ? &fd : NULL);
|
||||
r = chase(extension_full_path, root, CHASE_PREFIX_ROOT, ret_path ? &q : NULL, ret_fd ? &fd : NULL);
|
||||
log_full_errno_zerook(LOG_DEBUG, MIN(r, 0), "Checking for %s: %m", extension_full_path);
|
||||
|
||||
/* Cannot find the expected extension-release file? The image filename might have been
|
||||
@@ -122,8 +120,8 @@ int open_extension_release(const char *root, const char *extension, bool relax_e
|
||||
_cleanup_free_ char *extension_release_dir_path = NULL;
|
||||
_cleanup_closedir_ DIR *extension_release_dir = NULL;
|
||||
|
||||
r = chase_symlinks_and_opendir("/usr/lib/extension-release.d/", root, CHASE_PREFIX_ROOT,
|
||||
&extension_release_dir_path, &extension_release_dir);
|
||||
r = chase_and_opendir("/usr/lib/extension-release.d/", root, CHASE_PREFIX_ROOT,
|
||||
&extension_release_dir_path, &extension_release_dir);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Cannot open %s/usr/lib/extension-release.d/, ignoring: %m", root);
|
||||
|
||||
@@ -192,14 +190,10 @@ int open_extension_release(const char *root, const char *extension, bool relax_e
|
||||
} else {
|
||||
const char *var = secure_getenv("SYSTEMD_OS_RELEASE");
|
||||
if (var)
|
||||
r = chase_symlinks(var, root, 0,
|
||||
ret_path ? &q : NULL,
|
||||
ret_fd ? &fd : NULL);
|
||||
r = chase(var, root, 0, ret_path ? &q : NULL, ret_fd ? &fd : NULL);
|
||||
else
|
||||
FOREACH_STRING(path, "/etc/os-release", "/usr/lib/os-release") {
|
||||
r = chase_symlinks(path, root, CHASE_PREFIX_ROOT,
|
||||
ret_path ? &q : NULL,
|
||||
ret_fd ? &fd : NULL);
|
||||
r = chase(path, root, CHASE_PREFIX_ROOT, ret_path ? &q : NULL, ret_fd ? &fd : NULL);
|
||||
if (r != -ENOENT)
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "chase-symlinks.h"
|
||||
#include "chase.h"
|
||||
#include "extract-word.h"
|
||||
#include "fd-util.h"
|
||||
#include "fs-util.h"
|
||||
@@ -285,7 +285,7 @@ char **path_strv_resolve(char **l, const char *root) {
|
||||
} else
|
||||
t = *s;
|
||||
|
||||
r = chase_symlinks(t, root, 0, &u, NULL);
|
||||
r = chase(t, root, 0, &u, NULL);
|
||||
if (r == -ENOENT) {
|
||||
if (root) {
|
||||
u = TAKE_PTR(orig);
|
||||
@@ -621,16 +621,13 @@ static int find_executable_impl(const char *name, const char *root, char **ret_f
|
||||
|
||||
assert(name);
|
||||
|
||||
/* Function chase_symlinks() is invoked only when root is not NULL, as using it regardless of
|
||||
/* Function chase() is invoked only when root is not NULL, as using it regardless of
|
||||
* root value would alter the behavior of existing callers for example: /bin/sleep would become
|
||||
* /usr/bin/sleep when find_executables is called. Hence, this function should be invoked when
|
||||
* needed to avoid unforeseen regression or other complicated changes. */
|
||||
if (root) {
|
||||
r = chase_symlinks(name,
|
||||
root,
|
||||
CHASE_PREFIX_ROOT,
|
||||
&path_name,
|
||||
/* ret_fd= */ NULL); /* prefix root to name in case full paths are not specified */
|
||||
/* prefix root to name in case full paths are not specified */
|
||||
r = chase(name, root, CHASE_PREFIX_ROOT, &path_name, /* ret_fd= */ NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "chase-symlinks.h"
|
||||
#include "chase.h"
|
||||
#include "dirent-util.h"
|
||||
#include "errno-util.h"
|
||||
#include "fd-util.h"
|
||||
@@ -145,7 +145,7 @@ int null_or_empty_path_with_root(const char *fn, const char *root) {
|
||||
if (path_equal_ptr(path_startswith(fn, root ?: "/"), "dev/null"))
|
||||
return true;
|
||||
|
||||
r = chase_symlinks_and_stat(fn, root, CHASE_PREFIX_ROOT, NULL, &st);
|
||||
r = chase_and_stat(fn, root, CHASE_PREFIX_ROOT, NULL, &st);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "sd-id128.h"
|
||||
|
||||
#include "chase-symlinks.h"
|
||||
#include "chase.h"
|
||||
#include "dirent-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "fs-util.h"
|
||||
@@ -322,7 +322,7 @@ int unit_file_resolve_symlink(
|
||||
}
|
||||
|
||||
/* Get rid of "." and ".." components in target path */
|
||||
r = chase_symlinks(target, root_dir, CHASE_NOFOLLOW | CHASE_NONEXISTENT, &simplified, NULL);
|
||||
r = chase(target, root_dir, CHASE_NOFOLLOW | CHASE_NONEXISTENT, &simplified, NULL);
|
||||
if (r < 0)
|
||||
return log_warning_errno(r, "Failed to resolve symlink %s/%s pointing to %s: %m",
|
||||
dir, filename, target);
|
||||
@@ -432,7 +432,7 @@ int unit_file_build_name_map(
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
r = chase_symlinks(*dir, NULL, 0, &resolved_dir, NULL);
|
||||
r = chase(*dir, NULL, 0, &resolved_dir, NULL);
|
||||
if (r < 0) {
|
||||
if (r != -ENOENT)
|
||||
log_warning_errno(r, "Failed to resolve symlink %s, ignoring: %m", *dir);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "sd-messages.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "chase-symlinks.h"
|
||||
#include "chase.h"
|
||||
#include "errno-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
@@ -161,7 +161,7 @@ const char* default_root_shell(const char *root) {
|
||||
* will be /bin/bash. Fall back to /bin/sh if DEFAULT_USER_SHELL is not found,
|
||||
* or any access errors. */
|
||||
|
||||
int r = chase_symlinks(DEFAULT_USER_SHELL, root, CHASE_PREFIX_ROOT, NULL, NULL);
|
||||
int r = chase(DEFAULT_USER_SHELL, root, CHASE_PREFIX_ROOT, NULL, NULL);
|
||||
if (r < 0 && r != -ENOENT)
|
||||
log_debug_errno(r, "Failed to look up shell '%s%s%s': %m",
|
||||
strempty(root), root ? "/" : "", DEFAULT_USER_SHELL);
|
||||
|
||||
Reference in New Issue
Block a user