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 "alloc-util.h"
25 #include "bus-internal.h"
26 #include "bus-kernel.h"
27 #include "bus-policy.h"
30 #include "dbus-busname.h"
32 #include "formats-util.h"
34 #include "parse-util.h"
35 #include "process-util.h"
37 #include "signal-util.h"
39 #include "string-table.h"
40 #include "string-util.h"
42 static const UnitActiveState state_translation_table
[_BUSNAME_STATE_MAX
] = {
43 [BUSNAME_DEAD
] = UNIT_INACTIVE
,
44 [BUSNAME_MAKING
] = UNIT_ACTIVATING
,
45 [BUSNAME_REGISTERED
] = UNIT_ACTIVE
,
46 [BUSNAME_LISTENING
] = UNIT_ACTIVE
,
47 [BUSNAME_RUNNING
] = UNIT_ACTIVE
,
48 [BUSNAME_SIGTERM
] = UNIT_DEACTIVATING
,
49 [BUSNAME_SIGKILL
] = UNIT_DEACTIVATING
,
50 [BUSNAME_FAILED
] = UNIT_FAILED
53 static int busname_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
);
54 static int busname_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
);
56 static void busname_init(Unit
*u
) {
57 BusName
*n
= BUSNAME(u
);
60 assert(u
->load_state
== UNIT_STUB
);
66 n
->timeout_usec
= u
->manager
->default_timeout_start_usec
;
69 static void busname_unwatch_control_pid(BusName
*n
) {
72 if (n
->control_pid
<= 0)
75 unit_unwatch_pid(UNIT(n
), n
->control_pid
);
79 static void busname_free_policy(BusName
*n
) {
84 while ((p
= n
->policy
)) {
85 LIST_REMOVE(policy
, n
->policy
, p
);
92 static void busname_close_fd(BusName
*n
) {
95 n
->starter_event_source
= sd_event_source_unref(n
->starter_event_source
);
96 n
->starter_fd
= safe_close(n
->starter_fd
);
99 static void busname_done(Unit
*u
) {
100 BusName
*n
= BUSNAME(u
);
104 n
->name
= mfree(n
->name
);
106 busname_free_policy(n
);
107 busname_unwatch_control_pid(n
);
110 unit_ref_unset(&n
->service
);
112 n
->timer_event_source
= sd_event_source_unref(n
->timer_event_source
);
115 static int busname_arm_timer(BusName
*n
) {
120 if (n
->timeout_usec
<= 0) {
121 n
->timer_event_source
= sd_event_source_unref(n
->timer_event_source
);
125 if (n
->timer_event_source
) {
126 r
= sd_event_source_set_time(n
->timer_event_source
, now(CLOCK_MONOTONIC
) + n
->timeout_usec
);
130 return sd_event_source_set_enabled(n
->timer_event_source
, SD_EVENT_ONESHOT
);
133 r
= sd_event_add_time(
134 UNIT(n
)->manager
->event
,
135 &n
->timer_event_source
,
137 now(CLOCK_MONOTONIC
) + n
->timeout_usec
, 0,
138 busname_dispatch_timer
, n
);
142 (void) sd_event_source_set_description(n
->timer_event_source
, "busname-timer");
147 static int busname_add_default_default_dependencies(BusName
*n
) {
152 r
= unit_add_dependency_by_name(UNIT(n
), UNIT_BEFORE
, SPECIAL_BUSNAMES_TARGET
, NULL
, true);
156 if (UNIT(n
)->manager
->running_as
== MANAGER_SYSTEM
) {
157 r
= unit_add_two_dependencies_by_name(UNIT(n
), UNIT_AFTER
, UNIT_REQUIRES
, SPECIAL_SYSINIT_TARGET
, NULL
, true);
162 return unit_add_two_dependencies_by_name(UNIT(n
), UNIT_BEFORE
, UNIT_CONFLICTS
, SPECIAL_SHUTDOWN_TARGET
, NULL
, true);
165 static int busname_add_extras(BusName
*n
) {
172 r
= unit_name_to_prefix(u
->id
, &n
->name
);
177 if (!u
->description
) {
178 r
= unit_set_description(u
, n
->name
);
184 if (!UNIT_DEREF(n
->service
)) {
187 r
= unit_load_related_unit(u
, ".service", &x
);
191 unit_ref_set(&n
->service
, x
);
194 r
= unit_add_two_dependencies(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, UNIT_DEREF(n
->service
), true);
199 if (u
->default_dependencies
) {
200 r
= busname_add_default_default_dependencies(n
);
208 static int busname_verify(BusName
*n
) {
213 if (UNIT(n
)->load_state
!= UNIT_LOADED
)
216 if (!service_name_is_valid(n
->name
)) {
217 log_unit_error(UNIT(n
), "Name= setting is not a valid service name Refusing.");
221 e
= strjoina(n
->name
, ".busname");
222 if (!unit_has_name(UNIT(n
), e
)) {
223 log_unit_error(UNIT(n
), "Name= setting doesn't match unit name. Refusing.");
230 static int busname_load(Unit
*u
) {
231 BusName
*n
= BUSNAME(u
);
235 assert(u
->load_state
== UNIT_STUB
);
237 r
= unit_load_fragment_and_dropin(u
);
241 if (u
->load_state
== UNIT_LOADED
) {
242 /* This is a new unit? Then let's add in some extras */
243 r
= busname_add_extras(n
);
248 return busname_verify(n
);
251 static void busname_dump(Unit
*u
, FILE *f
, const char *prefix
) {
252 BusName
*n
= BUSNAME(u
);
258 "%sBus Name State: %s\n"
263 prefix
, busname_state_to_string(n
->state
),
264 prefix
, busname_result_to_string(n
->result
),
266 prefix
, yes_no(n
->activating
),
267 prefix
, yes_no(n
->accept_fd
));
269 if (n
->control_pid
> 0)
271 "%sControl PID: "PID_FMT
"\n",
272 prefix
, n
->control_pid
);
275 static void busname_unwatch_fd(BusName
*n
) {
280 if (!n
->starter_event_source
)
283 r
= sd_event_source_set_enabled(n
->starter_event_source
, SD_EVENT_OFF
);
285 log_unit_debug_errno(UNIT(n
), r
, "Failed to disable event source: %m");
288 static int busname_watch_fd(BusName
*n
) {
293 if (n
->starter_fd
< 0)
296 if (n
->starter_event_source
) {
297 r
= sd_event_source_set_enabled(n
->starter_event_source
, SD_EVENT_ON
);
301 r
= sd_event_add_io(UNIT(n
)->manager
->event
, &n
->starter_event_source
, n
->starter_fd
, EPOLLIN
, busname_dispatch_io
, n
);
305 (void) sd_event_source_set_description(n
->starter_event_source
, "busname-starter");
311 log_unit_warning_errno(UNIT(n
), r
, "Failed to watch starter fd: %m");
312 busname_unwatch_fd(n
);
316 static int busname_open_fd(BusName
*n
) {
317 _cleanup_free_
char *path
= NULL
;
322 if (n
->starter_fd
>= 0)
325 mode
= UNIT(n
)->manager
->running_as
== MANAGER_SYSTEM
? "system" : "user";
326 n
->starter_fd
= bus_kernel_open_bus_fd(mode
, &path
);
327 if (n
->starter_fd
< 0)
328 return log_unit_warning_errno(UNIT(n
), n
->starter_fd
, "Failed to open %s: %m", path
?: "kdbus");
333 static void busname_set_state(BusName
*n
, BusNameState state
) {
334 BusNameState old_state
;
337 old_state
= n
->state
;
340 if (!IN_SET(state
, BUSNAME_MAKING
, BUSNAME_SIGTERM
, BUSNAME_SIGKILL
)) {
341 n
->timer_event_source
= sd_event_source_unref(n
->timer_event_source
);
342 busname_unwatch_control_pid(n
);
345 if (state
!= BUSNAME_LISTENING
)
346 busname_unwatch_fd(n
);
348 if (!IN_SET(state
, BUSNAME_LISTENING
, BUSNAME_MAKING
, BUSNAME_REGISTERED
, BUSNAME_RUNNING
))
351 if (state
!= old_state
)
352 log_unit_debug(UNIT(n
), "Changed %s -> %s", busname_state_to_string(old_state
), busname_state_to_string(state
));
354 unit_notify(UNIT(n
), state_translation_table
[old_state
], state_translation_table
[state
], true);
357 static int busname_coldplug(Unit
*u
) {
358 BusName
*n
= BUSNAME(u
);
362 assert(n
->state
== BUSNAME_DEAD
);
364 if (n
->deserialized_state
== n
->state
)
367 if (IN_SET(n
->deserialized_state
, BUSNAME_MAKING
, BUSNAME_SIGTERM
, BUSNAME_SIGKILL
)) {
369 if (n
->control_pid
<= 0)
372 r
= unit_watch_pid(UNIT(n
), n
->control_pid
);
376 r
= busname_arm_timer(n
);
381 if (IN_SET(n
->deserialized_state
, BUSNAME_MAKING
, BUSNAME_LISTENING
, BUSNAME_REGISTERED
, BUSNAME_RUNNING
)) {
382 r
= busname_open_fd(n
);
387 if (n
->deserialized_state
== BUSNAME_LISTENING
) {
388 r
= busname_watch_fd(n
);
393 busname_set_state(n
, n
->deserialized_state
);
397 static int busname_make_starter(BusName
*n
, pid_t
*_pid
) {
401 r
= busname_arm_timer(n
);
405 /* We have to resolve the user/group names out-of-process,
406 * hence let's fork here. It's messy, but well, what can we
416 (void) default_signals(SIGNALS_CRASH_HANDLER
, SIGNALS_IGNORE
, -1);
417 (void) ignore_signals(SIGPIPE
, -1);
420 r
= bus_kernel_make_starter(n
->starter_fd
, n
->name
, n
->activating
, n
->accept_fd
, n
->policy
, n
->policy_world
);
422 ret
= EXIT_MAKE_STARTER
;
430 log_error_errno(r
, "Failed to create starter connection at step %s: %m", exit_status_to_string(ret
, EXIT_STATUS_SYSTEMD
));
435 r
= unit_watch_pid(UNIT(n
), pid
);
443 n
->timer_event_source
= sd_event_source_unref(n
->timer_event_source
);
447 static void busname_enter_dead(BusName
*n
, BusNameResult f
) {
450 if (f
!= BUSNAME_SUCCESS
)
453 busname_set_state(n
, n
->result
!= BUSNAME_SUCCESS
? BUSNAME_FAILED
: BUSNAME_DEAD
);
456 static void busname_enter_signal(BusName
*n
, BusNameState state
, BusNameResult f
) {
457 KillContext kill_context
= {};
462 if (f
!= BUSNAME_SUCCESS
)
465 kill_context_init(&kill_context
);
467 r
= unit_kill_context(UNIT(n
),
469 state
!= BUSNAME_SIGTERM
? KILL_KILL
: KILL_TERMINATE
,
474 log_unit_warning_errno(UNIT(n
), r
, "Failed to kill control process: %m");
479 r
= busname_arm_timer(n
);
481 log_unit_warning_errno(UNIT(n
), r
, "Failed to arm timer: %m");
485 busname_set_state(n
, state
);
486 } else if (state
== BUSNAME_SIGTERM
)
487 busname_enter_signal(n
, BUSNAME_SIGKILL
, BUSNAME_SUCCESS
);
489 busname_enter_dead(n
, BUSNAME_SUCCESS
);
494 busname_enter_dead(n
, BUSNAME_FAILURE_RESOURCES
);
497 static void busname_enter_listening(BusName
*n
) {
503 r
= busname_watch_fd(n
);
505 log_unit_warning_errno(UNIT(n
), r
, "Failed to watch names: %m");
509 busname_set_state(n
, BUSNAME_LISTENING
);
511 busname_set_state(n
, BUSNAME_REGISTERED
);
516 busname_enter_signal(n
, BUSNAME_SIGTERM
, BUSNAME_FAILURE_RESOURCES
);
519 static void busname_enter_making(BusName
*n
) {
524 r
= busname_open_fd(n
);
529 /* If there is a policy, we need to resolve user/group
530 * names, which we can't do from PID1, hence let's
532 busname_unwatch_control_pid(n
);
534 r
= busname_make_starter(n
, &n
->control_pid
);
536 log_unit_warning_errno(UNIT(n
), r
, "Failed to fork 'making' task: %m");
540 busname_set_state(n
, BUSNAME_MAKING
);
542 /* If there is no policy, we can do everything
543 * directly from PID 1, hence do so. */
545 r
= bus_kernel_make_starter(n
->starter_fd
, n
->name
, n
->activating
, n
->accept_fd
, NULL
, n
->policy_world
);
547 log_unit_warning_errno(UNIT(n
), r
, "Failed to make starter: %m");
551 busname_enter_listening(n
);
557 busname_enter_dead(n
, BUSNAME_FAILURE_RESOURCES
);
560 static void busname_enter_running(BusName
*n
) {
561 _cleanup_bus_error_free_ sd_bus_error error
= SD_BUS_ERROR_NULL
;
562 bool pending
= false;
572 /* We don't take connections anymore if we are supposed to
573 * shut down anyway */
575 if (unit_stop_pending(UNIT(n
))) {
576 log_unit_debug(UNIT(n
), "Suppressing activation request since unit stop is scheduled.");
578 /* Flush all queued activation reqeuest by closing and reopening the connection */
579 bus_kernel_drop_one(n
->starter_fd
);
581 busname_enter_listening(n
);
585 /* If there's already a start pending don't bother to do
587 SET_FOREACH(other
, UNIT(n
)->dependencies
[UNIT_TRIGGERS
], i
)
588 if (unit_active_or_pending(other
)) {
594 if (!UNIT_ISSET(n
->service
)) {
595 log_unit_error(UNIT(n
), "Service to activate vanished, refusing activation.");
600 r
= manager_add_job(UNIT(n
)->manager
, JOB_START
, UNIT_DEREF(n
->service
), JOB_REPLACE
, true, &error
, NULL
);
605 busname_set_state(n
, BUSNAME_RUNNING
);
609 log_unit_warning(UNIT(n
), "Failed to queue service startup job: %s", bus_error_message(&error
, r
));
610 busname_enter_dead(n
, BUSNAME_FAILURE_RESOURCES
);
613 static int busname_start(Unit
*u
) {
614 BusName
*n
= BUSNAME(u
);
618 /* We cannot fulfill this request right now, try again later
620 if (IN_SET(n
->state
, BUSNAME_SIGTERM
, BUSNAME_SIGKILL
))
624 if (n
->state
== BUSNAME_MAKING
)
627 if (n
->activating
&& UNIT_ISSET(n
->service
)) {
630 service
= SERVICE(UNIT_DEREF(n
->service
));
632 if (UNIT(service
)->load_state
!= UNIT_LOADED
) {
633 log_unit_error(u
, "Bus service %s not loaded, refusing.", UNIT(service
)->id
);
638 assert(IN_SET(n
->state
, BUSNAME_DEAD
, BUSNAME_FAILED
));
640 n
->result
= BUSNAME_SUCCESS
;
641 busname_enter_making(n
);
646 static int busname_stop(Unit
*u
) {
647 BusName
*n
= BUSNAME(u
);
652 if (IN_SET(n
->state
, BUSNAME_SIGTERM
, BUSNAME_SIGKILL
))
655 /* If there's already something running, we go directly into
658 if (n
->state
== BUSNAME_MAKING
) {
659 busname_enter_signal(n
, BUSNAME_SIGTERM
, BUSNAME_SUCCESS
);
663 assert(IN_SET(n
->state
, BUSNAME_REGISTERED
, BUSNAME_LISTENING
, BUSNAME_RUNNING
));
665 busname_enter_dead(n
, BUSNAME_SUCCESS
);
669 static int busname_serialize(Unit
*u
, FILE *f
, FDSet
*fds
) {
670 BusName
*n
= BUSNAME(u
);
677 unit_serialize_item(u
, f
, "state", busname_state_to_string(n
->state
));
678 unit_serialize_item(u
, f
, "result", busname_result_to_string(n
->result
));
680 if (n
->control_pid
> 0)
681 unit_serialize_item_format(u
, f
, "control-pid", PID_FMT
, n
->control_pid
);
683 r
= unit_serialize_item_fd(u
, f
, fds
, "starter-fd", n
->starter_fd
);
690 static int busname_deserialize_item(Unit
*u
, const char *key
, const char *value
, FDSet
*fds
) {
691 BusName
*n
= BUSNAME(u
);
697 if (streq(key
, "state")) {
700 state
= busname_state_from_string(value
);
702 log_unit_debug(u
, "Failed to parse state value: %s", value
);
704 n
->deserialized_state
= state
;
706 } else if (streq(key
, "result")) {
709 f
= busname_result_from_string(value
);
711 log_unit_debug(u
, "Failed to parse result value: %s", value
);
712 else if (f
!= BUSNAME_SUCCESS
)
715 } else if (streq(key
, "control-pid")) {
718 if (parse_pid(value
, &pid
) < 0)
719 log_unit_debug(u
, "Failed to parse control-pid value: %s", value
);
721 n
->control_pid
= pid
;
722 } else if (streq(key
, "starter-fd")) {
725 if (safe_atoi(value
, &fd
) < 0 || fd
< 0 || !fdset_contains(fds
, fd
))
726 log_unit_debug(u
, "Failed to parse starter fd value: %s", value
);
728 safe_close(n
->starter_fd
);
729 n
->starter_fd
= fdset_remove(fds
, fd
);
732 log_unit_debug(u
, "Unknown serialization key: %s", key
);
737 _pure_
static UnitActiveState
busname_active_state(Unit
*u
) {
740 return state_translation_table
[BUSNAME(u
)->state
];
743 _pure_
static const char *busname_sub_state_to_string(Unit
*u
) {
746 return busname_state_to_string(BUSNAME(u
)->state
);
749 static int busname_peek_message(BusName
*n
) {
750 struct kdbus_cmd_recv cmd_recv
= {
751 .size
= sizeof(cmd_recv
),
752 .flags
= KDBUS_RECV_PEEK
,
754 struct kdbus_cmd_free cmd_free
= {
755 .size
= sizeof(cmd_free
),
757 const char *comm
= NULL
;
758 struct kdbus_item
*d
;
760 size_t start
, ps
, sz
, delta
;
765 /* Generate a friendly debug log message about which process
766 * caused triggering of this bus name. This simply peeks the
767 * metadata of the first queued message and logs it. */
771 /* Let's shortcut things a bit, if debug logging is turned off
774 if (log_get_max_level() < LOG_DEBUG
)
777 r
= ioctl(n
->starter_fd
, KDBUS_CMD_RECV
, &cmd_recv
);
779 if (errno
== EINTR
|| errno
== EAGAIN
)
782 return log_unit_error_errno(UNIT(n
), errno
, "Failed to query activation message: %m");
785 /* We map as late as possible, and unmap imemdiately after
786 * use. On 32bit address space is scarce and we want to be
787 * able to handle a lot of activator connections at the same
788 * time, and hence shouldn't keep the mmap()s around for
789 * longer than necessary. */
792 start
= (cmd_recv
.msg
.offset
/ ps
) * ps
;
793 delta
= cmd_recv
.msg
.offset
- start
;
794 sz
= PAGE_ALIGN(delta
+ cmd_recv
.msg
.msg_size
);
796 p
= mmap(NULL
, sz
, PROT_READ
, MAP_SHARED
, n
->starter_fd
, start
);
797 if (p
== MAP_FAILED
) {
798 r
= log_unit_error_errno(UNIT(n
), errno
, "Failed to map activation message: %m");
802 k
= (struct kdbus_msg
*) ((uint8_t *) p
+ delta
);
803 KDBUS_ITEM_FOREACH(d
, k
, items
) {
806 case KDBUS_ITEM_PIDS
:
810 case KDBUS_ITEM_PID_COMM
:
817 log_unit_debug(UNIT(n
), "Activation triggered by process " PID_FMT
" (%s)", pid
, strna(comm
));
823 (void) munmap(p
, sz
);
825 cmd_free
.offset
= cmd_recv
.msg
.offset
;
826 if (ioctl(n
->starter_fd
, KDBUS_CMD_FREE
, &cmd_free
) < 0)
827 log_unit_warning(UNIT(n
), "Failed to free peeked message, ignoring: %m");
832 static int busname_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
) {
833 BusName
*n
= userdata
;
838 if (n
->state
!= BUSNAME_LISTENING
)
841 log_unit_debug(UNIT(n
), "Activation request");
843 if (revents
!= EPOLLIN
) {
844 log_unit_error(UNIT(n
), "Got unexpected poll event (0x%x) on starter fd.", revents
);
848 busname_peek_message(n
);
849 busname_enter_running(n
);
853 busname_enter_dead(n
, BUSNAME_FAILURE_RESOURCES
);
857 static void busname_sigchld_event(Unit
*u
, pid_t pid
, int code
, int status
) {
858 BusName
*n
= BUSNAME(u
);
864 if (pid
!= n
->control_pid
)
869 if (is_clean_exit(code
, status
, NULL
))
871 else if (code
== CLD_EXITED
)
872 f
= BUSNAME_FAILURE_EXIT_CODE
;
873 else if (code
== CLD_KILLED
)
874 f
= BUSNAME_FAILURE_SIGNAL
;
875 else if (code
== CLD_DUMPED
)
876 f
= BUSNAME_FAILURE_CORE_DUMP
;
878 assert_not_reached("Unknown sigchld code");
880 log_unit_full(u
, f
== BUSNAME_SUCCESS
? LOG_DEBUG
: LOG_NOTICE
, 0,
881 "Control process exited, code=%s status=%i", sigchld_code_to_string(code
), status
);
883 if (f
!= BUSNAME_SUCCESS
)
889 if (f
== BUSNAME_SUCCESS
)
890 busname_enter_listening(n
);
892 busname_enter_signal(n
, BUSNAME_SIGTERM
, f
);
895 case BUSNAME_SIGTERM
:
896 case BUSNAME_SIGKILL
:
897 busname_enter_dead(n
, f
);
901 assert_not_reached("Uh, control process died at wrong time.");
904 /* Notify clients about changed exit status */
905 unit_add_to_dbus_queue(u
);
908 static int busname_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
) {
909 BusName
*n
= BUSNAME(userdata
);
912 assert(n
->timer_event_source
== source
);
917 log_unit_warning(UNIT(n
), "Making timed out. Terminating.");
918 busname_enter_signal(n
, BUSNAME_SIGTERM
, BUSNAME_FAILURE_TIMEOUT
);
921 case BUSNAME_SIGTERM
:
922 log_unit_warning(UNIT(n
), "Stopping timed out. Killing.");
923 busname_enter_signal(n
, BUSNAME_SIGKILL
, BUSNAME_FAILURE_TIMEOUT
);
926 case BUSNAME_SIGKILL
:
927 log_unit_warning(UNIT(n
), "Processes still around after SIGKILL. Ignoring.");
928 busname_enter_dead(n
, BUSNAME_FAILURE_TIMEOUT
);
932 assert_not_reached("Timeout at wrong time.");
938 static void busname_reset_failed(Unit
*u
) {
939 BusName
*n
= BUSNAME(u
);
943 if (n
->state
== BUSNAME_FAILED
)
944 busname_set_state(n
, BUSNAME_DEAD
);
946 n
->result
= BUSNAME_SUCCESS
;
949 static void busname_trigger_notify(Unit
*u
, Unit
*other
) {
950 BusName
*n
= BUSNAME(u
);
956 if (!IN_SET(n
->state
, BUSNAME_RUNNING
, BUSNAME_LISTENING
))
959 if (other
->load_state
!= UNIT_LOADED
|| other
->type
!= UNIT_SERVICE
)
964 if (s
->state
== SERVICE_FAILED
&& s
->result
== SERVICE_FAILURE_START_LIMIT
)
965 busname_enter_dead(n
, BUSNAME_FAILURE_SERVICE_FAILED_PERMANENT
);
966 else if (IN_SET(s
->state
,
967 SERVICE_DEAD
, SERVICE_FAILED
,
968 SERVICE_STOP
, SERVICE_STOP_SIGTERM
, SERVICE_STOP_SIGKILL
,
969 SERVICE_STOP_POST
, SERVICE_FINAL_SIGTERM
, SERVICE_FINAL_SIGKILL
,
970 SERVICE_AUTO_RESTART
))
971 busname_enter_listening(n
);
974 static int busname_kill(Unit
*u
, KillWho who
, int signo
, sd_bus_error
*error
) {
975 return unit_kill_common(u
, who
, signo
, -1, BUSNAME(u
)->control_pid
, error
);
978 static int busname_get_timeout(Unit
*u
, uint64_t *timeout
) {
979 BusName
*n
= BUSNAME(u
);
982 if (!n
->timer_event_source
)
985 r
= sd_event_source_get_time(n
->timer_event_source
, timeout
);
992 static bool busname_supported(void) {
993 static int supported
= -1;
996 supported
= is_kdbus_available();
1001 static const char* const busname_result_table
[_BUSNAME_RESULT_MAX
] = {
1002 [BUSNAME_SUCCESS
] = "success",
1003 [BUSNAME_FAILURE_RESOURCES
] = "resources",
1004 [BUSNAME_FAILURE_TIMEOUT
] = "timeout",
1005 [BUSNAME_FAILURE_EXIT_CODE
] = "exit-code",
1006 [BUSNAME_FAILURE_SIGNAL
] = "signal",
1007 [BUSNAME_FAILURE_CORE_DUMP
] = "core-dump",
1008 [BUSNAME_FAILURE_SERVICE_FAILED_PERMANENT
] = "service-failed-permanent",
1011 DEFINE_STRING_TABLE_LOOKUP(busname_result
, BusNameResult
);
1013 const UnitVTable busname_vtable
= {
1014 .object_size
= sizeof(BusName
),
1020 .private_section
= "BusName",
1023 .no_instances
= true,
1025 .init
= busname_init
,
1026 .done
= busname_done
,
1027 .load
= busname_load
,
1029 .coldplug
= busname_coldplug
,
1031 .dump
= busname_dump
,
1033 .start
= busname_start
,
1034 .stop
= busname_stop
,
1036 .kill
= busname_kill
,
1038 .get_timeout
= busname_get_timeout
,
1040 .serialize
= busname_serialize
,
1041 .deserialize_item
= busname_deserialize_item
,
1043 .active_state
= busname_active_state
,
1044 .sub_state_to_string
= busname_sub_state_to_string
,
1046 .sigchld_event
= busname_sigchld_event
,
1048 .trigger_notify
= busname_trigger_notify
,
1050 .reset_failed
= busname_reset_failed
,
1052 .supported
= busname_supported
,
1054 .bus_vtable
= bus_busname_vtable
,
1056 .status_message_formats
= {
1057 .finished_start_job
= {
1058 [JOB_DONE
] = "Listening on %s.",
1059 [JOB_FAILED
] = "Failed to listen on %s.",
1061 .finished_stop_job
= {
1062 [JOB_DONE
] = "Closed %s.",
1063 [JOB_FAILED
] = "Failed stopping %s.",