Blame SOURCES/0297-core-look-for-instance-when-processing-template-name.patch

17b0f1
From 0e6ec33b5e8c8790e60d1b79801dc360dad010d3 Mon Sep 17 00:00:00 2001
17b0f1
From: Michal Sekletar <msekleta@redhat.com>
17b0f1
Date: Wed, 16 Mar 2016 15:47:18 +0100
17b0f1
Subject: [PATCH] core: look for instance when processing template name
17b0f1
17b0f1
If first attempt to merge units failed and we are trying to do
17b0f1
merge the other way around and at the same time we are working with
17b0f1
template name, then other unit can't possibly be template, because it is
17b0f1
not possible to have template unit running, only instances of the
17b0f1
template. Thus we need to look for already active instance instead.
17b0f1
17b0f1
rhel-only (upstream review pending)
17b0f1
17b0f1
Related: #1159308
17b0f1
---
17b0f1
 src/core/load-fragment.c | 11 ++++++++++-
17b0f1
 1 file changed, 10 insertions(+), 1 deletion(-)
17b0f1
17b0f1
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
17b0f1
index 70c09188a3..b188ec99d9 100644
17b0f1
--- a/src/core/load-fragment.c
17b0f1
+++ b/src/core/load-fragment.c
17b0f1
@@ -3472,8 +3472,17 @@ static int merge_by_names(Unit **u, Set *names, const char *id) {
17b0f1
                         /* Hmm, we couldn't merge the other unit into
17b0f1
                          * ours? Then let's try it the other way
17b0f1
                          * round */
17b0f1
+                        if (unit_name_is_template(k) && (*u)->instance) {
17b0f1
+                                _cleanup_free_ char *instance = NULL;
17b0f1
+
17b0f1
+                                instance = unit_name_replace_instance(k, (*u)->instance);
17b0f1
+                                if(!instance)
17b0f1
+                                        return -ENOMEM;
17b0f1
+                                other = manager_get_unit((*u)->manager, instance);
17b0f1
+
17b0f1
+                        } else
17b0f1
+                                other = manager_get_unit((*u)->manager, k);
17b0f1
 
17b0f1
-                        other = manager_get_unit((*u)->manager, k);
17b0f1
                         free(k);
17b0f1
 
17b0f1
                         if (other) {