diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-04-17 17:09:54 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-04-18 20:38:59 +0200 |
commit | 60e761d8f3e14ebbadb26f2e2ca2c225f97660ef (patch) | |
tree | e3f14f1e8428ce6bbaa7732e703d07513754d238 /src/basic/chase.c | |
parent | fd-util: skip to check mount ID if kernel is too old and /proc is not mounted (diff) | |
download | systemd-60e761d8f3e14ebbadb26f2e2ca2c225f97660ef.tar.xz systemd-60e761d8f3e14ebbadb26f2e2ca2c225f97660ef.zip |
chase: replace path_prefix_root_cwd() with chaseat_prefix_root()
The function path_prefix_root_cwd() was introduced for prefixing the
result from chaseat() with root, but
- it is named slightly generic,
- the logic is different from what chase() does.
This makes the name more explanative and specific for the result of the
chaseat(), and make the logic consistent with chase().
Fixes https://github.com/systemd/systemd/pull/27199#issuecomment-1511387731.
Follow-up for #27199.
Diffstat (limited to 'src/basic/chase.c')
-rw-r--r-- | src/basic/chase.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/basic/chase.c b/src/basic/chase.c index 96b59e7845..373252b645 100644 --- a/src/basic/chase.c +++ b/src/basic/chase.c @@ -583,6 +583,37 @@ int chase(const char *path, const char *root, ChaseFlags flags, char **ret_path, return r; } +int chaseat_prefix_root(const char *path, const char *root, char **ret) { + char *q; + int r; + + assert(path); + assert(ret); + + /* This is mostly for prefixing the result of chaseat(). */ + + if (!path_is_absolute(path)) { + _cleanup_free_ char *root_abs = NULL; + + /* If the dir_fd points to the root directory, chaseat() always returns an absolute path. */ + assert(!empty_or_root(root)); + + r = path_make_absolute_cwd(root, &root_abs); + if (r < 0) + return r; + + root = path_simplify(root_abs); + + q = path_join(root, path + (path[0] == '.' && IN_SET(path[1], '/', '\0'))); + } else + q = strdup(path); + if (!q) + return -ENOMEM; + + *ret = q; + return 0; +} + int chase_and_open(const char *path, const char *root, ChaseFlags chase_flags, int open_flags, char **ret_path) { _cleanup_close_ int path_fd = -EBADF; _cleanup_free_ char *p = NULL, *fname = NULL; |