summaryrefslogtreecommitdiff
path: root/src/tmpfiles
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-09-15 19:35:04 +0100
committerLennart Poettering <lennart@poettering.net>2022-09-23 09:28:59 +0200
commit27f6aa0b7112024c1236957abd909071b06869a8 (patch)
tree1cb5d320dfcded2f2abf2e4c7fc66facfa4e09c7 /src/tmpfiles
parent9e430ce3d4335541ac54658625483d282d0a1998 (diff)
downloadsystemd-27f6aa0b7112024c1236957abd909071b06869a8.tar.gz
tmpfiles: rework empty_directory() to also use chase_symlinks()
Diffstat (limited to 'src/tmpfiles')
-rw-r--r--src/tmpfiles/tmpfiles.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 8442cce5bc..0031b6ee49 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -1793,26 +1793,33 @@ static int create_subvolume(Item *i, const char *path) {
}
static int empty_directory(Item *i, const char *path, CreationMode creation) {
+ _cleanup_close_ int fd = -1;
+ struct stat st;
int r;
assert(i);
assert(i->type == EMPTY_DIRECTORY);
- r = is_dir(path, false);
+ r = chase_symlinks(path, arg_root, CHASE_SAFE|CHASE_WARN, NULL, &fd);
+ if (r == -ENOLINK) /* Unsafe symlink: already covered by CHASE_WARN */
+ return fd;
if (r == -ENOENT) {
- /* Option "e" operates only on existing objects. Do not
- * print errors about non-existent files or directories */
- log_debug("Skipping missing directory: %s", path);
+ /* Option "e" operates only on existing objects. Do not print errors about non-existent files
+ * or directories */
+ log_debug_errno(r, "Skipping missing directory: %s", path);
return 0;
}
if (r < 0)
- return log_error_errno(r, "is_dir() failed on path %s: %m", path);
- if (r == 0) {
- log_warning("\"%s\" already exists and is not a directory.", path);
+ return log_error_errno(r, "Failed to open directory '%s': %m", path);
+
+ if (fstat(fd, &st) < 0)
+ return log_error_errno(errno, "Failed to fstat(%s): %m", path);
+ if (!S_ISDIR(st.st_mode)) {
+ log_warning("'%s' already exists and is not a directory.", path);
return 0;
}
- return path_set_perms(i, path, creation);
+ return fd_set_perms(i, fd, path, &st, creation);
}
static int create_device(Item *i, mode_t file_type) {