1abbee
From e360c720533dccac39d8b88510b15c21a944b042 Mon Sep 17 00:00:00 2001
1abbee
From: Lennart Poettering <lennart@poettering.net>
1abbee
Date: Fri, 13 Nov 2015 18:46:50 +0100
1abbee
Subject: [PATCH] core: enable transient unit support for slice units
1abbee
1abbee
Cherry-picked from: 17f62e9bd00f5fefd486475861b06d3ec6b7ee10
1abbee
Resolves: #1370299
1abbee
---
1abbee
 src/core/dbus-manager.c | 13 ++++++++++++-
1abbee
 src/core/slice.c        |  1 +
1abbee
 2 files changed, 13 insertions(+), 1 deletion(-)
1abbee
1abbee
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
181b3f
index 9eef290ca..8d3758ac7 100644
1abbee
--- a/src/core/dbus-manager.c
1abbee
+++ b/src/core/dbus-manager.c
1abbee
@@ -633,7 +633,18 @@ static int transient_unit_from_message(
1abbee
         if (r < 0)
1abbee
                 return r;
1abbee
 
1abbee
-        if (u->load_state != UNIT_NOT_FOUND ||
1abbee
+        /* Check if the unit already exists or is already referenced,
1abbee
+         * in a number of different ways. Note that to cater for unit
1abbee
+         * types such as slice, we are generally fine with units that
1abbee
+         * are marked UNIT_LOADED even even though nothing was
1abbee
+         * actually loaded, as those unit types don't require a file
1abbee
+         * on disk to validly load. */
1abbee
+
1abbee
+        if (!IN_SET(u->load_state, UNIT_NOT_FOUND, UNIT_LOADED) ||
1abbee
+            u->fragment_path ||
1abbee
+            u->source_path ||
1abbee
+            !strv_isempty(u->dropin_paths) ||
1abbee
+            u->refs ||
1abbee
             set_size(u->dependencies[UNIT_REFERENCED_BY]) > 0)
1abbee
                 return sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, "Unit %s already exists.", name);
1abbee
 
1abbee
diff --git a/src/core/slice.c b/src/core/slice.c
181b3f
index 61ff9d331..9154558b7 100644
1abbee
--- a/src/core/slice.c
1abbee
+++ b/src/core/slice.c
1abbee
@@ -272,6 +272,7 @@ const UnitVTable slice_vtable = {
1abbee
 
1abbee
         .no_alias = true,
1abbee
         .no_instances = true,
1abbee
+        .can_transient = true,
1abbee
 
1abbee
         .load = slice_load,
1abbee