stat-util: specify O_DIRECTORY when reopening dir in dir_is_empty_at()

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...)
This commit is contained in:
Lennart Poettering
2021-10-25 21:39:05 +02:00
parent 6681eb021a
commit b9d0652263
+1 -1
View 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;
}