]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
stat-util: don't try to open path on path_is_temporary_fs()
authorLennart Poettering <lennart@poettering.net>
Wed, 6 Jan 2021 17:05:56 +0000 (18:05 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 6 Jan 2021 23:26:08 +0000 (23:26 +0000)
I mean, the old code at least used O_PATH, but still, we shouldn't
allocate/close an fd if we don't have to.

src/basic/stat-util.c

index 41c92e69de8eef67101507999b164ab8447b239e..f999681636da506c6183af589787fdd257ad779c 100644 (file)
@@ -226,13 +226,12 @@ int fd_is_network_fs(int fd) {
 }
 
 int path_is_temporary_fs(const char *path) {
-        _cleanup_close_ int fd = -1;
+        struct statfs s;
 
-        fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_PATH);
-        if (fd < 0)
+        if (statfs(path, &s) < 0)
                 return -errno;
 
-        return fd_is_temporary_fs(fd);
+        return is_temporary_fs(&s);
 }
 
 int stat_verify_regular(const struct stat *st) {