ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
ac3a84
From 47c0c5108b39d01283ba040c41d556b160d45a55 Mon Sep 17 00:00:00 2001
ac3a84
From: Michal Sekletar <msekleta@redhat.com>
ac3a84
Date: Wed, 30 Nov 2022 18:01:01 +0100
ac3a84
Subject: [PATCH] basic: add fallback in chase_symlinks_and_opendir() for cases
ac3a84
 when /proc is not mounted
ac3a84
ac3a84
rhel-only
ac3a84
ac3a84
Related: #2138081
ac3a84
---
ac3a84
 src/basic/chase-symlinks.c | 14 +++++++++++---
ac3a84
 1 file changed, 11 insertions(+), 3 deletions(-)
ac3a84
ac3a84
diff --git a/src/basic/chase-symlinks.c b/src/basic/chase-symlinks.c
ac3a84
index afab54f067..c09aab389e 100644
ac3a84
--- a/src/basic/chase-symlinks.c
ac3a84
+++ b/src/basic/chase-symlinks.c
ac3a84
@@ -466,14 +466,22 @@ int chase_symlinks_and_opendir(
ac3a84
                 return 0;
ac3a84
         }
ac3a84
 
ac3a84
-        r = chase_symlinks(path, root, chase_flags, ret_path ? &p : NULL, &path_fd);
ac3a84
+        r = chase_symlinks(path, root, chase_flags, &p, &path_fd);
ac3a84
         if (r < 0)
ac3a84
                 return r;
ac3a84
         assert(path_fd >= 0);
ac3a84
 
ac3a84
         d = opendir(FORMAT_PROC_FD_PATH(path_fd));
ac3a84
-        if (!d)
ac3a84
-                return -errno;
ac3a84
+        if (!d) {
ac3a84
+                /* Hmm, we have the fd already but we got ENOENT, most likely /proc is not mounted.
ac3a84
+                 * Let's try opendir() again on the full path. */
ac3a84
+                if (errno == ENOENT) {
ac3a84
+                        d = opendir(p);
ac3a84
+                        if (!d)
ac3a84
+                                return -errno;
ac3a84
+                } else
ac3a84
+                        return -errno;
ac3a84
+        }
ac3a84
 
ac3a84
         if (ret_path)
ac3a84
                 *ret_path = TAKE_PTR(p);