]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: refuse merging on units when the unit type does not support alias
authorLennart Poettering <lennart@poettering.net>
Fri, 29 Apr 2016 15:31:02 +0000 (17:31 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 29 Apr 2016 15:31:02 +0000 (17:31 +0200)
The concept of merging units exists so that we can create Unit objects for a
number of names early, and then load them only later, possibly merging units
which then turn out to be symlinked to other names. This of course only makes
sense for unit types where multiple names per unit are supported. For all
others, let's refuse the merge operation early.

src/core/unit.c

index cb79c7c6b1d7cde10c541d822465ccedbd0a559a..4a129ffd5e92b37373fe636635199bf8c5d5fa4a 100644 (file)
@@ -720,6 +720,9 @@ int unit_merge(Unit *u, Unit *other) {
         if (!u->instance != !other->instance)
                 return -EINVAL;
 
+        if (UNIT_VTABLE(u)->no_alias) /* Merging only applies to unit names that support aliases */
+                return -EEXIST;
+
         if (other->load_state != UNIT_STUB &&
             other->load_state != UNIT_NOT_FOUND)
                 return -EEXIST;
@@ -776,9 +779,9 @@ int unit_merge(Unit *u, Unit *other) {
 }
 
 int unit_merge_by_name(Unit *u, const char *name) {
+        _cleanup_free_ char *s = NULL;
         Unit *other;
         int r;
-        _cleanup_free_ char *s = NULL;
 
         assert(u);
         assert(name);