1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2013 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 #include "bus-internal.h"
25 #include "bus-kernel.h"
26 #include "bus-policy.h"
29 #include "dbus-busname.h"
31 #include "formats-util.h"
33 #include "parse-util.h"
35 #include "signal-util.h"
37 #include "string-util.h"
39 static const UnitActiveState state_translation_table
[_BUSNAME_STATE_MAX
] = {
40 [BUSNAME_DEAD
] = UNIT_INACTIVE
,
41 [BUSNAME_MAKING
] = UNIT_ACTIVATING
,
42 [BUSNAME_REGISTERED
] = UNIT_ACTIVE
,
43 [BUSNAME_LISTENING
] = UNIT_ACTIVE
,
44 [BUSNAME_RUNNING
] = UNIT_ACTIVE
,
45 [BUSNAME_SIGTERM
] = UNIT_DEACTIVATING
,
46 [BUSNAME_SIGKILL
] = UNIT_DEACTIVATING
,
47 [BUSNAME_FAILED
] = UNIT_FAILED
50 static int busname_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
);
51 static int busname_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
);
53 static void busname_init(Unit
*u
) {
54 BusName
*n
= BUSNAME(u
);
57 assert(u
->load_state
== UNIT_STUB
);
63 n
->timeout_usec
= u
->manager
->default_timeout_start_usec
;
66 static void busname_unwatch_control_pid(BusName
*n
) {
69 if (n
->control_pid
<= 0)
72 unit_unwatch_pid(UNIT(n
), n
->control_pid
);
76 static void busname_free_policy(BusName
*n
) {
81 while ((p
= n
->policy
)) {
82 LIST_REMOVE(policy
, n
->policy
, p
);
89 static void busname_close_fd(BusName
*n
) {
92 n
->starter_event_source
= sd_event_source_unref(n
->starter_event_source
);
93 n
->starter_fd
= safe_close(n
->starter_fd
);
96 static void busname_done(Unit
*u
) {
97 BusName
*n
= BUSNAME(u
);
101 n
->name
= mfree(n
->name
);
103 busname_free_policy(n
);
104 busname_unwatch_control_pid(n
);
107 unit_ref_unset(&n
->service
);
109 n
->timer_event_source
= sd_event_source_unref(n
->timer_event_source
);
112 static int busname_arm_timer(BusName
*n
) {
117 if (n
->timeout_usec
<= 0) {
118 n
->timer_event_source
= sd_event_source_unref(n
->timer_event_source
);
122 if (n
->timer_event_source
) {
123 r
= sd_event_source_set_time(n
->timer_event_source
, now(CLOCK_MONOTONIC
) + n
->timeout_usec
);
127 return sd_event_source_set_enabled(n
->timer_event_source
, SD_EVENT_ONESHOT
);
130 r
= sd_event_add_time(
131 UNIT(n
)->manager
->event
,
132 &n
->timer_event_source
,
134 now(CLOCK_MONOTONIC
) + n
->timeout_usec
, 0,
135 busname_dispatch_timer
, n
);
139 (void) sd_event_source_set_description(n
->timer_event_source
, "busname-timer");
144 static int busname_add_default_default_dependencies(BusName
*n
) {
149 r
= unit_add_dependency_by_name(UNIT(n
), UNIT_BEFORE
, SPECIAL_BUSNAMES_TARGET
, NULL
, true);
153 if (UNIT(n
)->manager
->running_as
== MANAGER_SYSTEM
) {
154 r
= unit_add_two_dependencies_by_name(UNIT(n
), UNIT_AFTER
, UNIT_REQUIRES
, SPECIAL_SYSINIT_TARGET
, NULL
, true);
159 return unit_add_two_dependencies_by_name(UNIT(n
), UNIT_BEFORE
, UNIT_CONFLICTS
, SPECIAL_SHUTDOWN_TARGET
, NULL
, true);
162 static int busname_add_extras(BusName
*n
) {
169 r
= unit_name_to_prefix(u
->id
, &n
->name
);
174 if (!u
->description
) {
175 r
= unit_set_description(u
, n
->name
);
181 if (!UNIT_DEREF(n
->service
)) {
184 r
= unit_load_related_unit(u
, ".service", &x
);
188 unit_ref_set(&n
->service
, x
);
191 r
= unit_add_two_dependencies(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, UNIT_DEREF(n
->service
), true);
196 if (u
->default_dependencies
) {
197 r
= busname_add_default_default_dependencies(n
);
205 static int busname_verify(BusName
*n
) {
210 if (UNIT(n
)->load_state
!= UNIT_LOADED
)
213 if (!service_name_is_valid(n
->name
)) {
214 log_unit_error(UNIT(n
), "Name= setting is not a valid service name Refusing.");
218 e
= strjoina(n
->name
, ".busname");
219 if (!unit_has_name(UNIT(n
), e
)) {
220 log_unit_error(UNIT(n
), "Name= setting doesn't match unit name. Refusing.");
227 static int busname_load(Unit
*u
) {
228 BusName
*n
= BUSNAME(u
);
232 assert(u
->load_state
== UNIT_STUB
);
234 r
= unit_load_fragment_and_dropin(u
);
238 if (u
->load_state
== UNIT_LOADED
) {
239 /* This is a new unit? Then let's add in some extras */
240 r
= busname_add_extras(n
);
245 return busname_verify(n
);
248 static void busname_dump(Unit
*u
, FILE *f
, const char *prefix
) {
249 BusName
*n
= BUSNAME(u
);
255 "%sBus Name State: %s\n"
260 prefix
, busname_state_to_string(n
->state
),
261 prefix
, busname_result_to_string(n
->result
),
263 prefix
, yes_no(n
->activating
),
264 prefix
, yes_no(n
->accept_fd
));
266 if (n
->control_pid
> 0)
268 "%sControl PID: "PID_FMT
"\n",
269 prefix
, n
->control_pid
);
272 static void busname_unwatch_fd(BusName
*n
) {
277 if (!n
->starter_event_source
)
280 r
= sd_event_source_set_enabled(n
->starter_event_source
, SD_EVENT_OFF
);
282 log_unit_debug_errno(UNIT(n
), r
, "Failed to disable event source: %m");
285 static int busname_watch_fd(BusName
*n
) {
290 if (n
->starter_fd
< 0)
293 if (n
->starter_event_source
) {
294 r
= sd_event_source_set_enabled(n
->starter_event_source
, SD_EVENT_ON
);
298 r
= sd_event_add_io(UNIT(n
)->manager
->event
, &n
->starter_event_source
, n
->starter_fd
, EPOLLIN
, busname_dispatch_io
, n
);
302 (void) sd_event_source_set_description(n
->starter_event_source
, "busname-starter");
308 log_unit_warning_errno(UNIT(n
), r
, "Failed to watch starter fd: %m");
309 busname_unwatch_fd(n
);
313 static int busname_open_fd(BusName
*n
) {
314 _cleanup_free_
char *path
= NULL
;
319 if (n
->starter_fd
>= 0)
322 mode
= UNIT(n
)->manager
->running_as
== MANAGER_SYSTEM
? "system" : "user";
323 n
->starter_fd
= bus_kernel_open_bus_fd(mode
, &path
);
324 if (n
->starter_fd
< 0)
325 return log_unit_warning_errno(UNIT(n
), n
->starter_fd
, "Failed to open %s: %m", path
?: "kdbus");
330 static void busname_set_state(BusName
*n
, BusNameState state
) {
331 BusNameState old_state
;
334 old_state
= n
->state
;
337 if (!IN_SET(state
, BUSNAME_MAKING
, BUSNAME_SIGTERM
, BUSNAME_SIGKILL
)) {
338 n
->timer_event_source
= sd_event_source_unref(n
->timer_event_source
);
339 busname_unwatch_control_pid(n
);
342 if (state
!= BUSNAME_LISTENING
)
343 busname_unwatch_fd(n
);
345 if (!IN_SET(state
, BUSNAME_LISTENING
, BUSNAME_MAKING
, BUSNAME_REGISTERED
, BUSNAME_RUNNING
))
348 if (state
!= old_state
)
349 log_unit_debug(UNIT(n
), "Changed %s -> %s", busname_state_to_string(old_state
), busname_state_to_string(state
));
351 unit_notify(UNIT(n
), state_translation_table
[old_state
], state_translation_table
[state
], true);
354 static int busname_coldplug(Unit
*u
) {
355 BusName
*n
= BUSNAME(u
);
359 assert(n
->state
== BUSNAME_DEAD
);
361 if (n
->deserialized_state
== n
->state
)
364 if (IN_SET(n
->deserialized_state
, BUSNAME_MAKING
, BUSNAME_SIGTERM
, BUSNAME_SIGKILL
)) {
366 if (n
->control_pid
<= 0)
369 r
= unit_watch_pid(UNIT(n
), n
->control_pid
);
373 r
= busname_arm_timer(n
);
378 if (IN_SET(n
->deserialized_state
, BUSNAME_MAKING
, BUSNAME_LISTENING
, BUSNAME_REGISTERED
, BUSNAME_RUNNING
)) {
379 r
= busname_open_fd(n
);
384 if (n
->deserialized_state
== BUSNAME_LISTENING
) {
385 r
= busname_watch_fd(n
);
390 busname_set_state(n
, n
->deserialized_state
);
394 static int busname_make_starter(BusName
*n
, pid_t
*_pid
) {
398 r
= busname_arm_timer(n
);
402 /* We have to resolve the user/group names out-of-process,
403 * hence let's fork here. It's messy, but well, what can we
413 (void) default_signals(SIGNALS_CRASH_HANDLER
, SIGNALS_IGNORE
, -1);
414 (void) ignore_signals(SIGPIPE
, -1);
417 r
= bus_kernel_make_starter(n
->starter_fd
, n
->name
, n
->activating
, n
->accept_fd
, n
->policy
, n
->policy_world
);
419 ret
= EXIT_MAKE_STARTER
;
427 log_error_errno(r
, "Failed to create starter connection at step %s: %m", exit_status_to_string(ret
, EXIT_STATUS_SYSTEMD
));
432 r
= unit_watch_pid(UNIT(n
), pid
);
440 n
->timer_event_source
= sd_event_source_unref(n
->timer_event_source
);
444 static void busname_enter_dead(BusName
*n
, BusNameResult f
) {
447 if (f
!= BUSNAME_SUCCESS
)
450 busname_set_state(n
, n
->result
!= BUSNAME_SUCCESS
? BUSNAME_FAILED
: BUSNAME_DEAD
);
453 static void busname_enter_signal(BusName
*n
, BusNameState state
, BusNameResult f
) {
454 KillContext kill_context
= {};
459 if (f
!= BUSNAME_SUCCESS
)
462 kill_context_init(&kill_context
);
464 r
= unit_kill_context(UNIT(n
),
466 state
!= BUSNAME_SIGTERM
? KILL_KILL
: KILL_TERMINATE
,
471 log_unit_warning_errno(UNIT(n
), r
, "Failed to kill control process: %m");
476 r
= busname_arm_timer(n
);
478 log_unit_warning_errno(UNIT(n
), r
, "Failed to arm timer: %m");
482 busname_set_state(n
, state
);
483 } else if (state
== BUSNAME_SIGTERM
)
484 busname_enter_signal(n
, BUSNAME_SIGKILL
, BUSNAME_SUCCESS
);
486 busname_enter_dead(n
, BUSNAME_SUCCESS
);
491 busname_enter_dead(n
, BUSNAME_FAILURE_RESOURCES
);
494 static void busname_enter_listening(BusName
*n
) {
500 r
= busname_watch_fd(n
);
502 log_unit_warning_errno(UNIT(n
), r
, "Failed to watch names: %m");
506 busname_set_state(n
, BUSNAME_LISTENING
);
508 busname_set_state(n
, BUSNAME_REGISTERED
);
513 busname_enter_signal(n
, BUSNAME_SIGTERM
, BUSNAME_FAILURE_RESOURCES
);
516 static void busname_enter_making(BusName
*n
) {
521 r
= busname_open_fd(n
);
526 /* If there is a policy, we need to resolve user/group
527 * names, which we can't do from PID1, hence let's
529 busname_unwatch_control_pid(n
);
531 r
= busname_make_starter(n
, &n
->control_pid
);
533 log_unit_warning_errno(UNIT(n
), r
, "Failed to fork 'making' task: %m");
537 busname_set_state(n
, BUSNAME_MAKING
);
539 /* If there is no policy, we can do everything
540 * directly from PID 1, hence do so. */
542 r
= bus_kernel_make_starter(n
->starter_fd
, n
->name
, n
->activating
, n
->accept_fd
, NULL
, n
->policy_world
);
544 log_unit_warning_errno(UNIT(n
), r
, "Failed to make starter: %m");
548 busname_enter_listening(n
);
554 busname_enter_dead(n
, BUSNAME_FAILURE_RESOURCES
);
557 static void busname_enter_running(BusName
*n
) {
558 _cleanup_bus_error_free_ sd_bus_error error
= SD_BUS_ERROR_NULL
;
559 bool pending
= false;
569 /* We don't take connections anymore if we are supposed to
570 * shut down anyway */
572 if (unit_stop_pending(UNIT(n
))) {
573 log_unit_debug(UNIT(n
), "Suppressing activation request since unit stop is scheduled.");
575 /* Flush all queued activation reqeuest by closing and reopening the connection */
576 bus_kernel_drop_one(n
->starter_fd
);
578 busname_enter_listening(n
);
582 /* If there's already a start pending don't bother to do
584 SET_FOREACH(other
, UNIT(n
)->dependencies
[UNIT_TRIGGERS
], i
)
585 if (unit_active_or_pending(other
)) {
591 if (!UNIT_ISSET(n
->service
)) {
592 log_unit_error(UNIT(n
), "Service to activate vanished, refusing activation.");
597 r
= manager_add_job(UNIT(n
)->manager
, JOB_START
, UNIT_DEREF(n
->service
), JOB_REPLACE
, true, &error
, NULL
);
602 busname_set_state(n
, BUSNAME_RUNNING
);
606 log_unit_warning(UNIT(n
), "Failed to queue service startup job: %s", bus_error_message(&error
, r
));
607 busname_enter_dead(n
, BUSNAME_FAILURE_RESOURCES
);
610 static int busname_start(Unit
*u
) {
611 BusName
*n
= BUSNAME(u
);
615 /* We cannot fulfill this request right now, try again later
617 if (IN_SET(n
->state
, BUSNAME_SIGTERM
, BUSNAME_SIGKILL
))
621 if (n
->state
== BUSNAME_MAKING
)
624 if (n
->activating
&& UNIT_ISSET(n
->service
)) {
627 service
= SERVICE(UNIT_DEREF(n
->service
));
629 if (UNIT(service
)->load_state
!= UNIT_LOADED
) {
630 log_unit_error(u
, "Bus service %s not loaded, refusing.", UNIT(service
)->id
);
635 assert(IN_SET(n
->state
, BUSNAME_DEAD
, BUSNAME_FAILED
));
637 n
->result
= BUSNAME_SUCCESS
;
638 busname_enter_making(n
);
643 static int busname_stop(Unit
*u
) {
644 BusName
*n
= BUSNAME(u
);
649 if (IN_SET(n
->state
, BUSNAME_SIGTERM
, BUSNAME_SIGKILL
))
652 /* If there's already something running, we go directly into
655 if (n
->state
== BUSNAME_MAKING
) {
656 busname_enter_signal(n
, BUSNAME_SIGTERM
, BUSNAME_SUCCESS
);
660 assert(IN_SET(n
->state
, BUSNAME_REGISTERED
, BUSNAME_LISTENING
, BUSNAME_RUNNING
));
662 busname_enter_dead(n
, BUSNAME_SUCCESS
);
666 static int busname_serialize(Unit
*u
, FILE *f
, FDSet
*fds
) {
667 BusName
*n
= BUSNAME(u
);
674 unit_serialize_item(u
, f
, "state", busname_state_to_string(n
->state
));
675 unit_serialize_item(u
, f
, "result", busname_result_to_string(n
->result
));
677 if (n
->control_pid
> 0)
678 unit_serialize_item_format(u
, f
, "control-pid", PID_FMT
, n
->control_pid
);
680 r
= unit_serialize_item_fd(u
, f
, fds
, "starter-fd", n
->starter_fd
);
687 static int busname_deserialize_item(Unit
*u
, const char *key
, const char *value
, FDSet
*fds
) {
688 BusName
*n
= BUSNAME(u
);
694 if (streq(key
, "state")) {
697 state
= busname_state_from_string(value
);
699 log_unit_debug(u
, "Failed to parse state value: %s", value
);
701 n
->deserialized_state
= state
;
703 } else if (streq(key
, "result")) {
706 f
= busname_result_from_string(value
);
708 log_unit_debug(u
, "Failed to parse result value: %s", value
);
709 else if (f
!= BUSNAME_SUCCESS
)
712 } else if (streq(key
, "control-pid")) {
715 if (parse_pid(value
, &pid
) < 0)
716 log_unit_debug(u
, "Failed to parse control-pid value: %s", value
);
718 n
->control_pid
= pid
;
719 } else if (streq(key
, "starter-fd")) {
722 if (safe_atoi(value
, &fd
) < 0 || fd
< 0 || !fdset_contains(fds
, fd
))
723 log_unit_debug(u
, "Failed to parse starter fd value: %s", value
);
725 safe_close(n
->starter_fd
);
726 n
->starter_fd
= fdset_remove(fds
, fd
);
729 log_unit_debug(u
, "Unknown serialization key: %s", key
);
734 _pure_
static UnitActiveState
busname_active_state(Unit
*u
) {
737 return state_translation_table
[BUSNAME(u
)->state
];
740 _pure_
static const char *busname_sub_state_to_string(Unit
*u
) {
743 return busname_state_to_string(BUSNAME(u
)->state
);
746 static int busname_peek_message(BusName
*n
) {
747 struct kdbus_cmd_recv cmd_recv
= {
748 .size
= sizeof(cmd_recv
),
749 .flags
= KDBUS_RECV_PEEK
,
751 struct kdbus_cmd_free cmd_free
= {
752 .size
= sizeof(cmd_free
),
754 const char *comm
= NULL
;
755 struct kdbus_item
*d
;
757 size_t start
, ps
, sz
, delta
;
762 /* Generate a friendly debug log message about which process
763 * caused triggering of this bus name. This simply peeks the
764 * metadata of the first queued message and logs it. */
768 /* Let's shortcut things a bit, if debug logging is turned off
771 if (log_get_max_level() < LOG_DEBUG
)
774 r
= ioctl(n
->starter_fd
, KDBUS_CMD_RECV
, &cmd_recv
);
776 if (errno
== EINTR
|| errno
== EAGAIN
)
779 return log_unit_error_errno(UNIT(n
), errno
, "Failed to query activation message: %m");
782 /* We map as late as possible, and unmap imemdiately after
783 * use. On 32bit address space is scarce and we want to be
784 * able to handle a lot of activator connections at the same
785 * time, and hence shouldn't keep the mmap()s around for
786 * longer than necessary. */
789 start
= (cmd_recv
.msg
.offset
/ ps
) * ps
;
790 delta
= cmd_recv
.msg
.offset
- start
;
791 sz
= PAGE_ALIGN(delta
+ cmd_recv
.msg
.msg_size
);
793 p
= mmap(NULL
, sz
, PROT_READ
, MAP_SHARED
, n
->starter_fd
, start
);
794 if (p
== MAP_FAILED
) {
795 r
= log_unit_error_errno(UNIT(n
), errno
, "Failed to map activation message: %m");
799 k
= (struct kdbus_msg
*) ((uint8_t *) p
+ delta
);
800 KDBUS_ITEM_FOREACH(d
, k
, items
) {
803 case KDBUS_ITEM_PIDS
:
807 case KDBUS_ITEM_PID_COMM
:
814 log_unit_debug(UNIT(n
), "Activation triggered by process " PID_FMT
" (%s)", pid
, strna(comm
));
820 (void) munmap(p
, sz
);
822 cmd_free
.offset
= cmd_recv
.msg
.offset
;
823 if (ioctl(n
->starter_fd
, KDBUS_CMD_FREE
, &cmd_free
) < 0)
824 log_unit_warning(UNIT(n
), "Failed to free peeked message, ignoring: %m");
829 static int busname_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
) {
830 BusName
*n
= userdata
;
835 if (n
->state
!= BUSNAME_LISTENING
)
838 log_unit_debug(UNIT(n
), "Activation request");
840 if (revents
!= EPOLLIN
) {
841 log_unit_error(UNIT(n
), "Got unexpected poll event (0x%x) on starter fd.", revents
);
845 busname_peek_message(n
);
846 busname_enter_running(n
);
850 busname_enter_dead(n
, BUSNAME_FAILURE_RESOURCES
);
854 static void busname_sigchld_event(Unit
*u
, pid_t pid
, int code
, int status
) {
855 BusName
*n
= BUSNAME(u
);
861 if (pid
!= n
->control_pid
)
866 if (is_clean_exit(code
, status
, NULL
))
868 else if (code
== CLD_EXITED
)
869 f
= BUSNAME_FAILURE_EXIT_CODE
;
870 else if (code
== CLD_KILLED
)
871 f
= BUSNAME_FAILURE_SIGNAL
;
872 else if (code
== CLD_DUMPED
)
873 f
= BUSNAME_FAILURE_CORE_DUMP
;
875 assert_not_reached("Unknown sigchld code");
877 log_unit_full(u
, f
== BUSNAME_SUCCESS
? LOG_DEBUG
: LOG_NOTICE
, 0,
878 "Control process exited, code=%s status=%i", sigchld_code_to_string(code
), status
);
880 if (f
!= BUSNAME_SUCCESS
)
886 if (f
== BUSNAME_SUCCESS
)
887 busname_enter_listening(n
);
889 busname_enter_signal(n
, BUSNAME_SIGTERM
, f
);
892 case BUSNAME_SIGTERM
:
893 case BUSNAME_SIGKILL
:
894 busname_enter_dead(n
, f
);
898 assert_not_reached("Uh, control process died at wrong time.");
901 /* Notify clients about changed exit status */
902 unit_add_to_dbus_queue(u
);
905 static int busname_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
) {
906 BusName
*n
= BUSNAME(userdata
);
909 assert(n
->timer_event_source
== source
);
914 log_unit_warning(UNIT(n
), "Making timed out. Terminating.");
915 busname_enter_signal(n
, BUSNAME_SIGTERM
, BUSNAME_FAILURE_TIMEOUT
);
918 case BUSNAME_SIGTERM
:
919 log_unit_warning(UNIT(n
), "Stopping timed out. Killing.");
920 busname_enter_signal(n
, BUSNAME_SIGKILL
, BUSNAME_FAILURE_TIMEOUT
);
923 case BUSNAME_SIGKILL
:
924 log_unit_warning(UNIT(n
), "Processes still around after SIGKILL. Ignoring.");
925 busname_enter_dead(n
, BUSNAME_FAILURE_TIMEOUT
);
929 assert_not_reached("Timeout at wrong time.");
935 static void busname_reset_failed(Unit
*u
) {
936 BusName
*n
= BUSNAME(u
);
940 if (n
->state
== BUSNAME_FAILED
)
941 busname_set_state(n
, BUSNAME_DEAD
);
943 n
->result
= BUSNAME_SUCCESS
;
946 static void busname_trigger_notify(Unit
*u
, Unit
*other
) {
947 BusName
*n
= BUSNAME(u
);
953 if (!IN_SET(n
->state
, BUSNAME_RUNNING
, BUSNAME_LISTENING
))
956 if (other
->load_state
!= UNIT_LOADED
|| other
->type
!= UNIT_SERVICE
)
961 if (s
->state
== SERVICE_FAILED
&& s
->result
== SERVICE_FAILURE_START_LIMIT
)
962 busname_enter_dead(n
, BUSNAME_FAILURE_SERVICE_FAILED_PERMANENT
);
963 else if (IN_SET(s
->state
,
964 SERVICE_DEAD
, SERVICE_FAILED
,
965 SERVICE_STOP
, SERVICE_STOP_SIGTERM
, SERVICE_STOP_SIGKILL
,
966 SERVICE_STOP_POST
, SERVICE_FINAL_SIGTERM
, SERVICE_FINAL_SIGKILL
,
967 SERVICE_AUTO_RESTART
))
968 busname_enter_listening(n
);
971 static int busname_kill(Unit
*u
, KillWho who
, int signo
, sd_bus_error
*error
) {
972 return unit_kill_common(u
, who
, signo
, -1, BUSNAME(u
)->control_pid
, error
);
975 static int busname_get_timeout(Unit
*u
, uint64_t *timeout
) {
976 BusName
*n
= BUSNAME(u
);
979 if (!n
->timer_event_source
)
982 r
= sd_event_source_get_time(n
->timer_event_source
, timeout
);
989 static bool busname_supported(void) {
990 static int supported
= -1;
993 supported
= is_kdbus_available();
998 static const char* const busname_result_table
[_BUSNAME_RESULT_MAX
] = {
999 [BUSNAME_SUCCESS
] = "success",
1000 [BUSNAME_FAILURE_RESOURCES
] = "resources",
1001 [BUSNAME_FAILURE_TIMEOUT
] = "timeout",
1002 [BUSNAME_FAILURE_EXIT_CODE
] = "exit-code",
1003 [BUSNAME_FAILURE_SIGNAL
] = "signal",
1004 [BUSNAME_FAILURE_CORE_DUMP
] = "core-dump",
1005 [BUSNAME_FAILURE_SERVICE_FAILED_PERMANENT
] = "service-failed-permanent",
1008 DEFINE_STRING_TABLE_LOOKUP(busname_result
, BusNameResult
);
1010 const UnitVTable busname_vtable
= {
1011 .object_size
= sizeof(BusName
),
1017 .private_section
= "BusName",
1020 .no_instances
= true,
1022 .init
= busname_init
,
1023 .done
= busname_done
,
1024 .load
= busname_load
,
1026 .coldplug
= busname_coldplug
,
1028 .dump
= busname_dump
,
1030 .start
= busname_start
,
1031 .stop
= busname_stop
,
1033 .kill
= busname_kill
,
1035 .get_timeout
= busname_get_timeout
,
1037 .serialize
= busname_serialize
,
1038 .deserialize_item
= busname_deserialize_item
,
1040 .active_state
= busname_active_state
,
1041 .sub_state_to_string
= busname_sub_state_to_string
,
1043 .sigchld_event
= busname_sigchld_event
,
1045 .trigger_notify
= busname_trigger_notify
,
1047 .reset_failed
= busname_reset_failed
,
1049 .supported
= busname_supported
,
1051 .bus_vtable
= bus_busname_vtable
,
1053 .status_message_formats
= {
1054 .finished_start_job
= {
1055 [JOB_DONE
] = "Listening on %s.",
1056 [JOB_FAILED
] = "Failed to listen on %s.",
1058 .finished_stop_job
= {
1059 [JOB_DONE
] = "Closed %s.",
1060 [JOB_FAILED
] = "Failed stopping %s.",