|
26 | 26 | #include "dbus-kill.h" |
27 | 27 | #include "dbus-scope.h" |
28 | 28 | #include "bus-util.h" |
| 29 | +#include "bus-internal.h" |
29 | 30 |
|
30 | 31 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, scope_result, ScopeResult); |
31 | 32 |
|
32 | 33 | const sd_bus_vtable bus_scope_vtable[] = { |
33 | 34 | SD_BUS_VTABLE_START(0), |
| 35 | + SD_BUS_PROPERTY("Controller", "s", NULL, offsetof(Scope, controller), SD_BUS_VTABLE_PROPERTY_CONST), |
34 | 36 | SD_BUS_PROPERTY("TimeoutStopUSec", "t", bus_property_get_usec, offsetof(Scope, timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST), |
35 | 37 | SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Scope, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), |
| 38 | + SD_BUS_SIGNAL("RequestStop", NULL, 0), |
36 | 39 | SD_BUS_VTABLE_END |
37 | 40 | }; |
38 | 41 |
|
@@ -86,6 +89,32 @@ static int bus_scope_set_transient_property( |
86 | 89 |
|
87 | 90 | return 1; |
88 | 91 |
|
| 92 | + } else if (streq(name, "Controller")) { |
| 93 | + const char *controller; |
| 94 | + char *c; |
| 95 | + |
| 96 | + r = sd_bus_message_read(message, "s", &controller); |
| 97 | + if (r < 0) |
| 98 | + return r; |
| 99 | + |
| 100 | + if (!isempty(controller) && !service_name_is_valid(controller)) |
| 101 | + return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Controller '%s' is not a valid bus name.", controller); |
| 102 | + |
| 103 | + if (mode != UNIT_CHECK) { |
| 104 | + if (isempty(controller)) |
| 105 | + c = NULL; |
| 106 | + else { |
| 107 | + c = strdup(controller); |
| 108 | + if (!c) |
| 109 | + return -ENOMEM; |
| 110 | + } |
| 111 | + |
| 112 | + free(s->controller); |
| 113 | + s->controller = c; |
| 114 | + } |
| 115 | + |
| 116 | + return 1; |
| 117 | + |
89 | 118 | } else if (streq(name, "TimeoutStopUSec")) { |
90 | 119 |
|
91 | 120 | if (mode != UNIT_CHECK) { |
@@ -145,3 +174,29 @@ int bus_scope_commit_properties(Unit *u) { |
145 | 174 | unit_realize_cgroup(u); |
146 | 175 | return 0; |
147 | 176 | } |
| 177 | + |
| 178 | +int bus_scope_send_request_stop(Scope *s) { |
| 179 | + _cleanup_bus_message_unref_ sd_bus_message *m = NULL; |
| 180 | + _cleanup_free_ char *p = NULL; |
| 181 | + int r; |
| 182 | + |
| 183 | + assert(s); |
| 184 | + |
| 185 | + if (!s->controller) |
| 186 | + return 0; |
| 187 | + |
| 188 | + p = unit_dbus_path(UNIT(s)); |
| 189 | + if (!p) |
| 190 | + return -ENOMEM; |
| 191 | + |
| 192 | + r = sd_bus_message_new_signal( |
| 193 | + UNIT(s)->manager->api_bus, |
| 194 | + p, |
| 195 | + "org.freedesktop.systemd1.Scope", |
| 196 | + "RequestStop", |
| 197 | + &m); |
| 198 | + if (r < 0) |
| 199 | + return r; |
| 200 | + |
| 201 | + return sd_bus_send_to(UNIT(s)->manager->api_bus, m, /* s->controller */ NULL, NULL); |
| 202 | +} |
0 commit comments