Blob Blame History Raw
From 47c0c5108b39d01283ba040c41d556b160d45a55 Mon Sep 17 00:00:00 2001
From: Michal Sekletar <msekleta@redhat.com>
Date: Wed, 30 Nov 2022 18:01:01 +0100
Subject: [PATCH] basic: add fallback in chase_symlinks_and_opendir() for cases
 when /proc is not mounted

rhel-only

Related: #2138081
---
 src/basic/chase-symlinks.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/basic/chase-symlinks.c b/src/basic/chase-symlinks.c
index afab54f067..c09aab389e 100644
--- a/src/basic/chase-symlinks.c
+++ b/src/basic/chase-symlinks.c
@@ -466,14 +466,22 @@ int chase_symlinks_and_opendir(
                 return 0;
         }
 
-        r = chase_symlinks(path, root, chase_flags, ret_path ? &p : NULL, &path_fd);
+        r = chase_symlinks(path, root, chase_flags, &p, &path_fd);
         if (r < 0)
                 return r;
         assert(path_fd >= 0);
 
         d = opendir(FORMAT_PROC_FD_PATH(path_fd));
-        if (!d)
-                return -errno;
+        if (!d) {
+                /* Hmm, we have the fd already but we got ENOENT, most likely /proc is not mounted.
+                 * Let's try opendir() again on the full path. */
+                if (errno == ENOENT) {
+                        d = opendir(p);
+                        if (!d)
+                                return -errno;
+                } else
+                        return -errno;
+        }
 
         if (ret_path)
                 *ret_path = TAKE_PTR(p);