Merge pull request #25338 from DaanDeMeyer/at-fixes

Followups for #24813
This commit is contained in:
Yu Watanabe
2022-11-13 22:59:40 +09:00
committed by GitHub
7 changed files with 8 additions and 50 deletions
-2
View File
@@ -460,9 +460,7 @@ int chase_symlinks(
SYNTHETIC_ERRNO(ECHRNG),
"Specified path '%s' is outside of specified root directory '%s', refusing to resolve.",
absolute, root);
}
if (root) {
fd = open(root, O_CLOEXEC|O_DIRECTORY|O_PATH);
if (fd < 0)
return -errno;
+2
View File
@@ -197,6 +197,8 @@ int readlink_and_make_absolute(const char *p, char **r) {
int chmod_and_chown_at(int dir_fd, const char *path, mode_t mode, uid_t uid, gid_t gid) {
_cleanup_close_ int fd = -1;
assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
if (path) {
/* Let's acquire an O_PATH fd, as precaution to change mode/owner on the same file */
fd = openat(dir_fd, path, O_PATH|O_CLOEXEC|O_NOFOLLOW);
-27
View File
@@ -221,33 +221,6 @@ int path_make_relative_parent(const char *from_child, const char *to, char **ret
return path_make_relative(from, to, ret);
}
int path_make_relative_cwd(const char *p, char **ret) {
char *c;
int r;
assert(p);
assert(ret);
if (path_is_absolute(p)) {
_cleanup_free_ char *cwd = NULL;
r = safe_getcwd(&cwd);
if (r < 0)
return r;
r = path_make_relative(cwd, p, &c);
if (r < 0)
return r;
} else {
c = strdup(p);
if (!c)
return -ENOMEM;
}
*ret = TAKE_PTR(c);
return 0;
}
char* path_startswith_strv(const char *p, char **set) {
STRV_FOREACH(s, set) {
char *t;
-1
View File
@@ -62,7 +62,6 @@ int safe_getcwd(char **ret);
int path_make_absolute_cwd(const char *p, char **ret);
int path_make_relative(const char *from, const char *to, char **ret);
int path_make_relative_parent(const char *from_child, const char *to, char **ret);
int path_make_relative_cwd(const char *from, char **ret);
char *path_startswith_full(const char *path, const char *prefix, bool accept_dot_dot) _pure_;
static inline char* path_startswith(const char *path, const char *prefix) {
return path_startswith_full(path, prefix, true);
+2
View File
@@ -25,6 +25,8 @@ int fopen_temporary_at(int dir_fd, const char *path, FILE **ret_file, char **ret
_cleanup_close_ int fd = -1;
int r;
assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
if (path) {
r = tempfn_random(path, NULL, &t);
if (r < 0)