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