daandemeyer / rpms / systemd

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