summaryrefslogtreecommitdiff
path: root/src/basic/stat-util.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-01-15 16:54:19 +0100
committerGitHub <noreply@github.com>2019-01-15 16:54:19 +0100
commit477fd8e886eeb32be87ac41c0c8a289209ba8615 (patch)
tree6f102217c74c08a14b23075b32724c4533e8edc5 /src/basic/stat-util.c
parentacd1220cffafbf93fbe88047311e34b3b44084b5 (diff)
parent55b25c43ff1224728aa51f90d599a6843dd27543 (diff)
downloadsystemd-477fd8e886eeb32be87ac41c0c8a289209ba8615.tar.gz
Merge pull request #11345 from kirbyfan64/tmpfiles-c-empty
tmpfiles: Make C still copy if the destination directory is empty
Diffstat (limited to 'src/basic/stat-util.c')
-rw-r--r--src/basic/stat-util.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c
index 0af869cf65..ea2bbc368b 100644
--- a/src/basic/stat-util.c
+++ b/src/basic/stat-util.c
@@ -67,13 +67,22 @@ int is_device_node(const char *path) {
return !!(S_ISBLK(info.st_mode) || S_ISCHR(info.st_mode));
}
-int dir_is_empty(const char *path) {
- _cleanup_closedir_ DIR *d;
+int dir_is_empty_at(int dir_fd, const char *path) {
+ _cleanup_close_ int fd = -1;
+ _cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
- d = opendir(path);
+ if (path)
+ fd = openat(dir_fd, path, O_RDONLY|O_DIRECTORY|O_CLOEXEC);
+ else
+ fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
+ if (fd < 0)
+ return -errno;
+
+ d = fdopendir(fd);
if (!d)
return -errno;
+ fd = -1;
FOREACH_DIRENT(de, d, return -errno)
return 0;