diff options
author | Mike Yuan <me@yhndnzj.com> | 2024-05-20 13:28:23 +0200 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2024-05-21 18:50:44 +0200 |
commit | d19b3c5d99918ad03e10ffdd6b38c675013c9daf (patch) | |
tree | 1b9c067af91f299eada73abf237d6fb79e5c32c9 /src/basic/fs-util.c | |
parent | fs-util: use RET_GATHER at one more place (diff) | |
download | systemd-d19b3c5d99918ad03e10ffdd6b38c675013c9daf.tar.xz systemd-d19b3c5d99918ad03e10ffdd6b38c675013c9daf.zip |
fd-util: introduce proc_fd_enoent_errno helper
Currently, if proc_mounted() != 0, some functions
propagate -ENOENT while others return -EBADF.
Let's make things consistent, by introducing
a static inline helper responsible for finding out
the appropriate errno.
Diffstat (limited to 'src/basic/fs-util.c')
-rw-r--r-- | src/basic/fs-util.c | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 6bb4587f81..13995cf7a7 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -313,10 +313,7 @@ int fchmod_opath(int fd, mode_t m) { if (errno != ENOENT) return -errno; - if (proc_mounted() == 0) - return -ENOSYS; /* if we have no /proc/, the concept is not implementable */ - - return -ENOENT; + return proc_fd_enoent_errno(); } return 0; @@ -339,10 +336,7 @@ int futimens_opath(int fd, const struct timespec ts[2]) { if (errno != ENOENT) return -errno; - if (proc_mounted() == 0) - return -ENOSYS; - - return -ENOENT; + return proc_fd_enoent_errno(); } return 0; @@ -685,14 +679,7 @@ int access_fd(int fd, int mode) { if (errno != ENOENT) return -errno; - /* ENOENT can mean two things: that the fd does not exist or that /proc is not mounted. Let's - * make things debuggable and distinguish the two. */ - - if (proc_mounted() == 0) - return -ENOSYS; /* /proc is not available or not set up properly, we're most likely in some chroot - * environment. */ - - return -EBADF; /* The directory exists, hence it's the fd that doesn't. */ + return proc_fd_enoent_errno(); } return 0; |