chiark / gitweb /
user-sessions: rely on PID 1 to kill sessions
[elogind.git] / src / core / dbus-unit.c
index 4605b2fe07de723e06cbc8a389ac946da6527c2a..57fac00d19a2769ae0160139abc96956331722b6 100644 (file)
@@ -794,6 +794,7 @@ static int bus_unit_set_transient_property(
                         return -EINVAL;
 
                 if (mode != UNIT_CHECK) {
+                        _cleanup_free_ char *contents = NULL;
                         const char *description;
 
                         dbus_message_iter_get_basic(i, &description);
@@ -801,6 +802,12 @@ static int bus_unit_set_transient_property(
                         r = unit_set_description(u, description);
                         if (r < 0)
                                 return r;
+
+                        contents = strjoin("[Unit]\nDescription=", description, "\n", NULL);
+                        if (!contents)
+                                return -ENOMEM;
+
+                        unit_write_drop_in(u, mode, "Description", contents);
                 }
 
                 return 1;
@@ -818,6 +825,8 @@ static int bus_unit_set_transient_property(
                         if (mode != UNIT_CHECK)
                                 unit_ref_unset(&u->slice);
                 } else {
+                        _cleanup_free_ char *contents = NULL;
+
                         r = manager_load_unit(u->manager, s, NULL, error, &slice);
                         if (r < 0)
                                 return r;
@@ -827,8 +836,71 @@ static int bus_unit_set_transient_property(
 
                         if (mode != UNIT_CHECK)
                                 unit_ref_set(&u->slice, slice);
+
+                        contents = strjoin("[", UNIT_VTABLE(u)->private_section, "]\nSlice=", s, NULL);
+                        if (!contents)
+                                return -ENOMEM;
+
+                        unit_write_drop_in(u, mode, "Slice", contents);
                 }
                 return 1;
+
+        } else if (streq(name, "Requires") ||
+                   streq(name, "RequiresOverridable") ||
+                   streq(name, "Requisite") ||
+                   streq(name, "RequisiteOverridable") ||
+                   streq(name, "Wants") ||
+                   streq(name, "BindsTo") ||
+                   streq(name, "Conflicts") ||
+                   streq(name, "Before") ||
+                   streq(name, "After") ||
+                   streq(name, "OnFailure") ||
+                   streq(name, "PropagatesReloadTo") ||
+                   streq(name, "ReloadPropagatedFrom") ||
+                   streq(name, "PartOf")) {
+
+                UnitDependency d;
+                DBusMessageIter sub;
+
+                d = unit_dependency_from_string(name);
+                if (d < 0)
+                        return -EINVAL;
+
+                if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_ARRAY ||
+                    dbus_message_iter_get_element_type(i) != DBUS_TYPE_STRING)
+                        return -EINVAL;
+
+                dbus_message_iter_recurse(i, &sub);
+                while (dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_STRING) {
+                        const char *other;
+
+                        dbus_message_iter_get_basic(&sub, &other);
+
+                        if (!unit_name_is_valid(other, false))
+                                return -EINVAL;
+
+                        if (mode != UNIT_CHECK) {
+                                _cleanup_free_ char *label = NULL, *contents = NULL;
+
+                                r = unit_add_dependency_by_name(u, d, other, NULL, true);
+                                if (r < 0)
+                                        return r;
+
+                                label = strjoin(name, "-", other, NULL);
+                                if (!label)
+                                        return -ENOMEM;
+
+                                contents = strjoin("[Unit]\n", name, "=", other, "\n", NULL);
+                                if (!contents)
+                                        return -ENOMEM;
+
+                                unit_write_drop_in(u, mode, label, contents);
+                        }
+
+                        dbus_message_iter_next(&sub);
+                }
+
+                return 1;
         }
 
         return 0;