]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
stat-util: make sure dir_is_empty_at() does something useful in all cases
authorLennart Poettering <lennart@poettering.net>
Fri, 22 Oct 2021 22:31:33 +0000 (00:31 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 25 Oct 2021 19:51:37 +0000 (21:51 +0200)
src/basic/stat-util.c

index 900f06ad1c74acd3121ab1ee27cd540987c90ce9..77e728bcab537c588e418ccaef701bb2fc083aa3 100644 (file)
@@ -80,9 +80,15 @@ int dir_is_empty_at(int dir_fd, const char *path) {
         ssize_t n;
 
         if (path) {
+                assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
+
                 fd = openat(dir_fd, path, O_RDONLY|O_DIRECTORY|O_CLOEXEC);
                 if (fd < 0)
                         return -errno;
+        } else if (dir_fd == AT_FDCWD) {
+                fd = open(".", O_RDONLY|O_DIRECTORY|O_CLOEXEC);
+                if (fd < 0)
+                        return -errno;
         } else {
                 /* Note that DUPing is not enough, as the internal pointer would still be shared and moved
                  * getedents64(). */