valeriyvdovin / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone

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

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