dbus-scope.c revision 1d22e9068c52c1cf935bcdff70b9b9654e3c939e
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen This file is part of systemd.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen Copyright 2013 Lennart Poettering
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen systemd is free software; you can redistribute it and/or modify it
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen under the terms of the GNU Lesser General Public License as published by
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen the Free Software Foundation; either version 2.1 of the License, or
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen (at your option) any later version.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen systemd is distributed in the hope that it will be useful, but
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen Lesser General Public License for more details.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen You should have received a copy of the GNU Lesser General Public License
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
a6f1e036de8f212f33ead7f5387c297afd8be26eTom Gundersenstatic int bus_scope_abandon(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen r = mac_selinux_unit_access_check(UNIT(s), message, "stop", error);
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen r = bus_verify_manage_units_async(UNIT(s)->manager, message, error);
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
a6f1e036de8f212f33ead7f5387c297afd8be26eTom Gundersen return sd_bus_error_setf(error, BUS_ERROR_SCOPE_NOT_RUNNING, "Scope %s is not running, cannot abandon.", UNIT(s)->id);
20af7091de0cdf92bf299addfc3f96c3ef805bd8Tom Gundersen return sd_bus_reply_method_return(message, NULL);
59b8f6b628145586e87b8a4f6e29c755ad7d61edTom Gundersenstatic BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, scope_result, ScopeResult);
20af7091de0cdf92bf299addfc3f96c3ef805bd8Tom Gundersen SD_BUS_PROPERTY("Controller", "s", NULL, offsetof(Scope, controller), SD_BUS_VTABLE_PROPERTY_CONST),
20af7091de0cdf92bf299addfc3f96c3ef805bd8Tom Gundersen SD_BUS_PROPERTY("TimeoutStopUSec", "t", bus_property_get_usec, offsetof(Scope, timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST),
20af7091de0cdf92bf299addfc3f96c3ef805bd8Tom Gundersen SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Scope, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
7c16313f11e3953f3fe4dbf544f2d36f58d14138Tom Gundersen SD_BUS_METHOD("Abandon", NULL, NULL, bus_scope_abandon, SD_BUS_VTABLE_UNPRIVILEGED),
a6f1e036de8f212f33ead7f5387c297afd8be26eTom Gundersen unsigned n = 0;
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen r = sd_bus_message_enter_container(message, 'a', "u");
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen while ((r = sd_bus_message_read(message, "u", &pid)) > 0) {
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen if (r < 0 && r != -EEXIST)
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen r = sd_bus_message_read(message, "s", &controller);
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen if (!isempty(controller) && !service_name_is_valid(controller))
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Controller '%s' is not a valid bus name.", controller);
3bdace9bf779ce051f00c14914b35c3a26164aa9Lennart Poettering } else if (streq(name, "TimeoutStopUSec")) {
3bdace9bf779ce051f00c14914b35c3a26164aa9Lennart Poettering r = sd_bus_message_read(message, "t", &s->timeout_stop_usec);
3bdace9bf779ce051f00c14914b35c3a26164aa9Lennart Poettering unit_write_drop_in_format(UNIT(s), mode, name, "[Scope]\nTimeoutStopSec="USEC_FMT"us\n", s->timeout_stop_usec);
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen r = bus_cgroup_set_property(u, &s->cgroup_context, name, message, mode, error);
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen /* While we are created we still accept PIDs */
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen r = bus_scope_set_transient_property(s, name, message, mode, error);
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen r = bus_kill_context_set_transient_property(u, &s->kill_context, name, message, mode, error);
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen "RequestStop");
a6f1e036de8f212f33ead7f5387c297afd8be26eTom Gundersen return sd_bus_send_to(UNIT(s)->manager->api_bus, m, /* s->controller */ NULL, NULL);