From: Yu Watanabe Date: Tue, 20 Jan 2026 09:41:11 +0000 (+0900) Subject: stat-util: make proc_mounted() not update errno X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e6a25c2fc7556b97406367bd1c9516ea621e1c07;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c index 628d99ac5a6..6d1796c315b 100644 --- a/src/basic/stat-util.c +++ b/src/basic/stat-util.c @@ -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 */