]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic: update fd_get_path() to use proc_mounted() helper
authorLennart Poettering <lennart@poettering.net>
Wed, 23 Sep 2020 16:16:34 +0000 (18:16 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 23 Sep 2020 16:20:38 +0000 (18:20 +0200)
We use it pretty much everywhere else, hence use it here too.

This also changes the error generated from EOPNOTSUPP to ENOSYS, to
match the other cases where we do such a check. One user checked for
EOPNOTSUPP which is updated to check for ENOSYS instead.

src/basic/fd-util.c
src/basic/fs-util.c

index 14b12b27061ac987901e7b06704341b6efd7f2eb..56700bc0576950bd4c17fa94c37a93fcc3312eab 100644 (file)
@@ -385,11 +385,9 @@ int fd_get_path(int fd, char **ret) {
                 /* 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 (access("/proc/self/fd/", F_OK) < 0)
-                        /* /proc is not available or not set up properly, we're most likely in some chroot
-                         * environment. */
-                        return errno == ENOENT ? -EOPNOTSUPP : -errno;
-
+                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. */
         }
 
index 7f8b8b22b3fa12eea3ce0d1a47b6b8e74a8b2243..477848f2a0aae5ca7bb6cd700ab302925d668721 100644 (file)
@@ -1441,9 +1441,9 @@ int fsync_directory_of_file(int fd) {
         if (r < 0) {
                 log_debug_errno(r, "Failed to query /proc/self/fd/%d%s: %m",
                                 fd,
-                                r == -EOPNOTSUPP ? ", ignoring" : "");
+                                r == -ENOSYS ? ", ignoring" : "");
 
-                if (r == -EOPNOTSUPP)
+                if (r == -ENOSYS)
                         /* If /proc is not available, we're most likely running in some
                          * chroot environment, and syncing the directory is not very
                          * important in that case. Let's just silently do nothing. */