dbus-scope.c revision 96aad8d15a324d0e956a4e5653a11a67b209b41a
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2013 Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int bus_scope_abandon(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
b93312f5960b276bae915906ccde36f545bae3e0Zbigniew Jędrzejewski-Szmek r = bus_verify_manage_unit_async(UNIT(s)->manager, message, error);
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering return sd_bus_error_setf(error, BUS_ERROR_SCOPE_NOT_RUNNING, "Scope %s is not running, cannot abandon.", UNIT(s)->id);
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering return sd_bus_reply_method_return(message, NULL);
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poetteringstatic BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, scope_result, ScopeResult);
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poetteringconst sd_bus_vtable bus_scope_vtable[] = {
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering SD_BUS_PROPERTY("Controller", "s", NULL, offsetof(Scope, controller), SD_BUS_VTABLE_PROPERTY_CONST),
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering SD_BUS_PROPERTY("TimeoutStopUSec", "t", bus_property_get_usec, offsetof(Scope, timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST),
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Scope, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering SD_BUS_METHOD("Abandon", NULL, NULL, bus_scope_abandon, 0),
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poetteringstatic int bus_scope_set_transient_property(
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering unsigned n = 0;
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering r = sd_bus_message_enter_container(message, 'a', "u");
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering while ((r = sd_bus_message_read(message, "u", &pid)) > 0) {
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering if (r < 0 && r != -EEXIST)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering r = sd_bus_message_exit_container(message);
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering r = sd_bus_message_read(message, "s", &controller);
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering if (!isempty(controller) && !service_name_is_valid(controller))
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Controller '%s' is not a valid bus name.", controller);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering } else if (streq(name, "TimeoutStopUSec")) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = sd_bus_message_read(message, "t", &s->timeout_stop_usec);
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering unit_write_drop_in_format(UNIT(s), mode, name, "[Scope]\nTimeoutStopSec="USEC_FMT"us\n", s->timeout_stop_usec);
abf126a355e2f2b62b6c51ab3bb37895d1e3eee7Tom Gundersen r = bus_cgroup_set_property(u, &s->cgroup_context, name, message, mode, error);
549c1a2564b56f2bb38f1203d59c747ea15817f3Tom Gundersen /* While we are created we still accept PIDs */
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering r = bus_scope_set_transient_property(s, name, message, mode, error);
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering r = bus_kill_context_set_transient_property(u, &s->kill_context, name, message, mode, error);
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmekint bus_scope_commit_properties(Unit *u) {
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek unit_update_cgroup_members_masks(u);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmekint bus_scope_send_request_stop(Scope *s) {
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen "RequestStop");
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen return sd_bus_send_to(UNIT(s)->manager->api_bus, m, /* s->controller */ NULL, NULL);