summaryrefslogtreecommitdiff
path: root/src/basic/chase.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-04-17 05:04:27 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-04-19 03:28:34 +0900
commitc0552b359c5b5dc0c130b831ce0067af99149f27 (patch)
tree2b1e0fdbdba4f22a769af2fb53a824a020a7a435 /src/basic/chase.c
parentd81fc152547769854835f471c97db8e7d066373e (diff)
downloadsystemd-c0552b359c5b5dc0c130b831ce0067af99149f27.tar.gz
chase: make chaseat() provides absolute path also when dir_fd points to the root directory
Usually, we pass the file descriptor of the root directory to chaseat() when `--root=` is not specified. Previously, even in such case, the result was relative, and we need to prefix the path with "/" when we want to pass the path to other functions that do not support dir_fd, or log or show the path. That's inconvenient.
Diffstat (limited to 'src/basic/chase.c')
-rw-r--r--src/basic/chase.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/basic/chase.c b/src/basic/chase.c
index eb4bda07a6..a6a37978e8 100644
--- a/src/basic/chase.c
+++ b/src/basic/chase.c
@@ -190,8 +190,9 @@ int chaseat(int dir_fd, const char *path, ChaseFlags flags, char **ret_path, int
return -ENOMEM;
/* If we receive an absolute path together with AT_FDCWD, we need to return an absolute path, because
- * a relative path would be interpreted relative to the current working directory. */
- bool need_absolute = dir_fd == AT_FDCWD && path_is_absolute(path);
+ * a relative path would be interpreted relative to the current working directory. Also, let's make
+ * the result absolute when the file descriptor of the root directory is specified. */
+ bool need_absolute = (dir_fd == AT_FDCWD && path_is_absolute(path)) || dir_fd_is_root(dir_fd) > 0;
if (need_absolute) {
done = strdup("/");
if (!done)