]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: look for instance when processing template name 2856/head
authorMichal Sekletar <msekleta@redhat.com>
Wed, 16 Mar 2016 13:52:44 +0000 (14:52 +0100)
committerMichal Sekletar <msekleta@redhat.com>
Wed, 16 Mar 2016 14:40:14 +0000 (15:40 +0100)
If first attempt to merge units failed and we are trying to do
merge the other way around and at the same time we are working with
template name, then other unit can't possibly be template, because it is
not possible to have template unit running, only instances of the
template. Thus we need to look for already active instance instead.

src/core/load-fragment.c

index e1bfdccbca0435759bf58eff186e5ec692bd9621..d078924c5ba981d8538229d8df0be69cf598e101 100644 (file)
@@ -3507,7 +3507,19 @@ static int merge_by_names(Unit **u, Set *names, const char *id) {
                          * ours? Then let's try it the other way
                          * round */
 
-                        other = manager_get_unit((*u)->manager, k);
+                        /* If the symlink name we are looking at is unit template, then
+                           we must search for instance of this template */
+                        if (unit_name_is_valid(k, UNIT_NAME_TEMPLATE)) {
+                                _cleanup_free_ char *instance = NULL;
+
+                                r = unit_name_replace_instance(k, (*u)->instance, &instance);
+                                if (r < 0)
+                                        return r;
+
+                                other = manager_get_unit((*u)->manager, instance);
+                        } else
+                                other = manager_get_unit((*u)->manager, k);
+
                         free(k);
 
                         if (other) {