2 This file is part of systemd.
4 Copyright 2013 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include "alloc-util.h"
23 #include "bus-internal.h"
24 #include "bus-kernel.h"
25 #include "bus-policy.h"
28 #include "dbus-busname.h"
30 #include "formats-util.h"
32 #include "parse-util.h"
33 #include "process-util.h"
35 #include "signal-util.h"
37 #include "string-table.h"
38 #include "string-util.h"
40 static const UnitActiveState state_translation_table
[_BUSNAME_STATE_MAX
] = {
41 [BUSNAME_DEAD
] = UNIT_INACTIVE
,
42 [BUSNAME_MAKING
] = UNIT_ACTIVATING
,
43 [BUSNAME_REGISTERED
] = UNIT_ACTIVE
,
44 [BUSNAME_LISTENING
] = UNIT_ACTIVE
,
45 [BUSNAME_RUNNING
] = UNIT_ACTIVE
,
46 [BUSNAME_SIGTERM
] = UNIT_DEACTIVATING
,
47 [BUSNAME_SIGKILL
] = UNIT_DEACTIVATING
,
48 [BUSNAME_FAILED
] = UNIT_FAILED
51 static int busname_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
);
52 static int busname_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
);
54 static void busname_init(Unit
*u
) {
55 BusName
*n
= BUSNAME(u
);
58 assert(u
->load_state
== UNIT_STUB
);
64 n
->timeout_usec
= u
->manager
->default_timeout_start_usec
;
67 static void busname_unwatch_control_pid(BusName
*n
) {
70 if (n
->control_pid
<= 0)
73 unit_unwatch_pid(UNIT(n
), n
->control_pid
);
77 static void busname_free_policy(BusName
*n
) {
82 while ((p
= n
->policy
)) {
83 LIST_REMOVE(policy
, n
->policy
, p
);
90 static void busname_close_fd(BusName
*n
) {
93 n
->starter_event_source
= sd_event_source_unref(n
->starter_event_source
);
94 n
->starter_fd
= safe_close(n
->starter_fd
);
97 static void busname_done(Unit
*u
) {
98 BusName
*n
= BUSNAME(u
);
102 n
->name
= mfree(n
->name
);
104 busname_free_policy(n
);
105 busname_unwatch_control_pid(n
);
108 unit_ref_unset(&n
->service
);
110 n
->timer_event_source
= sd_event_source_unref(n
->timer_event_source
);
113 static int busname_arm_timer(BusName
*n
, usec_t usec
) {
118 if (n
->timer_event_source
) {
119 r
= sd_event_source_set_time(n
->timer_event_source
, usec
);
123 return sd_event_source_set_enabled(n
->timer_event_source
, SD_EVENT_ONESHOT
);
126 if (usec
== USEC_INFINITY
)
129 r
= sd_event_add_time(
130 UNIT(n
)->manager
->event
,
131 &n
->timer_event_source
,
134 busname_dispatch_timer
, n
);
138 (void) sd_event_source_set_description(n
->timer_event_source
, "busname-timer");
143 static int busname_add_default_default_dependencies(BusName
*n
) {
148 r
= unit_add_dependency_by_name(UNIT(n
), UNIT_BEFORE
, SPECIAL_BUSNAMES_TARGET
, NULL
, true);
152 if (MANAGER_IS_SYSTEM(UNIT(n
)->manager
)) {
153 r
= unit_add_two_dependencies_by_name(UNIT(n
), UNIT_AFTER
, UNIT_REQUIRES
, SPECIAL_SYSINIT_TARGET
, NULL
, true);
158 return unit_add_two_dependencies_by_name(UNIT(n
), UNIT_BEFORE
, UNIT_CONFLICTS
, SPECIAL_SHUTDOWN_TARGET
, NULL
, true);
161 static int busname_add_extras(BusName
*n
) {
168 r
= unit_name_to_prefix(u
->id
, &n
->name
);
173 if (!u
->description
) {
174 r
= unit_set_description(u
, n
->name
);
180 if (!UNIT_DEREF(n
->service
)) {
183 r
= unit_load_related_unit(u
, ".service", &x
);
187 unit_ref_set(&n
->service
, x
);
190 r
= unit_add_two_dependencies(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, UNIT_DEREF(n
->service
), true);
195 if (u
->default_dependencies
) {
196 r
= busname_add_default_default_dependencies(n
);
204 static int busname_verify(BusName
*n
) {
209 if (UNIT(n
)->load_state
!= UNIT_LOADED
)
212 if (!service_name_is_valid(n
->name
)) {
213 log_unit_error(UNIT(n
), "Name= setting is not a valid service name Refusing.");
217 e
= strjoina(n
->name
, ".busname");
218 if (!unit_has_name(UNIT(n
), e
)) {
219 log_unit_error(UNIT(n
), "Name= setting doesn't match unit name. Refusing.");
226 static int busname_load(Unit
*u
) {
227 BusName
*n
= BUSNAME(u
);
231 assert(u
->load_state
== UNIT_STUB
);
233 r
= unit_load_fragment_and_dropin(u
);
237 if (u
->load_state
== UNIT_LOADED
) {
238 /* This is a new unit? Then let's add in some extras */
239 r
= busname_add_extras(n
);
244 return busname_verify(n
);
247 static void busname_dump(Unit
*u
, FILE *f
, const char *prefix
) {
248 BusName
*n
= BUSNAME(u
);
254 "%sBus Name State: %s\n"
259 prefix
, busname_state_to_string(n
->state
),
260 prefix
, busname_result_to_string(n
->result
),
262 prefix
, yes_no(n
->activating
),
263 prefix
, yes_no(n
->accept_fd
));
265 if (n
->control_pid
> 0)
267 "%sControl PID: "PID_FMT
"\n",
268 prefix
, n
->control_pid
);
271 static void busname_unwatch_fd(BusName
*n
) {
276 if (!n
->starter_event_source
)
279 r
= sd_event_source_set_enabled(n
->starter_event_source
, SD_EVENT_OFF
);
281 log_unit_debug_errno(UNIT(n
), r
, "Failed to disable event source: %m");
284 static int busname_watch_fd(BusName
*n
) {
289 if (n
->starter_fd
< 0)
292 if (n
->starter_event_source
) {
293 r
= sd_event_source_set_enabled(n
->starter_event_source
, SD_EVENT_ON
);
297 r
= sd_event_add_io(UNIT(n
)->manager
->event
, &n
->starter_event_source
, n
->starter_fd
, EPOLLIN
, busname_dispatch_io
, n
);
301 (void) sd_event_source_set_description(n
->starter_event_source
, "busname-starter");
307 log_unit_warning_errno(UNIT(n
), r
, "Failed to watch starter fd: %m");
308 busname_unwatch_fd(n
);
312 static int busname_open_fd(BusName
*n
) {
313 _cleanup_free_
char *path
= NULL
;
318 if (n
->starter_fd
>= 0)
321 mode
= MANAGER_IS_SYSTEM(UNIT(n
)->manager
) ? "system" : "user";
322 n
->starter_fd
= bus_kernel_open_bus_fd(mode
, &path
);
323 if (n
->starter_fd
< 0)
324 return log_unit_warning_errno(UNIT(n
), n
->starter_fd
, "Failed to open %s: %m", path
?: "kdbus");
329 static void busname_set_state(BusName
*n
, BusNameState state
) {
330 BusNameState old_state
;
333 old_state
= n
->state
;
336 if (!IN_SET(state
, BUSNAME_MAKING
, BUSNAME_SIGTERM
, BUSNAME_SIGKILL
)) {
337 n
->timer_event_source
= sd_event_source_unref(n
->timer_event_source
);
338 busname_unwatch_control_pid(n
);
341 if (state
!= BUSNAME_LISTENING
)
342 busname_unwatch_fd(n
);
344 if (!IN_SET(state
, BUSNAME_LISTENING
, BUSNAME_MAKING
, BUSNAME_REGISTERED
, BUSNAME_RUNNING
))
347 if (state
!= old_state
)
348 log_unit_debug(UNIT(n
), "Changed %s -> %s", busname_state_to_string(old_state
), busname_state_to_string(state
));
350 unit_notify(UNIT(n
), state_translation_table
[old_state
], state_translation_table
[state
], true);
353 static int busname_coldplug(Unit
*u
) {
354 BusName
*n
= BUSNAME(u
);
358 assert(n
->state
== BUSNAME_DEAD
);
360 if (n
->deserialized_state
== n
->state
)
363 if (n
->control_pid
> 0 &&
364 pid_is_unwaited(n
->control_pid
) &&
365 IN_SET(n
->deserialized_state
, BUSNAME_MAKING
, BUSNAME_SIGTERM
, BUSNAME_SIGKILL
)) {
367 r
= unit_watch_pid(UNIT(n
), n
->control_pid
);
371 r
= busname_arm_timer(n
, usec_add(u
->state_change_timestamp
.monotonic
, n
->timeout_usec
));
376 if (IN_SET(n
->deserialized_state
, BUSNAME_MAKING
, BUSNAME_LISTENING
, BUSNAME_REGISTERED
, BUSNAME_RUNNING
)) {
377 r
= busname_open_fd(n
);
382 if (n
->deserialized_state
== BUSNAME_LISTENING
) {
383 r
= busname_watch_fd(n
);
388 busname_set_state(n
, n
->deserialized_state
);
392 static int busname_make_starter(BusName
*n
, pid_t
*_pid
) {
396 r
= busname_arm_timer(n
, usec_add(now(CLOCK_MONOTONIC
), n
->timeout_usec
));
400 /* We have to resolve the user/group names out-of-process,
401 * hence let's fork here. It's messy, but well, what can we
411 (void) default_signals(SIGNALS_CRASH_HANDLER
, SIGNALS_IGNORE
, -1);
412 (void) ignore_signals(SIGPIPE
, -1);
415 r
= bus_kernel_make_starter(n
->starter_fd
, n
->name
, n
->activating
, n
->accept_fd
, n
->policy
, n
->policy_world
);
417 ret
= EXIT_MAKE_STARTER
;
425 log_error_errno(r
, "Failed to create starter connection at step %s: %m", exit_status_to_string(ret
, EXIT_STATUS_SYSTEMD
));
430 r
= unit_watch_pid(UNIT(n
), pid
);
438 n
->timer_event_source
= sd_event_source_unref(n
->timer_event_source
);
442 static void busname_enter_dead(BusName
*n
, BusNameResult f
) {
445 if (n
->result
== BUSNAME_SUCCESS
)
448 busname_set_state(n
, n
->result
!= BUSNAME_SUCCESS
? BUSNAME_FAILED
: BUSNAME_DEAD
);
451 static void busname_enter_signal(BusName
*n
, BusNameState state
, BusNameResult f
) {
452 KillContext kill_context
= {};
457 if (n
->result
== BUSNAME_SUCCESS
)
460 kill_context_init(&kill_context
);
462 r
= unit_kill_context(UNIT(n
),
464 state
!= BUSNAME_SIGTERM
? KILL_KILL
: KILL_TERMINATE
,
469 log_unit_warning_errno(UNIT(n
), r
, "Failed to kill control process: %m");
474 r
= busname_arm_timer(n
, usec_add(now(CLOCK_MONOTONIC
), n
->timeout_usec
));
476 log_unit_warning_errno(UNIT(n
), r
, "Failed to arm timer: %m");
480 busname_set_state(n
, state
);
481 } else if (state
== BUSNAME_SIGTERM
)
482 busname_enter_signal(n
, BUSNAME_SIGKILL
, BUSNAME_SUCCESS
);
484 busname_enter_dead(n
, BUSNAME_SUCCESS
);
489 busname_enter_dead(n
, BUSNAME_FAILURE_RESOURCES
);
492 static void busname_enter_listening(BusName
*n
) {
498 r
= busname_watch_fd(n
);
500 log_unit_warning_errno(UNIT(n
), r
, "Failed to watch names: %m");
504 busname_set_state(n
, BUSNAME_LISTENING
);
506 busname_set_state(n
, BUSNAME_REGISTERED
);
511 busname_enter_signal(n
, BUSNAME_SIGTERM
, BUSNAME_FAILURE_RESOURCES
);
514 static void busname_enter_making(BusName
*n
) {
519 r
= busname_open_fd(n
);
524 /* If there is a policy, we need to resolve user/group
525 * names, which we can't do from PID1, hence let's
527 busname_unwatch_control_pid(n
);
529 r
= busname_make_starter(n
, &n
->control_pid
);
531 log_unit_warning_errno(UNIT(n
), r
, "Failed to fork 'making' task: %m");
535 busname_set_state(n
, BUSNAME_MAKING
);
537 /* If there is no policy, we can do everything
538 * directly from PID 1, hence do so. */
540 r
= bus_kernel_make_starter(n
->starter_fd
, n
->name
, n
->activating
, n
->accept_fd
, NULL
, n
->policy_world
);
542 log_unit_warning_errno(UNIT(n
), r
, "Failed to make starter: %m");
546 busname_enter_listening(n
);
552 busname_enter_dead(n
, BUSNAME_FAILURE_RESOURCES
);
555 static void busname_enter_running(BusName
*n
) {
556 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
557 bool pending
= false;
567 /* We don't take connections anymore if we are supposed to
568 * shut down anyway */
570 if (unit_stop_pending(UNIT(n
))) {
571 log_unit_debug(UNIT(n
), "Suppressing activation request since unit stop is scheduled.");
573 /* Flush all queued activation reqeuest by closing and reopening the connection */
574 bus_kernel_drop_one(n
->starter_fd
);
576 busname_enter_listening(n
);
580 /* If there's already a start pending don't bother to do
582 SET_FOREACH(other
, UNIT(n
)->dependencies
[UNIT_TRIGGERS
], i
)
583 if (unit_active_or_pending(other
)) {
589 if (!UNIT_ISSET(n
->service
)) {
590 log_unit_error(UNIT(n
), "Service to activate vanished, refusing activation.");
595 r
= manager_add_job(UNIT(n
)->manager
, JOB_START
, UNIT_DEREF(n
->service
), JOB_REPLACE
, &error
, NULL
);
600 busname_set_state(n
, BUSNAME_RUNNING
);
604 log_unit_warning(UNIT(n
), "Failed to queue service startup job: %s", bus_error_message(&error
, r
));
605 busname_enter_dead(n
, BUSNAME_FAILURE_RESOURCES
);
608 static int busname_start(Unit
*u
) {
609 BusName
*n
= BUSNAME(u
);
614 /* We cannot fulfill this request right now, try again later
616 if (IN_SET(n
->state
, BUSNAME_SIGTERM
, BUSNAME_SIGKILL
))
620 if (n
->state
== BUSNAME_MAKING
)
623 if (n
->activating
&& UNIT_ISSET(n
->service
)) {
626 service
= SERVICE(UNIT_DEREF(n
->service
));
628 if (UNIT(service
)->load_state
!= UNIT_LOADED
) {
629 log_unit_error(u
, "Bus service %s not loaded, refusing.", UNIT(service
)->id
);
634 assert(IN_SET(n
->state
, BUSNAME_DEAD
, BUSNAME_FAILED
));
636 r
= unit_start_limit_test(u
);
638 busname_enter_dead(n
, BUSNAME_FAILURE_START_LIMIT_HIT
);
642 r
= unit_acquire_invocation_id(u
);
646 n
->result
= BUSNAME_SUCCESS
;
647 busname_enter_making(n
);
652 static int busname_stop(Unit
*u
) {
653 BusName
*n
= BUSNAME(u
);
658 if (IN_SET(n
->state
, BUSNAME_SIGTERM
, BUSNAME_SIGKILL
))
661 /* If there's already something running, we go directly into
664 if (n
->state
== BUSNAME_MAKING
) {
665 busname_enter_signal(n
, BUSNAME_SIGTERM
, BUSNAME_SUCCESS
);
669 assert(IN_SET(n
->state
, BUSNAME_REGISTERED
, BUSNAME_LISTENING
, BUSNAME_RUNNING
));
671 busname_enter_dead(n
, BUSNAME_SUCCESS
);
675 static int busname_serialize(Unit
*u
, FILE *f
, FDSet
*fds
) {
676 BusName
*n
= BUSNAME(u
);
683 unit_serialize_item(u
, f
, "state", busname_state_to_string(n
->state
));
684 unit_serialize_item(u
, f
, "result", busname_result_to_string(n
->result
));
686 if (n
->control_pid
> 0)
687 unit_serialize_item_format(u
, f
, "control-pid", PID_FMT
, n
->control_pid
);
689 r
= unit_serialize_item_fd(u
, f
, fds
, "starter-fd", n
->starter_fd
);
696 static int busname_deserialize_item(Unit
*u
, const char *key
, const char *value
, FDSet
*fds
) {
697 BusName
*n
= BUSNAME(u
);
703 if (streq(key
, "state")) {
706 state
= busname_state_from_string(value
);
708 log_unit_debug(u
, "Failed to parse state value: %s", value
);
710 n
->deserialized_state
= state
;
712 } else if (streq(key
, "result")) {
715 f
= busname_result_from_string(value
);
717 log_unit_debug(u
, "Failed to parse result value: %s", value
);
718 else if (f
!= BUSNAME_SUCCESS
)
721 } else if (streq(key
, "control-pid")) {
724 if (parse_pid(value
, &pid
) < 0)
725 log_unit_debug(u
, "Failed to parse control-pid value: %s", value
);
727 n
->control_pid
= pid
;
728 } else if (streq(key
, "starter-fd")) {
731 if (safe_atoi(value
, &fd
) < 0 || fd
< 0 || !fdset_contains(fds
, fd
))
732 log_unit_debug(u
, "Failed to parse starter fd value: %s", value
);
734 safe_close(n
->starter_fd
);
735 n
->starter_fd
= fdset_remove(fds
, fd
);
738 log_unit_debug(u
, "Unknown serialization key: %s", key
);
743 _pure_
static UnitActiveState
busname_active_state(Unit
*u
) {
746 return state_translation_table
[BUSNAME(u
)->state
];
749 _pure_
static const char *busname_sub_state_to_string(Unit
*u
) {
752 return busname_state_to_string(BUSNAME(u
)->state
);
755 static int busname_peek_message(BusName
*n
) {
756 struct kdbus_cmd_recv cmd_recv
= {
757 .size
= sizeof(cmd_recv
),
758 .flags
= KDBUS_RECV_PEEK
,
760 struct kdbus_cmd_free cmd_free
= {
761 .size
= sizeof(cmd_free
),
763 const char *comm
= NULL
;
764 struct kdbus_item
*d
;
766 size_t start
, ps
, sz
, delta
;
771 /* Generate a friendly debug log message about which process
772 * caused triggering of this bus name. This simply peeks the
773 * metadata of the first queued message and logs it. */
777 /* Let's shortcut things a bit, if debug logging is turned off
780 if (log_get_max_level() < LOG_DEBUG
)
783 r
= ioctl(n
->starter_fd
, KDBUS_CMD_RECV
, &cmd_recv
);
785 if (errno
== EINTR
|| errno
== EAGAIN
)
788 return log_unit_error_errno(UNIT(n
), errno
, "Failed to query activation message: %m");
791 /* We map as late as possible, and unmap imemdiately after
792 * use. On 32bit address space is scarce and we want to be
793 * able to handle a lot of activator connections at the same
794 * time, and hence shouldn't keep the mmap()s around for
795 * longer than necessary. */
798 start
= (cmd_recv
.msg
.offset
/ ps
) * ps
;
799 delta
= cmd_recv
.msg
.offset
- start
;
800 sz
= PAGE_ALIGN(delta
+ cmd_recv
.msg
.msg_size
);
802 p
= mmap(NULL
, sz
, PROT_READ
, MAP_SHARED
, n
->starter_fd
, start
);
803 if (p
== MAP_FAILED
) {
804 r
= log_unit_error_errno(UNIT(n
), errno
, "Failed to map activation message: %m");
808 k
= (struct kdbus_msg
*) ((uint8_t *) p
+ delta
);
809 KDBUS_ITEM_FOREACH(d
, k
, items
) {
812 case KDBUS_ITEM_PIDS
:
816 case KDBUS_ITEM_PID_COMM
:
823 log_unit_debug(UNIT(n
), "Activation triggered by process " PID_FMT
" (%s)", pid
, strna(comm
));
829 (void) munmap(p
, sz
);
831 cmd_free
.offset
= cmd_recv
.msg
.offset
;
832 if (ioctl(n
->starter_fd
, KDBUS_CMD_FREE
, &cmd_free
) < 0)
833 log_unit_warning(UNIT(n
), "Failed to free peeked message, ignoring: %m");
838 static int busname_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
) {
839 BusName
*n
= userdata
;
844 if (n
->state
!= BUSNAME_LISTENING
)
847 log_unit_debug(UNIT(n
), "Activation request");
849 if (revents
!= EPOLLIN
) {
850 log_unit_error(UNIT(n
), "Got unexpected poll event (0x%x) on starter fd.", revents
);
854 busname_peek_message(n
);
855 busname_enter_running(n
);
859 busname_enter_dead(n
, BUSNAME_FAILURE_RESOURCES
);
863 static void busname_sigchld_event(Unit
*u
, pid_t pid
, int code
, int status
) {
864 BusName
*n
= BUSNAME(u
);
870 if (pid
!= n
->control_pid
)
875 if (is_clean_exit(code
, status
, NULL
))
877 else if (code
== CLD_EXITED
)
878 f
= BUSNAME_FAILURE_EXIT_CODE
;
879 else if (code
== CLD_KILLED
)
880 f
= BUSNAME_FAILURE_SIGNAL
;
881 else if (code
== CLD_DUMPED
)
882 f
= BUSNAME_FAILURE_CORE_DUMP
;
884 assert_not_reached("Unknown sigchld code");
886 log_unit_full(u
, f
== BUSNAME_SUCCESS
? LOG_DEBUG
: LOG_NOTICE
, 0,
887 "Control process exited, code=%s status=%i", sigchld_code_to_string(code
), status
);
889 if (n
->result
== BUSNAME_SUCCESS
)
895 if (f
== BUSNAME_SUCCESS
)
896 busname_enter_listening(n
);
898 busname_enter_signal(n
, BUSNAME_SIGTERM
, f
);
901 case BUSNAME_SIGTERM
:
902 case BUSNAME_SIGKILL
:
903 busname_enter_dead(n
, f
);
907 assert_not_reached("Uh, control process died at wrong time.");
910 /* Notify clients about changed exit status */
911 unit_add_to_dbus_queue(u
);
914 static int busname_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
) {
915 BusName
*n
= BUSNAME(userdata
);
918 assert(n
->timer_event_source
== source
);
923 log_unit_warning(UNIT(n
), "Making timed out. Terminating.");
924 busname_enter_signal(n
, BUSNAME_SIGTERM
, BUSNAME_FAILURE_TIMEOUT
);
927 case BUSNAME_SIGTERM
:
928 log_unit_warning(UNIT(n
), "Stopping timed out. Killing.");
929 busname_enter_signal(n
, BUSNAME_SIGKILL
, BUSNAME_FAILURE_TIMEOUT
);
932 case BUSNAME_SIGKILL
:
933 log_unit_warning(UNIT(n
), "Processes still around after SIGKILL. Ignoring.");
934 busname_enter_dead(n
, BUSNAME_FAILURE_TIMEOUT
);
938 assert_not_reached("Timeout at wrong time.");
944 static void busname_reset_failed(Unit
*u
) {
945 BusName
*n
= BUSNAME(u
);
949 if (n
->state
== BUSNAME_FAILED
)
950 busname_set_state(n
, BUSNAME_DEAD
);
952 n
->result
= BUSNAME_SUCCESS
;
955 static void busname_trigger_notify(Unit
*u
, Unit
*other
) {
956 BusName
*n
= BUSNAME(u
);
961 if (!IN_SET(n
->state
, BUSNAME_RUNNING
, BUSNAME_LISTENING
))
964 if (other
->start_limit_hit
) {
965 busname_enter_dead(n
, BUSNAME_FAILURE_SERVICE_START_LIMIT_HIT
);
969 if (other
->load_state
!= UNIT_LOADED
|| other
->type
!= UNIT_SERVICE
)
972 if (IN_SET(SERVICE(other
)->state
,
973 SERVICE_DEAD
, SERVICE_FAILED
,
974 SERVICE_FINAL_SIGTERM
, SERVICE_FINAL_SIGKILL
,
975 SERVICE_AUTO_RESTART
))
976 busname_enter_listening(n
);
978 if (SERVICE(other
)->state
== SERVICE_RUNNING
)
979 busname_set_state(n
, BUSNAME_RUNNING
);
982 static int busname_kill(Unit
*u
, KillWho who
, int signo
, sd_bus_error
*error
) {
983 return unit_kill_common(u
, who
, signo
, -1, BUSNAME(u
)->control_pid
, error
);
986 static int busname_get_timeout(Unit
*u
, usec_t
*timeout
) {
987 BusName
*n
= BUSNAME(u
);
991 if (!n
->timer_event_source
)
994 r
= sd_event_source_get_time(n
->timer_event_source
, &t
);
997 if (t
== USEC_INFINITY
)
1004 static bool busname_supported(void) {
1008 static int busname_control_pid(Unit
*u
) {
1009 BusName
*n
= BUSNAME(u
);
1013 return n
->control_pid
;
1016 static const char* const busname_result_table
[_BUSNAME_RESULT_MAX
] = {
1017 [BUSNAME_SUCCESS
] = "success",
1018 [BUSNAME_FAILURE_RESOURCES
] = "resources",
1019 [BUSNAME_FAILURE_TIMEOUT
] = "timeout",
1020 [BUSNAME_FAILURE_EXIT_CODE
] = "exit-code",
1021 [BUSNAME_FAILURE_SIGNAL
] = "signal",
1022 [BUSNAME_FAILURE_CORE_DUMP
] = "core-dump",
1023 [BUSNAME_FAILURE_START_LIMIT_HIT
] = "start-limit-hit",
1024 [BUSNAME_FAILURE_SERVICE_START_LIMIT_HIT
] = "service-start-limit-hit",
1027 DEFINE_STRING_TABLE_LOOKUP(busname_result
, BusNameResult
);
1029 const UnitVTable busname_vtable
= {
1030 .object_size
= sizeof(BusName
),
1036 .private_section
= "BusName",
1038 .init
= busname_init
,
1039 .done
= busname_done
,
1040 .load
= busname_load
,
1042 .coldplug
= busname_coldplug
,
1044 .dump
= busname_dump
,
1046 .start
= busname_start
,
1047 .stop
= busname_stop
,
1049 .kill
= busname_kill
,
1051 .get_timeout
= busname_get_timeout
,
1053 .serialize
= busname_serialize
,
1054 .deserialize_item
= busname_deserialize_item
,
1056 .active_state
= busname_active_state
,
1057 .sub_state_to_string
= busname_sub_state_to_string
,
1059 .sigchld_event
= busname_sigchld_event
,
1061 .trigger_notify
= busname_trigger_notify
,
1063 .reset_failed
= busname_reset_failed
,
1065 .supported
= busname_supported
,
1067 .control_pid
= busname_control_pid
,
1069 .bus_vtable
= bus_busname_vtable
,
1071 .status_message_formats
= {
1072 .finished_start_job
= {
1073 [JOB_DONE
] = "Listening on %s.",
1074 [JOB_FAILED
] = "Failed to listen on %s.",
1076 .finished_stop_job
= {
1077 [JOB_DONE
] = "Closed %s.",
1078 [JOB_FAILED
] = "Failed stopping %s.",