richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
923a60
From 8d166597076d87aae9d5f98144103386c79d6446 Mon Sep 17 00:00:00 2001
923a60
From: Jan Synacek <jsynacek@redhat.com>
923a60
Date: Fri, 31 Mar 2017 09:47:46 +0200
923a60
Subject: [PATCH] namespace: don't fail on masked mounts
923a60
923a60
Before this patch, a service file with ReadWriteDirectories=/file...
923a60
could fail if the file exists but is not a mountpoint, despite being
923a60
listed in /proc/self/mountinfo. It could happen with masked mounts.
923a60
923a60
(cherry picked from commit 98df8089bea1b2407c46495b6c2eb76dda46c658)
923a60
923a60
Resolves: #1433687
923a60
---
923a60
 src/shared/util.c | 23 +++++++++++------------
923a60
 1 file changed, 11 insertions(+), 12 deletions(-)
923a60
923a60
diff --git a/src/shared/util.c b/src/shared/util.c
923a60
index 1070e32c4a..3e13cc1fdb 100644
923a60
--- a/src/shared/util.c
923a60
+++ b/src/shared/util.c
923a60
@@ -7332,22 +7332,21 @@ int bind_remount_recursive(const char *prefix, bool ro) {
923a60
                         if (r < 0)
923a60
                                 return r;
923a60
 
923a60
-                        /* Try to reuse the original flag set, but
923a60
-                         * don't care for errors, in case of
923a60
-                         * obstructed mounts */
923a60
+                        /* Deal with mount points that are obstructed by a
923a60
+                         * later mount */
923a60
+                        r = path_is_mount_point(x, 0);
923a60
+                        if (r == -ENOENT || r == 0)
923a60
+                                continue;
923a60
+                        if (r < 0)
923a60
+                                return r;
923a60
+
923a60
+                        /* Try to reuse the original flag set */
923a60
                         orig_flags = 0;
923a60
                         (void) get_mount_flags(x, &orig_flags);
923a60
                         orig_flags &= ~MS_RDONLY;
923a60
 
923a60
-                        if (mount(NULL, x, NULL, orig_flags|MS_BIND|MS_REMOUNT|(ro ? MS_RDONLY : 0), NULL) < 0) {
923a60
-
923a60
-                                /* Deal with mount points that are
923a60
-                                 * obstructed by a later mount */
923a60
-
923a60
-                                if (errno != ENOENT)
923a60
-                                        return -errno;
923a60
-                        }
923a60
-
923a60
+                        if (mount(NULL, x, NULL, orig_flags|MS_BIND|MS_REMOUNT|(ro ? MS_RDONLY : 0), NULL) < 0)
923a60
+                                return -errno;
923a60
                 }
923a60
         }
923a60
 }