923a60
From d772781b2810ae71bace24cce05f255212a348ed Mon Sep 17 00:00:00 2001
923a60
From: Franck Bui <fbui@suse.com>
923a60
Date: Thu, 8 Oct 2015 19:06:06 +0200
923a60
Subject: [PATCH] Make sure the mount units pulled by 'RequiresMountsFor=' are
923a60
 loaded (if they exist)
923a60
923a60
We should make sure that mount units involved by 'RequiresMountsFor='
923a60
directives are really loaded if not required by any others units so
923a60
that Requires= dependencies on the mount units are applied and thus
923a60
the mount unit dependencies are started.
923a60
923a60
(cherry-picked from commit c7c89abb9edf9320246482bf4a8e0656199281ae)
923a60
923a60
Resolves: #1619743
923a60
---
923a60
 src/core/unit.c | 18 ++++++++++++++----
923a60
 1 file changed, 14 insertions(+), 4 deletions(-)
923a60
923a60
diff --git a/src/core/unit.c b/src/core/unit.c
923a60
index cfddce34d4..e8532a057d 100644
923a60
--- a/src/core/unit.c
923a60
+++ b/src/core/unit.c
923a60
@@ -1131,13 +1131,23 @@ static int unit_add_mount_dependencies(Unit *u) {
923a60
                 char prefix[strlen(*i) + 1];
923a60
 
923a60
                 PATH_FOREACH_PREFIX_MORE(prefix, *i) {
923a60
+                        _cleanup_free_ char *p = NULL;
923a60
                         Unit *m;
923a60
 
923a60
-                        r = manager_get_unit_by_path(u->manager, prefix, ".mount", &m);
923a60
-                        if (r < 0)
923a60
-                                return r;
923a60
-                        if (r == 0)
923a60
+                        p = unit_name_from_path(prefix, ".mount");
923a60
+                        if (!p)
923a60
+                                return -ENOMEM;
923a60
+
923a60
+                        m = manager_get_unit(u->manager, p);
923a60
+                        if (!m) {
923a60
+                                /* Make sure to load the mount unit if
923a60
+                                 * it exists. If so the dependencies
923a60
+                                 * on this unit will be added later
923a60
+                                 * during the loading of the mount
923a60
+                                 * unit. */
923a60
+                                (void) manager_load_unit_prepare(u->manager, p, NULL, NULL, &m);
923a60
                                 continue;
923a60
+                        }
923a60
                         if (m == u)
923a60
                                 continue;
923a60