]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
stat-util: specify O_DIRECTORY when reopening dir in dir_is_empty_at()
authorLennart Poettering <lennart@poettering.net>
Thu, 21 Oct 2021 16:07:06 +0000 (18:07 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 25 Oct 2021 19:39:05 +0000 (21:39 +0200)
That way we can fail earlier if the specified fd is not actually a
directory.

(Also, it's not exactly according to standards to open things without
either O_RDONLY/O_RDWR...)

src/basic/stat-util.c

index 0004255bdbe59a43f8d93233e721232d3c05e846..56789b4878555d62beed4ad7b3b9884f0015af94 100644 (file)
@@ -83,7 +83,7 @@ int dir_is_empty_at(int dir_fd, const char *path) {
         } else {
                 /* Note that DUPing is not enough, as the internal pointer
                  * would still be shared and moved by FOREACH_DIRENT. */
-                fd = fd_reopen(dir_fd, O_CLOEXEC);
+                fd = fd_reopen(dir_fd, O_RDONLY|O_DIRECTORY|O_CLOEXEC);
                 if (fd < 0)
                         return fd;
         }