stat-util: make proc_mounted() not update errno

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.
This commit is contained in:
Yu Watanabe
2026-01-20 22:37:04 +09:00
parent e41d7de091
commit e6a25c2fc7
+2
View 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 */