1ff636
From 602786c9171d189e859796fd61873835fe858a06 Mon Sep 17 00:00:00 2001
1ff636
From: Lennart Poettering <lennart@poettering.net>
1ff636
Date: Tue, 19 May 2015 17:19:27 +0200
1ff636
Subject: [PATCH] mount: properly check for mounts currently in
1ff636
 /proc/self/mountinfo
1ff636
1ff636
http://lists.freedesktop.org/archives/systemd-devel/2015-May/032059.html
1ff636
(cherry picked from commit 394763f63c1941cafd9d3bf81e8151a2206474a7)
1ff636
1ff636
Cherry-picked from: 394763f
1ff636
Resolves: #1222517
1ff636
---
1ff636
 src/core/mount.c | 33 +++++++++++++++++++--------------
1ff636
 1 file changed, 19 insertions(+), 14 deletions(-)
1ff636
1ff636
diff --git a/src/core/mount.c b/src/core/mount.c
1ff636
index fa63f24..1f1a41a 100644
1ff636
--- a/src/core/mount.c
1ff636
+++ b/src/core/mount.c
1ff636
@@ -1768,7 +1768,18 @@ static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents,
1ff636
 
1ff636
                 if (!mount->is_mounted) {
1ff636
 
1ff636
-                        /* A mount point is gone */
1ff636
+                        /* A mount point is not around right now. It
1ff636
+                         * might be gone, or might never have
1ff636
+                         * existed. */
1ff636
+
1ff636
+                        if (mount->from_proc_self_mountinfo &&
1ff636
+                            mount->parameters_proc_self_mountinfo.what) {
1ff636
+
1ff636
+                                /* Remember that this device might just have disappeared */
1ff636
+                                if (set_ensure_allocated(&gone, &string_hash_ops) < 0 ||
1ff636
+                                    set_put(gone, mount->parameters_proc_self_mountinfo.what) < 0)
1ff636
+                                        log_oom(); /* we don't care too much about OOM here... */
1ff636
+                        }
1ff636
 
1ff636
                         mount->from_proc_self_mountinfo = false;
1ff636
 
1ff636
@@ -1785,14 +1796,6 @@ static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents,
1ff636
                                 break;
1ff636
                         }
1ff636
 
1ff636
-                        /* Remember that this device might just have disappeared */
1ff636
-                        if (mount->parameters_proc_self_mountinfo.what) {
1ff636
-
1ff636
-                                if (set_ensure_allocated(&gone, &string_hash_ops) < 0 ||
1ff636
-                                    set_put(gone, mount->parameters_proc_self_mountinfo.what) < 0)
1ff636
-                                        log_oom(); /* we don't care too much about OOM here... */
1ff636
-                        }
1ff636
-
1ff636
                 } else if (mount->just_mounted || mount->just_changed) {
1ff636
 
1ff636
                         /* A mount point was added or changed */
1ff636
@@ -1820,13 +1823,15 @@ static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents,
1ff636
                                 mount_set_state(mount, mount->state);
1ff636
                                 break;
1ff636
                         }
1ff636
+                }
1ff636
 
1ff636
-                        if (mount->parameters_proc_self_mountinfo.what) {
1ff636
+                if (mount->is_mounted &&
1ff636
+                    mount->from_proc_self_mountinfo &&
1ff636
+                    mount->parameters_proc_self_mountinfo.what) {
1ff636
 
1ff636
-                                if (set_ensure_allocated(&around, &string_hash_ops) < 0 ||
1ff636
-                                    set_put(around, mount->parameters_proc_self_mountinfo.what) < 0)
1ff636
-                                        log_oom();
1ff636
-                        }
1ff636
+                        if (set_ensure_allocated(&around, &string_hash_ops) < 0 ||
1ff636
+                            set_put(around, mount->parameters_proc_self_mountinfo.what) < 0)
1ff636
+                                log_oom();
1ff636
                 }
1ff636
 
1ff636
                 /* Reset the flags for later calls */