busname.c revision dcc2fc01fa850e9ee36c549dc2691e7e5c71bebf
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt This file is part of systemd.
7bd8e95d44977833d0de3fc4e893eb3bc84351d6Patrik Flykt Copyright 2013 Lennart Poettering
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt systemd is free software; you can redistribute it and/or modify it
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt under the terms of the GNU Lesser General Public License as published by
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt the Free Software Foundation; either version 2.1 of the License, or
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt (at your option) any later version.
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt systemd is distributed in the hope that it will be useful, but
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt WITHOUT ANY WARRANTY; without even the implied warranty of
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt Lesser General Public License for more details.
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt You should have received a copy of the GNU Lesser General Public License
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt along with systemd; If not, see <http://www.gnu.org/licenses/>.
f12abb48fc510b8b349c05e35ba048134debaf25Patrik Flyktstatic const UnitActiveState state_translation_table[_BUSNAME_STATE_MAX] = {
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flyktstatic int busname_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata);
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flyktstatic int busname_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata);
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt n->timeout_usec = u->manager->default_timeout_start_usec;
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flyktstatic void busname_unwatch_control_pid(BusName *n) {
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt while ((p = n->policy)) {
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt n->starter_event_source = sd_event_source_unref(n->starter_event_source);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt n->timer_event_source = sd_event_source_unref(n->timer_event_source);
3f0c075f8ef3344da5a6bda524540201f9204e61Patrik Flykt if (n->timeout_usec <= 0) {
3f0c075f8ef3344da5a6bda524540201f9204e61Patrik Flykt n->timer_event_source = sd_event_source_unref(n->timer_event_source);
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt r = sd_event_source_set_time(n->timer_event_source, now(CLOCK_MONOTONIC) + n->timeout_usec);
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt return sd_event_source_set_enabled(n->timer_event_source, SD_EVENT_ONESHOT);
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flyktstatic int busname_add_default_default_dependencies(BusName *n) {
76253e73f9c9c24fec755e485516f3b55d0707b4Dan Williams r = unit_add_dependency_by_name(UNIT(n), UNIT_BEFORE, SPECIAL_BUSNAMES_TARGET, NULL, true);
76253e73f9c9c24fec755e485516f3b55d0707b4Dan Williams if (UNIT(n)->manager->running_as == SYSTEMD_SYSTEM) {
76253e73f9c9c24fec755e485516f3b55d0707b4Dan Williams r = unit_add_two_dependencies_by_name(UNIT(n), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SYSINIT_TARGET, NULL, true);
76253e73f9c9c24fec755e485516f3b55d0707b4Dan Williams return unit_add_two_dependencies_by_name(UNIT(n), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true);
fe4b2156256c5bdf52341576571ce9f095d9f085Tom Gundersen r = unit_add_two_dependencies(u, UNIT_BEFORE, UNIT_TRIGGERS, UNIT_DEREF(n->service), true);
fe4b2156256c5bdf52341576571ce9f095d9f085Tom Gundersen r = busname_add_default_default_dependencies(n);
66eac1201a9c1596f5901f8dbbf24bda7e350878Dan Williams log_error_unit(UNIT(n)->id, "%s's Name= setting is not a valid service name Refusing.", UNIT(n)->id);
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt log_error_unit(UNIT(n)->id, "%s's Name= setting doesn't match unit name. Refusing.", UNIT(n)->id);
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt /* This is a new unit? Then let's add in some extras */
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flyktstatic void busname_dump(Unit *u, FILE *f, const char *prefix) {
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt "%sBus Name State: %s\n"
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt "%sResult: %s\n"
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt "%sName: %s\n"
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt "%sActivating: %s\n"
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt "%sAccept FD: %s\n",
3f0c075f8ef3344da5a6bda524540201f9204e61Patrik Flykt r = sd_event_source_set_enabled(n->starter_event_source, SD_EVENT_OFF);
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt log_debug_unit(UNIT(n)->id, "Failed to disable event source.");
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt r = sd_event_source_set_enabled(n->starter_event_source, SD_EVENT_ON);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt r = sd_event_add_io(UNIT(n)->manager->event, &n->starter_event_source, n->starter_fd, EPOLLIN, busname_dispatch_io, n);
c3e2adeaba8e043caed0ef139eeaea016bd152d0Patrik Flykt if (r < 0) {
346e13a25dc6f76d3bc9d8decd40dc4782b02d2aPatrik Flykt log_warning_unit(UNIT(n)->id, "Failed to watch starter fd: %s", strerror(-r));
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt const char *mode;
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt mode = UNIT(n)->manager->running_as == SYSTEMD_SYSTEM ? "system" : "user";
3f0c075f8ef3344da5a6bda524540201f9204e61Patrik Flykt n->starter_fd = bus_kernel_open_bus_fd(mode, &path);
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt log_warning_unit(UNIT(n)->id, "Failed to open %s: %s", path ?: "kdbus", strerror(-n->starter_fd));
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flyktstatic void busname_set_state(BusName *n, BusNameState state) {
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt if (!IN_SET(state, BUSNAME_MAKING, BUSNAME_SIGTERM, BUSNAME_SIGKILL)) {
346e13a25dc6f76d3bc9d8decd40dc4782b02d2aPatrik Flykt n->timer_event_source = sd_event_source_unref(n->timer_event_source);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt if (!IN_SET(state, BUSNAME_LISTENING, BUSNAME_MAKING, BUSNAME_REGISTERED, BUSNAME_RUNNING))
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt log_debug_unit(UNIT(n)->id, "%s changed %s -> %s",
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt UNIT(n)->id, busname_state_to_string(old_state), busname_state_to_string(state));
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt unit_notify(UNIT(n), state_translation_table[old_state], state_translation_table[state], true);
926695f1b5f9395eeb416cc2f478a9cf75fdbeb4Thomas Hindoe Paaboel Andersen if (n->deserialized_state == n->state)
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt if (IN_SET(n->deserialized_state, BUSNAME_MAKING, BUSNAME_SIGTERM, BUSNAME_SIGKILL)) {
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt if (IN_SET(n->deserialized_state, BUSNAME_MAKING, BUSNAME_LISTENING, BUSNAME_REGISTERED, BUSNAME_RUNNING)) {
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt if (n->deserialized_state == BUSNAME_LISTENING) {
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flyktstatic int busname_make_starter(BusName *n, pid_t *_pid) {
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt /* We have to resolve the user/group names out-of-process,
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt * hence let's fork here. It's messy, but well, what can we
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt default_signals(SIGNALS_CRASH_HANDLER, SIGNALS_IGNORE, -1);
346e13a25dc6f76d3bc9d8decd40dc4782b02d2aPatrik Flykt r = bus_kernel_make_starter(n->starter_fd, n->name, n->activating, n->accept_fd, n->policy, n->policy_world);
346e13a25dc6f76d3bc9d8decd40dc4782b02d2aPatrik Flykt if (r < 0) {
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt log_error("Failed to create starter connection at step %s: %s", exit_status_to_string(ret, EXIT_STATUS_SYSTEMD), strerror(-r));
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt n->timer_event_source = sd_event_source_unref(n->timer_event_source);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flyktstatic void busname_enter_dead(BusName *n, BusNameResult f) {
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt busname_set_state(n, n->result != BUSNAME_SUCCESS ? BUSNAME_FAILED : BUSNAME_DEAD);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flyktstatic void busname_enter_signal(BusName *n, BusNameState state, BusNameResult f) {
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt state != BUSNAME_SIGTERM ? KILL_KILL : KILL_TERMINATE,
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt if (r < 0) {
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt log_warning_unit(UNIT(n)->id, "%s failed to kill control process: %s", UNIT(n)->id, strerror(-r));
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt if (r > 0) {
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt if (r < 0) {
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt log_warning_unit(UNIT(n)->id, "%s failed to arm timer: %s", UNIT(n)->id, strerror(-r));
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt busname_enter_signal(n, BUSNAME_SIGKILL, BUSNAME_SUCCESS);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt busname_enter_dead(n, BUSNAME_FAILURE_RESOURCES);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flyktstatic void busname_enter_listening(BusName *n) {
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt if (r < 0) {
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt log_warning_unit(UNIT(n)->id, "%s failed to watch names: %s", UNIT(n)->id, strerror(-r));
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt busname_enter_signal(n, BUSNAME_SIGTERM, BUSNAME_FAILURE_RESOURCES);
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt /* If there is a policy, we need to resolve user/group
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt * names, which we can't do from PID1, hence let's
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt if (r < 0) {
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt log_warning_unit(UNIT(n)->id, "%s failed to fork 'making' task: %s", UNIT(n)->id, strerror(-r));
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt /* If there is no policy, we can do everything
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt * directly from PID 1, hence do so. */
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt r = bus_kernel_make_starter(n->starter_fd, n->name, n->activating, n->accept_fd, NULL, n->policy_world);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt if (r < 0) {
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt log_warning_unit(UNIT(n)->id, "%s failed to make starter: %s", UNIT(n)->id, strerror(-r));
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt busname_enter_dead(n, BUSNAME_FAILURE_RESOURCES);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt bool pending = false;
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt /* We don't take conenctions anymore if we are supposed to
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt * shut down anyway */
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt log_debug_unit(UNIT(n)->id, "Suppressing activation request on %s since unit stop is scheduled.", UNIT(n)->id);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt /* Flush all queued activation reqeuest by closing and reopening the connection */
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt /* If there's already a start pending don't bother to do
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt * anything */
346e13a25dc6f76d3bc9d8decd40dc4782b02d2aPatrik Flykt SET_FOREACH(other, UNIT(n)->dependencies[UNIT_TRIGGERS], i)
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt r = manager_add_job(UNIT(n)->manager, JOB_START, UNIT_DEREF(n->service), JOB_REPLACE, true, &error, NULL);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt log_warning_unit(UNIT(n)->id, "%s failed to queue service startup job: %s", UNIT(n)->id, bus_error_message(&error, r));
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt busname_enter_dead(n, BUSNAME_FAILURE_RESOURCES);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt /* We cannot fulfill this request right now, try again later
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt * please! */
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt if (IN_SET(n->state, BUSNAME_SIGTERM, BUSNAME_SIGKILL))
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt /* Already on it! */
9021bb9f935c93b516b10c88db2a212a9e3a8140Tom Gundersen if (UNIT(service)->load_state != UNIT_LOADED) {
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt log_error_unit(u->id, "Bus service %s not loaded, refusing.", UNIT(service)->id);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert(IN_SET(n->state, BUSNAME_DEAD, BUSNAME_FAILED));
9021bb9f935c93b516b10c88db2a212a9e3a8140Tom Gundersen /* Already on it */
356779df90a2ecab5da2cb310ad0f8ebc9ca9f46Lennart Poettering if (IN_SET(n->state, BUSNAME_SIGTERM, BUSNAME_SIGKILL))
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt /* If there's already something running, we go directly into
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt * kill mode. */
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt busname_enter_signal(n, BUSNAME_SIGTERM, BUSNAME_SUCCESS);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert(IN_SET(n->state, BUSNAME_REGISTERED, BUSNAME_LISTENING, BUSNAME_RUNNING));
f12abb48fc510b8b349c05e35ba048134debaf25Patrik Flyktstatic int busname_serialize(Unit *u, FILE *f, FDSet *fds) {
f12abb48fc510b8b349c05e35ba048134debaf25Patrik Flykt unit_serialize_item(u, f, "state", busname_state_to_string(n->state));
f12abb48fc510b8b349c05e35ba048134debaf25Patrik Flykt unit_serialize_item(u, f, "result", busname_result_to_string(n->result));
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt unit_serialize_item_format(u, f, "control-pid", PID_FMT, n->control_pid);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt if (n->starter_fd >= 0) {
44481a8b537839cd9ffead4d261491641f5b5260Zbigniew Jędrzejewski-Szmek unit_serialize_item_format(u, f, "starter-fd", "%i", copy);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flyktstatic int busname_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) {
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt log_debug_unit(u->id, "Failed to parse state value %s", value);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt log_debug_unit(u->id, "Failed to parse result value %s", value);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt log_debug_unit(u->id, "Failed to parse control-pid value %s", value);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt if (safe_atoi(value, &fd) < 0 || fd < 0 || !fdset_contains(fds, fd))
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt log_debug_unit(u->id, "Failed to parse starter fd value %s", value);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt log_debug_unit(u->id, "Unknown serialization key '%s'", key);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt_pure_ static UnitActiveState busname_active_state(Unit *u) {
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt return state_translation_table[BUSNAME(u)->state];
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt_pure_ static const char *busname_sub_state_to_string(Unit *u) {
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt return busname_state_to_string(BUSNAME(u)->state);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt /* Generate a friendly debug log message about which process
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt * caused triggering of this bus name. This simply peeks the
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt * metadata of the first queued message and logs it. */
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt /* Let's shortcut things a bit, if debug logging is turned off
ed6ee21953dac9c78383da00bc4514ece6b75ab5Patrik Flykt * anyway. */
ed6ee21953dac9c78383da00bc4514ece6b75ab5Patrik Flykt r = ioctl(n->starter_fd, KDBUS_CMD_MSG_RECV, &cmd_recv);
ed6ee21953dac9c78383da00bc4514ece6b75ab5Patrik Flykt if (r < 0) {
7bd8e95d44977833d0de3fc4e893eb3bc84351d6Patrik Flykt log_error_unit(UNIT(n)->id, "%s: Failed to query activation message: %m", UNIT(n)->id);
5da1b97f3c3d15521f2dcfbc18eccd6580122ebcPatrik Flykt /* We map as late as possible, and unmap imemdiately after
5da1b97f3c3d15521f2dcfbc18eccd6580122ebcPatrik Flykt * use. On 32bit address space is scarce and we want to be
5da1b97f3c3d15521f2dcfbc18eccd6580122ebcPatrik Flykt * able to handle a lot of activator connections at the same
5da1b97f3c3d15521f2dcfbc18eccd6580122ebcPatrik Flykt * time, and hence shouldn't keep the mmap()s around for
5da1b97f3c3d15521f2dcfbc18eccd6580122ebcPatrik Flykt * longer than necessary. */
6599680e2d33597f0f11a99e1c3c957b42418568Patrik Flykt p = mmap(NULL, sz, PROT_READ, MAP_SHARED, n->starter_fd, start);
6599680e2d33597f0f11a99e1c3c957b42418568Patrik Flykt log_error_unit(UNIT(n)->id, "%s: Failed to map activation message: %m", UNIT(n)->id);
41e4615d4f4f5c61afa84ba857f23c0ac496687bPatrik Flykt k = (struct kdbus_msg *) ((uint8_t *) p + delta);
41e4615d4f4f5c61afa84ba857f23c0ac496687bPatrik Flykt switch (d->type) {
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt log_debug_unit(UNIT(n)->id, "%s: Activation triggered by process " PID_FMT " (%s)", UNIT(n)->id, pid, strna(comm));
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt if (ioctl(n->starter_fd, KDBUS_CMD_FREE, &cmd_free) < 0)
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt log_warning_unit(UNIT(n)->id, "Failed to free peeked message, ignoring: %m");
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flyktstatic int busname_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt log_debug_unit(UNIT(n)->id, "Activation request on %s", UNIT(n)->id);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt log_error_unit(UNIT(n)->id, "%s: Got unexpected poll event (0x%x) on starter fd.",
ed6ee21953dac9c78383da00bc4514ece6b75ab5Patrik Flykt busname_enter_dead(n, BUSNAME_FAILURE_RESOURCES);
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flyktstatic void busname_sigchld_event(Unit *u, pid_t pid, int code, int status) {
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt log_full_unit(f == BUSNAME_SUCCESS ? LOG_DEBUG : LOG_NOTICE,
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt u->id, "%s control process exited, code=%s status=%i",
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt switch (n->state) {
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt assert_not_reached("Uh, control process died at wrong time.");
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt /* Notify clients about changed exit status */
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flyktstatic int busname_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata) {
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt switch (n->state) {
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt log_warning_unit(UNIT(n)->id, "%s making timed out. Terminating.", UNIT(n)->id);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt busname_enter_signal(n, BUSNAME_SIGTERM, BUSNAME_FAILURE_TIMEOUT);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt log_warning_unit(UNIT(n)->id, "%s stopping timed out. Killing.", UNIT(n)->id);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt busname_enter_signal(n, BUSNAME_SIGKILL, BUSNAME_FAILURE_TIMEOUT);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt log_warning_unit(UNIT(n)->id, "%s still around after SIGKILL. Ignoring.", UNIT(n)->id);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt busname_enter_dead(n, BUSNAME_FAILURE_TIMEOUT);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flyktstatic void busname_trigger_notify(Unit *u, Unit *other) {
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt if (!IN_SET(n->state, BUSNAME_RUNNING, BUSNAME_LISTENING))
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt if (other->load_state != UNIT_LOADED || other->type != UNIT_SERVICE)
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt if (s->state == SERVICE_FAILED && s->result == SERVICE_FAILURE_START_LIMIT)
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt busname_enter_dead(n, BUSNAME_FAILURE_SERVICE_FAILED_PERMANENT);
ed6ee21953dac9c78383da00bc4514ece6b75ab5Patrik Flykt SERVICE_STOP, SERVICE_STOP_SIGTERM, SERVICE_STOP_SIGKILL,
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt SERVICE_STOP_POST, SERVICE_FINAL_SIGTERM, SERVICE_FINAL_SIGKILL,
ed6ee21953dac9c78383da00bc4514ece6b75ab5Patrik Flyktstatic int busname_kill(Unit *u, KillWho who, int signo, sd_bus_error *error) {
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt return unit_kill_common(u, who, signo, -1, BUSNAME(u)->control_pid, error);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flyktstatic int busname_get_timeout(Unit *u, uint64_t *timeout) {
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt r = sd_event_source_get_time(n->timer_event_source, timeout);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flyktstatic const char* const busname_state_table[_BUSNAME_STATE_MAX] = {
631bbe71298ec892f77f44f94feb612646fe6853Patrik FlyktDEFINE_STRING_TABLE_LOOKUP(busname_state, BusNameState);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flyktstatic const char* const busname_result_table[_BUSNAME_RESULT_MAX] = {
c3e2adeaba8e043caed0ef139eeaea016bd152d0Patrik Flykt [BUSNAME_FAILURE_SERVICE_FAILED_PERMANENT] = "service-failed-permanent",
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik FlyktDEFINE_STRING_TABLE_LOOKUP(busname_result, BusNameResult);
c3e2adeaba8e043caed0ef139eeaea016bd152d0Patrik Flykt "Install\0",
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt .sub_state_to_string = busname_sub_state_to_string,
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt .bus_interface = "org.freedesktop.systemd1.BusName",
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt [JOB_DEPENDENCY] = "Dependency failed for %s.",