]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
stat-util: make proc_mounted() not update errno
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 20 Jan 2026 09:41:11 +0000 (18:41 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 20 Jan 2026 13:37:04 +0000 (22:37 +0900)
Typically, proc_mounted() is used in error handling. Hence, it is better
to make it not update the original errno.

Currently, there are two places that returns wrong error code:
- pidref_get_capability() in src/basic/capability-util.c
```c
        _cleanup_fclose_ FILE *f = fopen(path, "re");
        if (!f) {
                if (errno == ENOENT && proc_mounted() == 0)
                        return -ENOSYS;

                return -errno;
        }
```
- fdset_new_fill() in src/shared/fdset.c
```c
        d = opendir("/proc/self/fd");
        if (!d) {
                if (errno == ENOENT && proc_mounted() == 0)
                        return -ENOSYS;

                return -errno;
        }
```

Rather than fixing them, let's make proc_mounted() not update errno,
otherwise we may make a similar failure in a future.

src/basic/stat-util.c

index 628d99ac5a685985f437434b2bd3c5d38709e786..6d1796c315bb59e98b22f315d13b9b45ec24edf5 100644 (file)
@@ -471,6 +471,8 @@ int path_is_network_fs(const char *path) {
 }
 
 int proc_mounted(void) {
+        /* This is typically used in error path. So, it is better to not overwrite the original errno. */
+        PROTECT_ERRNO;
         int r;
 
         /* A quick check of procfs is properly mounted */