valeriyvdovin / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

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

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