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