busname.c revision ce30c8dcb41dfe9264f79f30c7f51c0e74576638
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering/***
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering This file is part of systemd.
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering Copyright 2013 Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering systemd is free software; you can redistribute it and/or modify it
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering under the terms of the GNU Lesser General Public License as published by
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering (at your option) any later version.
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering systemd is distributed in the hope that it will be useful, but
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering Lesser General Public License for more details.
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering You should have received a copy of the GNU Lesser General Public License
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering***/
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering#include <sys/mman.h>
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering#include "special.h"
24882e06c135584f16f31ba8a00fecde8b7f6fadLennart Poettering#include "formats-util.h"
24882e06c135584f16f31ba8a00fecde8b7f6fadLennart Poettering#include "signal-util.h"
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering#include "bus-kernel.h"
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering#include "bus-internal.h"
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering#include "bus-util.h"
3c70e3bb022f0de3317f3600c9366a2f4597339eLennart Poettering#include "kdbus.h"
3c70e3bb022f0de3317f3600c9366a2f4597339eLennart Poettering#include "bus-policy.h"
24882e06c135584f16f31ba8a00fecde8b7f6fadLennart Poettering#include "service.h"
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering#include "dbus-busname.h"
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering#include "busname.h"
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic const UnitActiveState state_translation_table[_BUSNAME_STATE_MAX] = {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering [BUSNAME_DEAD] = UNIT_INACTIVE,
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering [BUSNAME_MAKING] = UNIT_ACTIVATING,
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack [BUSNAME_REGISTERED] = UNIT_ACTIVE,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering [BUSNAME_LISTENING] = UNIT_ACTIVE,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering [BUSNAME_RUNNING] = UNIT_ACTIVE,
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering [BUSNAME_SIGTERM] = UNIT_DEACTIVATING,
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering [BUSNAME_SIGKILL] = UNIT_DEACTIVATING,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering [BUSNAME_FAILED] = UNIT_FAILED
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering};
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic int busname_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringstatic int busname_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic void busname_init(Unit *u) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering BusName *n = BUSNAME(u);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(u);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(u->load_state == UNIT_STUB);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering n->starter_fd = -1;
3f9da416457c4265b8f1179516a32ad1a987ff7dLennart Poettering n->accept_fd = true;
4f10118016f9b2fd7e1d26c9ef7d91eb33fba694Lennart Poettering n->activating = true;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering n->timeout_usec = u->manager->default_timeout_start_usec;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering}
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringstatic void busname_unwatch_control_pid(BusName *n) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert(n);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (n->control_pid <= 0)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering unit_unwatch_pid(UNIT(n), n->control_pid);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering n->control_pid = 0;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering}
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringstatic void busname_free_policy(BusName *n) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering BusNamePolicy *p;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert(n);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering while ((p = n->policy)) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering LIST_REMOVE(policy, n->policy, p);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering free(p->name);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering free(p);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering }
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering}
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringstatic void busname_close_fd(BusName *n) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert(n);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering n->starter_event_source = sd_event_source_unref(n->starter_event_source);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering n->starter_fd = safe_close(n->starter_fd);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic void busname_done(Unit *u) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering BusName *n = BUSNAME(u);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
a1e58e8ee1c84b633d6d6d651d5328d4dd4eba5bLennart Poettering free(n->name);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering n->name = NULL;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering busname_free_policy(n);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering busname_unwatch_control_pid(n);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering busname_close_fd(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering unit_ref_unset(&n->service);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering n->timer_event_source = sd_event_source_unref(n->timer_event_source);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering}
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringstatic int busname_arm_timer(BusName *n) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering int r;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert(n);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (n->timeout_usec <= 0) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering n->timer_event_source = sd_event_source_unref(n->timer_event_source);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return 0;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering }
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (n->timer_event_source) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering r = sd_event_source_set_time(n->timer_event_source, now(CLOCK_MONOTONIC) + n->timeout_usec);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (r < 0)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return r;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return sd_event_source_set_enabled(n->timer_event_source, SD_EVENT_ONESHOT);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering }
920b52e4909d9dc812817fd8b82f83ca23a11c91Thomas Hindoe Paaboel Andersen
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering r = sd_event_add_time(
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering UNIT(n)->manager->event,
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering &n->timer_event_source,
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering CLOCK_MONOTONIC,
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering now(CLOCK_MONOTONIC) + n->timeout_usec, 0,
7dfbe2e3fc0215b49d8202a32beb6b1aae08c4e4Tom Gundersen busname_dispatch_timer, n);
7dfbe2e3fc0215b49d8202a32beb6b1aae08c4e4Tom Gundersen if (r < 0)
7dfbe2e3fc0215b49d8202a32beb6b1aae08c4e4Tom Gundersen return r;
7dfbe2e3fc0215b49d8202a32beb6b1aae08c4e4Tom Gundersen
7dfbe2e3fc0215b49d8202a32beb6b1aae08c4e4Tom Gundersen (void) sd_event_source_set_description(n->timer_event_source, "busname-timer");
7dfbe2e3fc0215b49d8202a32beb6b1aae08c4e4Tom Gundersen
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return 0;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic int busname_add_default_default_dependencies(BusName *n) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering int r;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering r = unit_add_dependency_by_name(UNIT(n), UNIT_BEFORE, SPECIAL_BUSNAMES_TARGET, NULL, true);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (r < 0)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return r;
b2c23da8cea1987a1a329f5a964d3299b7ca7890Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (UNIT(n)->manager->running_as == MANAGER_SYSTEM) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering r = unit_add_two_dependencies_by_name(UNIT(n), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SYSINIT_TARGET, NULL, true);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (r < 0)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return r;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering }
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return unit_add_two_dependencies_by_name(UNIT(n), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic int busname_add_extras(BusName *n) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering Unit *u = UNIT(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering int r;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering if (!n->name) {
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering r = unit_name_to_prefix(u->id, &n->name);
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering if (r < 0)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return r;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering }
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (!u->description) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering r = unit_set_description(u, n->name);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (r < 0)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return r;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering }
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack if (n->activating) {
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack if (!UNIT_DEREF(n->service)) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering Unit *x;
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack r = unit_load_related_unit(u, ".service", &x);
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack if (r < 0)
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack return r;
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack unit_ref_set(&n->service, x);
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack }
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering r = unit_add_two_dependencies(u, UNIT_BEFORE, UNIT_TRIGGERS, UNIT_DEREF(n->service), true);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (r < 0)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return r;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering }
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (u->default_dependencies) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering r = busname_add_default_default_dependencies(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (r < 0)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return r;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering }
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return 0;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic int busname_verify(BusName *n) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering char *e;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (UNIT(n)->load_state != UNIT_LOADED)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return 0;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering if (!service_name_is_valid(n->name)) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering log_unit_error(UNIT(n), "Name= setting is not a valid service name Refusing.");
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return -EINVAL;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering }
63c372cb9df3bee01e3bf8cd7f96f336bddda846Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering e = strjoina(n->name, ".busname");
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering if (!unit_has_name(UNIT(n), e)) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering log_unit_error(UNIT(n), "Name= setting doesn't match unit name. Refusing.");
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return -EINVAL;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering }
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return 0;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic int busname_load(Unit *u) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering BusName *n = BUSNAME(u);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering int r;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(u);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(u->load_state == UNIT_STUB);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering r = unit_load_fragment_and_dropin(u);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (r < 0)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return r;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (u->load_state == UNIT_LOADED) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering /* This is a new unit? Then let's add in some extras */
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering r = busname_add_extras(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (r < 0)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return r;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering }
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return busname_verify(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic void busname_dump(Unit *u, FILE *f, const char *prefix) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering BusName *n = BUSNAME(u);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(f);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering fprintf(f,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering "%sBus Name State: %s\n"
3f9da416457c4265b8f1179516a32ad1a987ff7dLennart Poettering "%sResult: %s\n"
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack "%sName: %s\n"
3f9da416457c4265b8f1179516a32ad1a987ff7dLennart Poettering "%sActivating: %s\n"
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering "%sAccept FD: %s\n",
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering prefix, busname_state_to_string(n->state),
3f9da416457c4265b8f1179516a32ad1a987ff7dLennart Poettering prefix, busname_result_to_string(n->result),
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack prefix, n->name,
3f9da416457c4265b8f1179516a32ad1a987ff7dLennart Poettering prefix, yes_no(n->activating),
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering prefix, yes_no(n->accept_fd));
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (n->control_pid > 0)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering fprintf(f,
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering "%sControl PID: "PID_FMT"\n",
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering prefix, n->control_pid);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic void busname_unwatch_fd(BusName *n) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering int r;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(n);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (!n->starter_event_source)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering r = sd_event_source_set_enabled(n->starter_event_source, SD_EVENT_OFF);
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering if (r < 0)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering log_unit_debug_errno(UNIT(n), r, "Failed to disable event source: %m");
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic int busname_watch_fd(BusName *n) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering int r;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (n->starter_fd < 0)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return 0;
cbf60d0a7fda7bd6c0578a6cc151f798a0edfd02Lennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (n->starter_event_source) {
cbf60d0a7fda7bd6c0578a6cc151f798a0edfd02Lennart Poettering r = sd_event_source_set_enabled(n->starter_event_source, SD_EVENT_ON);
cbf60d0a7fda7bd6c0578a6cc151f798a0edfd02Lennart Poettering if (r < 0)
cbf60d0a7fda7bd6c0578a6cc151f798a0edfd02Lennart Poettering goto fail;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering } else {
cbf60d0a7fda7bd6c0578a6cc151f798a0edfd02Lennart Poettering r = sd_event_add_io(UNIT(n)->manager->event, &n->starter_event_source, n->starter_fd, EPOLLIN, busname_dispatch_io, n);
cbf60d0a7fda7bd6c0578a6cc151f798a0edfd02Lennart Poettering if (r < 0)
cfa9677bd164574600d29a9bf99f9d1f28a7a170Mantas MikulÄ—nas goto fail;
cbf60d0a7fda7bd6c0578a6cc151f798a0edfd02Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering (void) sd_event_source_set_description(n->starter_event_source, "busname-starter");
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering }
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
cbf60d0a7fda7bd6c0578a6cc151f798a0edfd02Lennart Poettering return 0;
cbf60d0a7fda7bd6c0578a6cc151f798a0edfd02Lennart Poettering
cbf60d0a7fda7bd6c0578a6cc151f798a0edfd02Lennart Poetteringfail:
cbf60d0a7fda7bd6c0578a6cc151f798a0edfd02Lennart Poettering log_unit_warning_errno(UNIT(n), r, "Failed to watch starter fd: %m");
cbf60d0a7fda7bd6c0578a6cc151f798a0edfd02Lennart Poettering busname_unwatch_fd(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return r;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
8f077bf94e129fa1b6f0159e3140c4326f1066cfZbigniew Jędrzejewski-Szmekstatic int busname_open_fd(BusName *n) {
8f077bf94e129fa1b6f0159e3140c4326f1066cfZbigniew Jędrzejewski-Szmek _cleanup_free_ char *path = NULL;
8f077bf94e129fa1b6f0159e3140c4326f1066cfZbigniew Jędrzejewski-Szmek const char *mode;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (n->starter_fd >= 0)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return 0;
b2c23da8cea1987a1a329f5a964d3299b7ca7890Lennart Poettering
8f077bf94e129fa1b6f0159e3140c4326f1066cfZbigniew Jędrzejewski-Szmek mode = UNIT(n)->manager->running_as == MANAGER_SYSTEM ? "system" : "user";
23bbb0de4e3f85d9704a5c12a5afa2dfa0159e41Michal Schmidt n->starter_fd = bus_kernel_open_bus_fd(mode, &path);
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering if (n->starter_fd < 0)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return log_unit_warning_errno(UNIT(n), n->starter_fd, "Failed to open %s: %m", path ?: "kdbus");
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return 0;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic void busname_set_state(BusName *n, BusNameState state) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering BusNameState old_state;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering old_state = n->state;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering n->state = state;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (!IN_SET(state, BUSNAME_MAKING, BUSNAME_SIGTERM, BUSNAME_SIGKILL)) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering n->timer_event_source = sd_event_source_unref(n->timer_event_source);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering busname_unwatch_control_pid(n);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering }
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (state != BUSNAME_LISTENING)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering busname_unwatch_fd(n);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (!IN_SET(state, BUSNAME_LISTENING, BUSNAME_MAKING, BUSNAME_REGISTERED, BUSNAME_RUNNING))
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering busname_close_fd(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering if (state != old_state)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering log_unit_debug(UNIT(n), "Changed %s -> %s", busname_state_to_string(old_state), busname_state_to_string(state));
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering unit_notify(UNIT(n), state_translation_table[old_state], state_translation_table[state], true);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
be847e82cf95bf8eb589778df2aa2b3d1d7ae99eLennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic int busname_coldplug(Unit *u) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering BusName *n = BUSNAME(u);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering int r;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(n->state == BUSNAME_DEAD);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (n->deserialized_state == n->state)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return 0;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (IN_SET(n->deserialized_state, BUSNAME_MAKING, BUSNAME_SIGTERM, BUSNAME_SIGKILL)) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (n->control_pid <= 0)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return -EBADMSG;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering r = unit_watch_pid(UNIT(n), n->control_pid);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (r < 0)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return r;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering r = busname_arm_timer(n);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (r < 0)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return r;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering }
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (IN_SET(n->deserialized_state, BUSNAME_MAKING, BUSNAME_LISTENING, BUSNAME_REGISTERED, BUSNAME_RUNNING)) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering r = busname_open_fd(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (r < 0)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return r;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering }
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (n->deserialized_state == BUSNAME_LISTENING) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering r = busname_watch_fd(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (r < 0)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return r;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering }
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering busname_set_state(n, n->deserialized_state);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return 0;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringstatic int busname_make_starter(BusName *n, pid_t *_pid) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering pid_t pid;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering int r;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering r = busname_arm_timer(n);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (r < 0)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering goto fail;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering /* We have to resolve the user/group names out-of-process,
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering * hence let's fork here. It's messy, but well, what can we
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering * do? */
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering pid = fork();
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (pid < 0)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return -errno;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (pid == 0) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering int ret;
ce30c8dcb41dfe9264f79f30c7f51c0e74576638Lennart Poettering
ce30c8dcb41dfe9264f79f30c7f51c0e74576638Lennart Poettering (void) default_signals(SIGNALS_CRASH_HANDLER, SIGNALS_IGNORE, -1);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering (void) ignore_signals(SIGPIPE, -1);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering log_forget_fds();
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering r = bus_kernel_make_starter(n->starter_fd, n->name, n->activating, n->accept_fd, n->policy, n->policy_world);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (r < 0) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering ret = EXIT_MAKE_STARTER;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering goto fail_child;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering }
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering _exit(0);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering fail_child:
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt log_open();
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering log_error_errno(r, "Failed to create starter connection at step %s: %m", exit_status_to_string(ret, EXIT_STATUS_SYSTEMD));
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering _exit(ret);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering }
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering r = unit_watch_pid(UNIT(n), pid);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (r < 0)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering goto fail;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering *_pid = pid;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return 0;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringfail:
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering n->timer_event_source = sd_event_source_unref(n->timer_event_source);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return r;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic void busname_enter_dead(BusName *n, BusNameResult f) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (f != BUSNAME_SUCCESS)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering n->result = f;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering busname_set_state(n, n->result != BUSNAME_SUCCESS ? BUSNAME_FAILED : BUSNAME_DEAD);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringstatic void busname_enter_signal(BusName *n, BusNameState state, BusNameResult f) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering KillContext kill_context = {};
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering int r;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(n);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (f != BUSNAME_SUCCESS)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering n->result = f;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering kill_context_init(&kill_context);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering r = unit_kill_context(UNIT(n),
db2cb23b5b179707000d28a11efb3d888d06ee80Umut Tezduyar Lindskog &kill_context,
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering state != BUSNAME_SIGTERM ? KILL_KILL : KILL_TERMINATE,
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering -1,
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering n->control_pid,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering false);
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering if (r < 0) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering log_unit_warning_errno(UNIT(n), r, "Failed to kill control process: %m");
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering goto fail;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering }
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (r > 0) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering r = busname_arm_timer(n);
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering if (r < 0) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering log_unit_warning_errno(UNIT(n), r, "Failed to arm timer: %m");
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering goto fail;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering }
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering busname_set_state(n, state);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering } else if (state == BUSNAME_SIGTERM)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering busname_enter_signal(n, BUSNAME_SIGKILL, BUSNAME_SUCCESS);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering else
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering busname_enter_dead(n, BUSNAME_SUCCESS);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringfail:
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering busname_enter_dead(n, BUSNAME_FAILURE_RESOURCES);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering}
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringstatic void busname_enter_listening(BusName *n) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering int r;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert(n);
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack if (n->activating) {
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack r = busname_watch_fd(n);
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering if (r < 0) {
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack log_unit_warning_errno(UNIT(n), r, "Failed to watch names: %m");
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack goto fail;
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack }
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack busname_set_state(n, BUSNAME_LISTENING);
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack } else
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering busname_set_state(n, BUSNAME_REGISTERED);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringfail:
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering busname_enter_signal(n, BUSNAME_SIGTERM, BUSNAME_FAILURE_RESOURCES);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering}
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringstatic void busname_enter_making(BusName *n) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering int r;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert(n);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering r = busname_open_fd(n);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (r < 0)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering goto fail;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
8d0e0ddda6501479eb69164687c83c1a7667b33aJan Engelhardt if (n->policy) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering /* If there is a policy, we need to resolve user/group
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering * names, which we can't do from PID1, hence let's
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering * fork. */
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering busname_unwatch_control_pid(n);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering r = busname_make_starter(n, &n->control_pid);
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering if (r < 0) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering log_unit_warning_errno(UNIT(n), r, "Failed to fork 'making' task: %m");
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering goto fail;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering }
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering busname_set_state(n, BUSNAME_MAKING);
8d0e0ddda6501479eb69164687c83c1a7667b33aJan Engelhardt } else {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering /* If there is no policy, we can do everything
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering * directly from PID 1, hence do so. */
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering r = bus_kernel_make_starter(n->starter_fd, n->name, n->activating, n->accept_fd, NULL, n->policy_world);
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering if (r < 0) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering log_unit_warning_errno(UNIT(n), r, "Failed to make starter: %m");
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering goto fail;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering }
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering busname_enter_listening(n);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering }
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringfail:
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering busname_enter_dead(n, BUSNAME_FAILURE_RESOURCES);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic void busname_enter_running(BusName *n) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering bool pending = false;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering Unit *other;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering Iterator i;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering int r;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(n);
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack if (!n->activating)
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack return;
05a08cb60f02970e8476306074c70ee4e6a57fb3Thomas Hindoe Paaboel Andersen
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering /* We don't take connections anymore if we are supposed to
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering * shut down anyway */
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering if (unit_stop_pending(UNIT(n))) {
16ac401407959cbc62312e61c2dd76dbc3a0793bLennart Poettering log_unit_debug(UNIT(n), "Suppressing activation request since unit stop is scheduled.");
16ac401407959cbc62312e61c2dd76dbc3a0793bLennart Poettering
ff975efb2e88dcd5221a2f0d76c4c87e85b821a8Lennart Poettering /* Flush all queued activation reqeuest by closing and reopening the connection */
16ac401407959cbc62312e61c2dd76dbc3a0793bLennart Poettering bus_kernel_drop_one(n->starter_fd);
16ac401407959cbc62312e61c2dd76dbc3a0793bLennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering busname_enter_listening(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering }
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering /* If there's already a start pending don't bother to do
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering * anything */
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering SET_FOREACH(other, UNIT(n)->dependencies[UNIT_TRIGGERS], i)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (unit_active_or_pending(other)) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering pending = true;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering break;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering }
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (!pending) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering r = manager_add_job(UNIT(n)->manager, JOB_START, UNIT_DEREF(n->service), JOB_REPLACE, true, &error, NULL);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (r < 0)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering goto fail;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering }
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering busname_set_state(n, BUSNAME_RUNNING);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poetteringfail:
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering log_unit_warning(UNIT(n), "Failed to queue service startup job: %s", bus_error_message(&error, r));
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering busname_enter_dead(n, BUSNAME_FAILURE_RESOURCES);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic int busname_start(Unit *u) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering BusName *n = BUSNAME(u);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(n);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering /* We cannot fulfill this request right now, try again later
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering * please! */
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (IN_SET(n->state, BUSNAME_SIGTERM, BUSNAME_SIGKILL))
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return -EAGAIN;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering /* Already on it! */
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (n->state == BUSNAME_MAKING)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return 0;
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (n->activating && UNIT_ISSET(n->service)) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering Service *service;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering service = SERVICE(UNIT_DEREF(n->service));
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering if (UNIT(service)->load_state != UNIT_LOADED) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering log_unit_error(u, "Bus service %s not loaded, refusing.", UNIT(service)->id);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return -ENOENT;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering }
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering }
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(IN_SET(n->state, BUSNAME_DEAD, BUSNAME_FAILED));
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering n->result = BUSNAME_SUCCESS;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering busname_enter_making(n);
82a2b6bb5e4e5d294f09af778c48974a7857afb6Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return 1;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic int busname_stop(Unit *u) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering BusName *n = BUSNAME(u);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert(n);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering /* Already on it */
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (IN_SET(n->state, BUSNAME_SIGTERM, BUSNAME_SIGKILL))
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return 0;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering /* If there's already something running, we go directly into
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering * kill mode. */
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (n->state == BUSNAME_MAKING) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering busname_enter_signal(n, BUSNAME_SIGTERM, BUSNAME_SUCCESS);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return -EAGAIN;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering }
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(IN_SET(n->state, BUSNAME_REGISTERED, BUSNAME_LISTENING, BUSNAME_RUNNING));
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
82a2b6bb5e4e5d294f09af778c48974a7857afb6Lennart Poettering busname_enter_dead(n, BUSNAME_SUCCESS);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return 1;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic int busname_serialize(Unit *u, FILE *f, FDSet *fds) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering BusName *n = BUSNAME(u);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(f);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(fds);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering unit_serialize_item(u, f, "state", busname_state_to_string(n->state));
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering unit_serialize_item(u, f, "result", busname_result_to_string(n->result));
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (n->control_pid > 0)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering unit_serialize_item_format(u, f, "control-pid", PID_FMT, n->control_pid);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (n->starter_fd >= 0) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering int copy;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering copy = fdset_put_dup(fds, n->starter_fd);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (copy < 0)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return copy;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering unit_serialize_item_format(u, f, "starter-fd", "%i", copy);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering }
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return 0;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic int busname_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering BusName *n = BUSNAME(u);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(key);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(value);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (streq(key, "state")) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering BusNameState state;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering state = busname_state_from_string(value);
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering if (state < 0)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering log_unit_debug(u, "Failed to parse state value: %s", value);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering else
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering n->deserialized_state = state;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering } else if (streq(key, "result")) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering BusNameResult f;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering f = busname_result_from_string(value);
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering if (f < 0)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering log_unit_debug(u, "Failed to parse result value: %s", value);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering else if (f != BUSNAME_SUCCESS)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering n->result = f;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering } else if (streq(key, "control-pid")) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering pid_t pid;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering if (parse_pid(value, &pid) < 0)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering log_unit_debug(u, "Failed to parse control-pid value: %s", value);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering else
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering n->control_pid = pid;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering } else if (streq(key, "starter-fd")) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering int fd;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering if (safe_atoi(value, &fd) < 0 || fd < 0 || !fdset_contains(fds, fd))
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering log_unit_debug(u, "Failed to parse starter fd value: %s", value);
03e334a1c7dc8c20c38902aa039440763acc9b17Lennart Poettering else {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering safe_close(n->starter_fd);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering n->starter_fd = fdset_remove(fds, fd);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering }
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering } else
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering log_unit_debug(u, "Unknown serialization key: %s", key);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return 0;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering_pure_ static UnitActiveState busname_active_state(Unit *u) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(u);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return state_translation_table[BUSNAME(u)->state];
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering_pure_ static const char *busname_sub_state_to_string(Unit *u) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(u);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return busname_state_to_string(BUSNAME(u)->state);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poetteringstatic int busname_peek_message(BusName *n) {
94e15fdc4d9d96fa6607bfb4eaaea164a3aec417David Herrmann struct kdbus_cmd_recv cmd_recv = {
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering .size = sizeof(cmd_recv),
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering .flags = KDBUS_RECV_PEEK,
e24e415e5f3af2fe86d2be9a1f1a2e8d5f8c96bfDaniel Mack };
e24e415e5f3af2fe86d2be9a1f1a2e8d5f8c96bfDaniel Mack struct kdbus_cmd_free cmd_free = {
e24e415e5f3af2fe86d2be9a1f1a2e8d5f8c96bfDaniel Mack .size = sizeof(cmd_free),
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering };
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering const char *comm = NULL;
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering struct kdbus_item *d;
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering struct kdbus_msg *k;
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering size_t start, ps, sz, delta;
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering void *p = NULL;
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering pid_t pid = 0;
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering int r;
dcc2fc01fa850e9ee36c549dc2691e7e5c71bebfLennart Poettering
dcc2fc01fa850e9ee36c549dc2691e7e5c71bebfLennart Poettering /* Generate a friendly debug log message about which process
dcc2fc01fa850e9ee36c549dc2691e7e5c71bebfLennart Poettering * caused triggering of this bus name. This simply peeks the
dcc2fc01fa850e9ee36c549dc2691e7e5c71bebfLennart Poettering * metadata of the first queued message and logs it. */
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering assert(n);
dcc2fc01fa850e9ee36c549dc2691e7e5c71bebfLennart Poettering
dcc2fc01fa850e9ee36c549dc2691e7e5c71bebfLennart Poettering /* Let's shortcut things a bit, if debug logging is turned off
dcc2fc01fa850e9ee36c549dc2691e7e5c71bebfLennart Poettering * anyway. */
dcc2fc01fa850e9ee36c549dc2691e7e5c71bebfLennart Poettering
dcc2fc01fa850e9ee36c549dc2691e7e5c71bebfLennart Poettering if (log_get_max_level() < LOG_DEBUG)
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering return 0;
94e15fdc4d9d96fa6607bfb4eaaea164a3aec417David Herrmann
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering r = ioctl(n->starter_fd, KDBUS_CMD_RECV, &cmd_recv);
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering if (r < 0) {
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering if (errno == EINTR || errno == EAGAIN)
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering return 0;
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering return log_unit_error_errno(UNIT(n), errno, "Failed to query activation message: %m");
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering }
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering /* We map as late as possible, and unmap imemdiately after
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering * use. On 32bit address space is scarce and we want to be
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering * able to handle a lot of activator connections at the same
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering * time, and hence shouldn't keep the mmap()s around for
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering * longer than necessary. */
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering
a9c8343e83ec09f80a76930573b2592f97ae4283Daniel Mack ps = page_size();
a9c8343e83ec09f80a76930573b2592f97ae4283Daniel Mack start = (cmd_recv.msg.offset / ps) * ps;
a9c8343e83ec09f80a76930573b2592f97ae4283Daniel Mack delta = cmd_recv.msg.offset - start;
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering sz = PAGE_ALIGN(delta + cmd_recv.msg.msg_size);
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering p = mmap(NULL, sz, PROT_READ, MAP_SHARED, n->starter_fd, start);
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering if (p == MAP_FAILED) {
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering r = log_unit_error_errno(UNIT(n), errno, "Failed to map activation message: %m");
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering goto finish;
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering }
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering k = (struct kdbus_msg *) ((uint8_t *) p + delta);
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering KDBUS_ITEM_FOREACH(d, k, items) {
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering switch (d->type) {
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering case KDBUS_ITEM_PIDS:
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering pid = d->pids.pid;
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering break;
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering case KDBUS_ITEM_PID_COMM:
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering comm = d->str;
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering break;
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering }
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering }
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering if (pid > 0)
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering log_unit_debug(UNIT(n), "Activation triggered by process " PID_FMT " (%s)", pid, strna(comm));
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering r = 0;
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poetteringfinish:
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering if (p)
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering (void) munmap(p, sz);
a9c8343e83ec09f80a76930573b2592f97ae4283Daniel Mack
dcc2fc01fa850e9ee36c549dc2691e7e5c71bebfLennart Poettering cmd_free.offset = cmd_recv.msg.offset;
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering if (ioctl(n->starter_fd, KDBUS_CMD_FREE, &cmd_free) < 0)
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering log_unit_warning(UNIT(n), "Failed to free peeked message, ignoring: %m");
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering return r;
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic int busname_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering BusName *n = userdata;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(fd >= 0);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (n->state != BUSNAME_LISTENING)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return 0;
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering log_unit_debug(UNIT(n), "Activation request");
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering if (revents != EPOLLIN) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering log_unit_error(UNIT(n), "Got unexpected poll event (0x%x) on starter fd.", revents);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering goto fail;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering }
bd5f920f1288c0d4d488629fadf067f709227030Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering busname_peek_message(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering busname_enter_running(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return 0;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringfail:
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering busname_enter_dead(n, BUSNAME_FAILURE_RESOURCES);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return 0;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringstatic void busname_sigchld_event(Unit *u, pid_t pid, int code, int status) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering BusName *n = BUSNAME(u);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering BusNameResult f;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert(n);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert(pid >= 0);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (pid != n->control_pid)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering n->control_pid = 0;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (is_clean_exit(code, status, NULL))
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering f = BUSNAME_SUCCESS;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering else if (code == CLD_EXITED)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering f = BUSNAME_FAILURE_EXIT_CODE;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering else if (code == CLD_KILLED)
deffddf1df29a5ed047feff3a0f2b765006fb71bLukas Nykryn f = BUSNAME_FAILURE_SIGNAL;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering else if (code == CLD_DUMPED)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering f = BUSNAME_FAILURE_CORE_DUMP;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering else
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert_not_reached("Unknown sigchld code");
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering log_unit_full(u, f == BUSNAME_SUCCESS ? LOG_DEBUG : LOG_NOTICE, 0,
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering "Control process exited, code=%s status=%i", sigchld_code_to_string(code), status);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (f != BUSNAME_SUCCESS)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering n->result = f;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering switch (n->state) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering case BUSNAME_MAKING:
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (f == BUSNAME_SUCCESS)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering busname_enter_listening(n);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering else
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering busname_enter_signal(n, BUSNAME_SIGTERM, f);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering break;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering case BUSNAME_SIGTERM:
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering case BUSNAME_SIGKILL:
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering busname_enter_dead(n, f);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering break;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering default:
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert_not_reached("Uh, control process died at wrong time.");
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering }
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering /* Notify clients about changed exit status */
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering unit_add_to_dbus_queue(u);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering}
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringstatic int busname_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering BusName *n = BUSNAME(userdata);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert(n);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert(n->timer_event_source == source);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering switch (n->state) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering case BUSNAME_MAKING:
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering log_unit_warning(UNIT(n), "Making timed out. Terminating.");
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering busname_enter_signal(n, BUSNAME_SIGTERM, BUSNAME_FAILURE_TIMEOUT);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering break;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering case BUSNAME_SIGTERM:
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering log_unit_warning(UNIT(n), "Stopping timed out. Killing.");
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering busname_enter_signal(n, BUSNAME_SIGKILL, BUSNAME_FAILURE_TIMEOUT);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering break;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
f2341e0a87cab1558c84c933956e9181d5fb6c52Lennart Poettering case BUSNAME_SIGKILL:
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering log_unit_warning(UNIT(n), "Processes still around after SIGKILL. Ignoring.");
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering busname_enter_dead(n, BUSNAME_FAILURE_TIMEOUT);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering break;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering default:
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering assert_not_reached("Timeout at wrong time.");
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering }
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return 0;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic void busname_reset_failed(Unit *u) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering BusName *n = BUSNAME(u);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (n->state == BUSNAME_FAILED)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering busname_set_state(n, BUSNAME_DEAD);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering n->result = BUSNAME_SUCCESS;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic void busname_trigger_notify(Unit *u, Unit *other) {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering BusName *n = BUSNAME(u);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering Service *s;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering assert(other);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (!IN_SET(n->state, BUSNAME_RUNNING, BUSNAME_LISTENING))
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering if (other->load_state != UNIT_LOADED || other->type != UNIT_SERVICE)
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering return;
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering s = SERVICE(other);
2f671520ebade4877cbf6aca3572a5f8c4e1871dLennart Poettering
2f671520ebade4877cbf6aca3572a5f8c4e1871dLennart Poettering if (s->state == SERVICE_FAILED && s->result == SERVICE_FAILURE_START_LIMIT)
2f671520ebade4877cbf6aca3572a5f8c4e1871dLennart Poettering busname_enter_dead(n, BUSNAME_FAILURE_SERVICE_FAILED_PERMANENT);
2f671520ebade4877cbf6aca3572a5f8c4e1871dLennart Poettering else if (IN_SET(s->state,
2f671520ebade4877cbf6aca3572a5f8c4e1871dLennart Poettering SERVICE_DEAD, SERVICE_FAILED,
2f671520ebade4877cbf6aca3572a5f8c4e1871dLennart Poettering SERVICE_STOP, SERVICE_STOP_SIGTERM, SERVICE_STOP_SIGKILL,
2f671520ebade4877cbf6aca3572a5f8c4e1871dLennart Poettering SERVICE_STOP_POST, SERVICE_FINAL_SIGTERM, SERVICE_FINAL_SIGKILL,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering SERVICE_AUTO_RESTART))
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering busname_enter_listening(n);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering}
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringstatic int busname_kill(Unit *u, KillWho who, int signo, sd_bus_error *error) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return unit_kill_common(u, who, signo, -1, BUSNAME(u)->control_pid, error);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering}
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poetteringstatic int busname_get_timeout(Unit *u, uint64_t *timeout) {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering BusName *n = BUSNAME(u);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering int r;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (!n->timer_event_source)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return 0;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering r = sd_event_source_get_time(n->timer_event_source, timeout);
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering if (r < 0)
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return r;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering return 1;
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering}
1c2e9646e4a1720fc8ad35c705c195ae1a2c5ce0Lennart Poettering
d69a7ceaed77992105342a056fe68769c2e6d3bdJohannes Hölzlstatic bool busname_supported(void) {
0faacd470dfbd24f4c6504da6f04213aa05f9d19Lennart Poettering static int supported = -1;
0faacd470dfbd24f4c6504da6f04213aa05f9d19Lennart Poettering
d79acc309327f8c0863bd3da8b93d926a1c93ba1David Herrmann if (supported < 0)
0faacd470dfbd24f4c6504da6f04213aa05f9d19Lennart Poettering supported = is_kdbus_available();
0faacd470dfbd24f4c6504da6f04213aa05f9d19Lennart Poettering
0faacd470dfbd24f4c6504da6f04213aa05f9d19Lennart Poettering return supported;
0faacd470dfbd24f4c6504da6f04213aa05f9d19Lennart Poettering}
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic const char* const busname_state_table[_BUSNAME_STATE_MAX] = {
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering [BUSNAME_DEAD] = "dead",
5892a914d173e4b968d2a14fbf717373dee3999aDaniel Mack [BUSNAME_MAKING] = "making",
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering [BUSNAME_REGISTERED] = "registered",
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering [BUSNAME_LISTENING] = "listening",
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering [BUSNAME_RUNNING] = "running",
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering [BUSNAME_SIGTERM] = "sigterm",
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering [BUSNAME_SIGKILL] = "sigkill",
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering [BUSNAME_FAILED] = "failed",
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering};
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart PoetteringDEFINE_STRING_TABLE_LOOKUP(busname_state, BusNameState);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringstatic const char* const busname_result_table[_BUSNAME_RESULT_MAX] = {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering [BUSNAME_SUCCESS] = "success",
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering [BUSNAME_FAILURE_RESOURCES] = "resources",
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering [BUSNAME_FAILURE_TIMEOUT] = "timeout",
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering [BUSNAME_FAILURE_EXIT_CODE] = "exit-code",
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering [BUSNAME_FAILURE_SIGNAL] = "signal",
700ff4d97311902a440109a2c081731ab6ae8a20Lennart Poettering [BUSNAME_FAILURE_CORE_DUMP] = "core-dump",
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering [BUSNAME_FAILURE_SERVICE_FAILED_PERMANENT] = "service-failed-permanent",
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering};
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart PoetteringDEFINE_STRING_TABLE_LOOKUP(busname_result, BusNameResult);
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poetteringconst UnitVTable busname_vtable = {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering .object_size = sizeof(BusName),
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering .sections =
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering "Unit\0"
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering "BusName\0"
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering "Install\0",
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering .private_section = "BusName",
e05ad7bcc87f652cea321224f8eeb32e21d18e0cLennart Poettering
e05ad7bcc87f652cea321224f8eeb32e21d18e0cLennart Poettering .no_alias = true,
e05ad7bcc87f652cea321224f8eeb32e21d18e0cLennart Poettering .no_instances = true,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering .init = busname_init,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering .done = busname_done,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering .load = busname_load,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering .coldplug = busname_coldplug,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering .dump = busname_dump,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering .start = busname_start,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering .stop = busname_stop,
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering .kill = busname_kill,
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering .get_timeout = busname_get_timeout,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering .serialize = busname_serialize,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering .deserialize_item = busname_deserialize_item,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering .active_state = busname_active_state,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering .sub_state_to_string = busname_sub_state_to_string,
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering
a4152e3fe28b53b8919cc404dd7eca7ead1bf9bdLennart Poettering .sigchld_event = busname_sigchld_event,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering .trigger_notify = busname_trigger_notify,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering .reset_failed = busname_reset_failed,
0faacd470dfbd24f4c6504da6f04213aa05f9d19Lennart Poettering
0faacd470dfbd24f4c6504da6f04213aa05f9d19Lennart Poettering .supported = busname_supported,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering .bus_interface = "org.freedesktop.systemd1.BusName",
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering .bus_vtable = bus_busname_vtable,
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering .status_message_formats = {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering .finished_start_job = {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering [JOB_DONE] = "Listening on %s.",
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering [JOB_FAILED] = "Failed to listen on %s.",
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering [JOB_DEPENDENCY] = "Dependency failed for %s.",
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering [JOB_TIMEOUT] = "Timed out starting %s.",
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering },
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering .finished_stop_job = {
e821075a23fdfa3ca7738fc30bb2d4c430fe10c0Lennart Poettering [JOB_DONE] = "Closed %s.",
[JOB_FAILED] = "Failed stopping %s.",
[JOB_TIMEOUT] = "Timed out stopping %s.",
},
},
};