anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

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

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