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/>.
25 #include "bus-kernel.h"
26 #include "bus-internal.h"
30 #include "bus-policy.h"
31 #include "dbus-busname.h"
33 #include "formats-util.h"
35 static const UnitActiveState state_translation_table
[_BUSNAME_STATE_MAX
] = {
36 [BUSNAME_DEAD
] = UNIT_INACTIVE
,
37 [BUSNAME_MAKING
] = UNIT_ACTIVATING
,
38 [BUSNAME_REGISTERED
] = UNIT_ACTIVE
,
39 [BUSNAME_LISTENING
] = UNIT_ACTIVE
,
40 [BUSNAME_RUNNING
] = UNIT_ACTIVE
,
41 [BUSNAME_SIGTERM
] = UNIT_DEACTIVATING
,
42 [BUSNAME_SIGKILL
] = UNIT_DEACTIVATING
,
43 [BUSNAME_FAILED
] = UNIT_FAILED
46 static int busname_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
);
47 static int busname_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
);
49 static void busname_init(Unit
*u
) {
50 BusName
*n
= BUSNAME(u
);
53 assert(u
->load_state
== UNIT_STUB
);
59 n
->timeout_usec
= u
->manager
->default_timeout_start_usec
;
62 static void busname_unwatch_control_pid(BusName
*n
) {
65 if (n
->control_pid
<= 0)
68 unit_unwatch_pid(UNIT(n
), n
->control_pid
);
72 static void busname_free_policy(BusName
*n
) {
77 while ((p
= n
->policy
)) {
78 LIST_REMOVE(policy
, n
->policy
, p
);
85 static void busname_close_fd(BusName
*n
) {
88 n
->starter_event_source
= sd_event_source_unref(n
->starter_event_source
);
89 n
->starter_fd
= safe_close(n
->starter_fd
);
92 static void busname_done(Unit
*u
) {
93 BusName
*n
= BUSNAME(u
);
100 busname_free_policy(n
);
101 busname_unwatch_control_pid(n
);
104 unit_ref_unset(&n
->service
);
106 n
->timer_event_source
= sd_event_source_unref(n
->timer_event_source
);
109 static int busname_arm_timer(BusName
*n
) {
114 if (n
->timeout_usec
<= 0) {
115 n
->timer_event_source
= sd_event_source_unref(n
->timer_event_source
);
119 if (n
->timer_event_source
) {
120 r
= sd_event_source_set_time(n
->timer_event_source
, now(CLOCK_MONOTONIC
) + n
->timeout_usec
);
124 return sd_event_source_set_enabled(n
->timer_event_source
, SD_EVENT_ONESHOT
);
127 r
= sd_event_add_time(
128 UNIT(n
)->manager
->event
,
129 &n
->timer_event_source
,
131 now(CLOCK_MONOTONIC
) + n
->timeout_usec
, 0,
132 busname_dispatch_timer
, n
);
136 (void) sd_event_source_set_description(n
->timer_event_source
, "busname-timer");
141 static int busname_add_default_default_dependencies(BusName
*n
) {
146 r
= unit_add_dependency_by_name(UNIT(n
), UNIT_BEFORE
, SPECIAL_BUSNAMES_TARGET
, NULL
, true);
150 if (UNIT(n
)->manager
->running_as
== SYSTEMD_SYSTEM
) {
151 r
= unit_add_two_dependencies_by_name(UNIT(n
), UNIT_AFTER
, UNIT_REQUIRES
, SPECIAL_SYSINIT_TARGET
, NULL
, true);
156 return unit_add_two_dependencies_by_name(UNIT(n
), UNIT_BEFORE
, UNIT_CONFLICTS
, SPECIAL_SHUTDOWN_TARGET
, NULL
, true);
159 static int busname_add_extras(BusName
*n
) {
166 r
= unit_name_to_prefix(u
->id
, &n
->name
);
171 if (!u
->description
) {
172 r
= unit_set_description(u
, n
->name
);
178 if (!UNIT_DEREF(n
->service
)) {
181 r
= unit_load_related_unit(u
, ".service", &x
);
185 unit_ref_set(&n
->service
, x
);
188 r
= unit_add_two_dependencies(u
, UNIT_BEFORE
, UNIT_TRIGGERS
, UNIT_DEREF(n
->service
), true);
193 if (u
->default_dependencies
) {
194 r
= busname_add_default_default_dependencies(n
);
202 static int busname_verify(BusName
*n
) {
207 if (UNIT(n
)->load_state
!= UNIT_LOADED
)
210 if (!service_name_is_valid(n
->name
)) {
211 log_unit_error(UNIT(n
), "Name= setting is not a valid service name Refusing.");
215 e
= strjoina(n
->name
, ".busname");
216 if (!unit_has_name(UNIT(n
), e
)) {
217 log_unit_error(UNIT(n
), "Name= setting doesn't match unit name. Refusing.");
224 static int busname_load(Unit
*u
) {
225 BusName
*n
= BUSNAME(u
);
229 assert(u
->load_state
== UNIT_STUB
);
231 r
= unit_load_fragment_and_dropin(u
);
235 if (u
->load_state
== UNIT_LOADED
) {
236 /* This is a new unit? Then let's add in some extras */
237 r
= busname_add_extras(n
);
242 return busname_verify(n
);
245 static void busname_dump(Unit
*u
, FILE *f
, const char *prefix
) {
246 BusName
*n
= BUSNAME(u
);
252 "%sBus Name State: %s\n"
257 prefix
, busname_state_to_string(n
->state
),
258 prefix
, busname_result_to_string(n
->result
),
260 prefix
, yes_no(n
->activating
),
261 prefix
, yes_no(n
->accept_fd
));
263 if (n
->control_pid
> 0)
265 "%sControl PID: "PID_FMT
"\n",
266 prefix
, n
->control_pid
);
269 static void busname_unwatch_fd(BusName
*n
) {
274 if (!n
->starter_event_source
)
277 r
= sd_event_source_set_enabled(n
->starter_event_source
, SD_EVENT_OFF
);
279 log_unit_debug_errno(UNIT(n
), r
, "Failed to disable event source: %m");
282 static int busname_watch_fd(BusName
*n
) {
287 if (n
->starter_fd
< 0)
290 if (n
->starter_event_source
)
291 r
= sd_event_source_set_enabled(n
->starter_event_source
, SD_EVENT_ON
);
293 r
= sd_event_add_io(UNIT(n
)->manager
->event
, &n
->starter_event_source
, n
->starter_fd
, EPOLLIN
, busname_dispatch_io
, n
);
296 log_unit_warning_errno(UNIT(n
), r
, "Failed to watch starter fd: %m");
297 busname_unwatch_fd(n
);
301 (void) sd_event_source_set_description(n
->starter_event_source
, "busname-starter");
306 static int busname_open_fd(BusName
*n
) {
307 _cleanup_free_
char *path
= NULL
;
312 if (n
->starter_fd
>= 0)
315 mode
= UNIT(n
)->manager
->running_as
== SYSTEMD_SYSTEM
? "system" : "user";
316 n
->starter_fd
= bus_kernel_open_bus_fd(mode
, &path
);
317 if (n
->starter_fd
< 0)
318 return log_unit_warning_errno(UNIT(n
), n
->starter_fd
, "Failed to open %s: %m", path
?: "kdbus");
323 static void busname_set_state(BusName
*n
, BusNameState state
) {
324 BusNameState old_state
;
327 old_state
= n
->state
;
330 if (!IN_SET(state
, BUSNAME_MAKING
, BUSNAME_SIGTERM
, BUSNAME_SIGKILL
)) {
331 n
->timer_event_source
= sd_event_source_unref(n
->timer_event_source
);
332 busname_unwatch_control_pid(n
);
335 if (state
!= BUSNAME_LISTENING
)
336 busname_unwatch_fd(n
);
338 if (!IN_SET(state
, BUSNAME_LISTENING
, BUSNAME_MAKING
, BUSNAME_REGISTERED
, BUSNAME_RUNNING
))
341 if (state
!= old_state
)
342 log_unit_debug(UNIT(n
), "Changed %s -> %s", busname_state_to_string(old_state
), busname_state_to_string(state
));
344 unit_notify(UNIT(n
), state_translation_table
[old_state
], state_translation_table
[state
], true);
347 static int busname_coldplug(Unit
*u
) {
348 BusName
*n
= BUSNAME(u
);
352 assert(n
->state
== BUSNAME_DEAD
);
354 if (n
->deserialized_state
== n
->state
)
357 if (IN_SET(n
->deserialized_state
, BUSNAME_MAKING
, BUSNAME_SIGTERM
, BUSNAME_SIGKILL
)) {
359 if (n
->control_pid
<= 0)
362 r
= unit_watch_pid(UNIT(n
), n
->control_pid
);
366 r
= busname_arm_timer(n
);
371 if (IN_SET(n
->deserialized_state
, BUSNAME_MAKING
, BUSNAME_LISTENING
, BUSNAME_REGISTERED
, BUSNAME_RUNNING
)) {
372 r
= busname_open_fd(n
);
377 if (n
->deserialized_state
== BUSNAME_LISTENING
) {
378 r
= busname_watch_fd(n
);
383 busname_set_state(n
, n
->deserialized_state
);
387 static int busname_make_starter(BusName
*n
, pid_t
*_pid
) {
391 r
= busname_arm_timer(n
);
395 /* We have to resolve the user/group names out-of-process,
396 * hence let's fork here. It's messy, but well, what can we
406 default_signals(SIGNALS_CRASH_HANDLER
, SIGNALS_IGNORE
, -1);
407 ignore_signals(SIGPIPE
, -1);
410 r
= bus_kernel_make_starter(n
->starter_fd
, n
->name
, n
->activating
, n
->accept_fd
, n
->policy
, n
->policy_world
);
412 ret
= EXIT_MAKE_STARTER
;
420 log_error_errno(r
, "Failed to create starter connection at step %s: %m", exit_status_to_string(ret
, EXIT_STATUS_SYSTEMD
));
425 r
= unit_watch_pid(UNIT(n
), pid
);
433 n
->timer_event_source
= sd_event_source_unref(n
->timer_event_source
);
437 static void busname_enter_dead(BusName
*n
, BusNameResult f
) {
440 if (f
!= BUSNAME_SUCCESS
)
443 busname_set_state(n
, n
->result
!= BUSNAME_SUCCESS
? BUSNAME_FAILED
: BUSNAME_DEAD
);
446 static void busname_enter_signal(BusName
*n
, BusNameState state
, BusNameResult f
) {
447 KillContext kill_context
= {};
452 if (f
!= BUSNAME_SUCCESS
)
455 kill_context_init(&kill_context
);
457 r
= unit_kill_context(UNIT(n
),
459 state
!= BUSNAME_SIGTERM
? KILL_KILL
: KILL_TERMINATE
,
464 log_unit_warning_errno(UNIT(n
), r
, "Failed to kill control process: %m");
469 r
= busname_arm_timer(n
);
471 log_unit_warning_errno(UNIT(n
), r
, "Failed to arm timer: %m");
475 busname_set_state(n
, state
);
476 } else if (state
== BUSNAME_SIGTERM
)
477 busname_enter_signal(n
, BUSNAME_SIGKILL
, BUSNAME_SUCCESS
);
479 busname_enter_dead(n
, BUSNAME_SUCCESS
);
484 busname_enter_dead(n
, BUSNAME_FAILURE_RESOURCES
);
487 static void busname_enter_listening(BusName
*n
) {
493 r
= busname_watch_fd(n
);
495 log_unit_warning_errno(UNIT(n
), r
, "Failed to watch names: %m");
499 busname_set_state(n
, BUSNAME_LISTENING
);
501 busname_set_state(n
, BUSNAME_REGISTERED
);
506 busname_enter_signal(n
, BUSNAME_SIGTERM
, BUSNAME_FAILURE_RESOURCES
);
509 static void busname_enter_making(BusName
*n
) {
514 r
= busname_open_fd(n
);
519 /* If there is a policy, we need to resolve user/group
520 * names, which we can't do from PID1, hence let's
522 busname_unwatch_control_pid(n
);
524 r
= busname_make_starter(n
, &n
->control_pid
);
526 log_unit_warning_errno(UNIT(n
), r
, "Failed to fork 'making' task: %m");
530 busname_set_state(n
, BUSNAME_MAKING
);
532 /* If there is no policy, we can do everything
533 * directly from PID 1, hence do so. */
535 r
= bus_kernel_make_starter(n
->starter_fd
, n
->name
, n
->activating
, n
->accept_fd
, NULL
, n
->policy_world
);
537 log_unit_warning_errno(UNIT(n
), r
, "Failed to make starter: %m");
541 busname_enter_listening(n
);
547 busname_enter_dead(n
, BUSNAME_FAILURE_RESOURCES
);
550 static void busname_enter_running(BusName
*n
) {
551 _cleanup_bus_error_free_ sd_bus_error error
= SD_BUS_ERROR_NULL
;
552 bool pending
= false;
562 /* We don't take connections anymore if we are supposed to
563 * shut down anyway */
565 if (unit_stop_pending(UNIT(n
))) {
566 log_unit_debug(UNIT(n
), "Suppressing activation request since unit stop is scheduled.");
568 /* Flush all queued activation reqeuest by closing and reopening the connection */
569 bus_kernel_drop_one(n
->starter_fd
);
571 busname_enter_listening(n
);
575 /* If there's already a start pending don't bother to do
577 SET_FOREACH(other
, UNIT(n
)->dependencies
[UNIT_TRIGGERS
], i
)
578 if (unit_active_or_pending(other
)) {
584 r
= manager_add_job(UNIT(n
)->manager
, JOB_START
, UNIT_DEREF(n
->service
), JOB_REPLACE
, true, &error
, NULL
);
589 busname_set_state(n
, BUSNAME_RUNNING
);
593 log_unit_warning(UNIT(n
), "Failed to queue service startup job: %s", bus_error_message(&error
, r
));
594 busname_enter_dead(n
, BUSNAME_FAILURE_RESOURCES
);
597 static int busname_start(Unit
*u
) {
598 BusName
*n
= BUSNAME(u
);
602 /* We cannot fulfill this request right now, try again later
604 if (IN_SET(n
->state
, BUSNAME_SIGTERM
, BUSNAME_SIGKILL
))
608 if (n
->state
== BUSNAME_MAKING
)
611 if (n
->activating
&& UNIT_ISSET(n
->service
)) {
614 service
= SERVICE(UNIT_DEREF(n
->service
));
616 if (UNIT(service
)->load_state
!= UNIT_LOADED
) {
617 log_unit_error(u
, "Bus service %s not loaded, refusing.", UNIT(service
)->id
);
622 assert(IN_SET(n
->state
, BUSNAME_DEAD
, BUSNAME_FAILED
));
624 n
->result
= BUSNAME_SUCCESS
;
625 busname_enter_making(n
);
630 static int busname_stop(Unit
*u
) {
631 BusName
*n
= BUSNAME(u
);
636 if (IN_SET(n
->state
, BUSNAME_SIGTERM
, BUSNAME_SIGKILL
))
639 /* If there's already something running, we go directly into
642 if (n
->state
== BUSNAME_MAKING
) {
643 busname_enter_signal(n
, BUSNAME_SIGTERM
, BUSNAME_SUCCESS
);
647 assert(IN_SET(n
->state
, BUSNAME_REGISTERED
, BUSNAME_LISTENING
, BUSNAME_RUNNING
));
649 busname_enter_dead(n
, BUSNAME_SUCCESS
);
653 static int busname_serialize(Unit
*u
, FILE *f
, FDSet
*fds
) {
654 BusName
*n
= BUSNAME(u
);
660 unit_serialize_item(u
, f
, "state", busname_state_to_string(n
->state
));
661 unit_serialize_item(u
, f
, "result", busname_result_to_string(n
->result
));
663 if (n
->control_pid
> 0)
664 unit_serialize_item_format(u
, f
, "control-pid", PID_FMT
, n
->control_pid
);
666 if (n
->starter_fd
>= 0) {
669 copy
= fdset_put_dup(fds
, n
->starter_fd
);
673 unit_serialize_item_format(u
, f
, "starter-fd", "%i", copy
);
679 static int busname_deserialize_item(Unit
*u
, const char *key
, const char *value
, FDSet
*fds
) {
680 BusName
*n
= BUSNAME(u
);
686 if (streq(key
, "state")) {
689 state
= busname_state_from_string(value
);
691 log_unit_debug(u
, "Failed to parse state value: %s", value
);
693 n
->deserialized_state
= state
;
695 } else if (streq(key
, "result")) {
698 f
= busname_result_from_string(value
);
700 log_unit_debug(u
, "Failed to parse result value: %s", value
);
701 else if (f
!= BUSNAME_SUCCESS
)
704 } else if (streq(key
, "control-pid")) {
707 if (parse_pid(value
, &pid
) < 0)
708 log_unit_debug(u
, "Failed to parse control-pid value: %s", value
);
710 n
->control_pid
= pid
;
711 } else if (streq(key
, "starter-fd")) {
714 if (safe_atoi(value
, &fd
) < 0 || fd
< 0 || !fdset_contains(fds
, fd
))
715 log_unit_debug(u
, "Failed to parse starter fd value: %s", value
);
717 safe_close(n
->starter_fd
);
718 n
->starter_fd
= fdset_remove(fds
, fd
);
721 log_unit_debug(u
, "Unknown serialization key: %s", key
);
726 _pure_
static UnitActiveState
busname_active_state(Unit
*u
) {
729 return state_translation_table
[BUSNAME(u
)->state
];
732 _pure_
static const char *busname_sub_state_to_string(Unit
*u
) {
735 return busname_state_to_string(BUSNAME(u
)->state
);
738 static int busname_peek_message(BusName
*n
) {
739 struct kdbus_cmd_recv cmd_recv
= {
740 .size
= sizeof(cmd_recv
),
741 .flags
= KDBUS_RECV_PEEK
,
743 struct kdbus_cmd_free cmd_free
= {
744 .size
= sizeof(cmd_free
),
746 const char *comm
= NULL
;
747 struct kdbus_item
*d
;
749 size_t start
, ps
, sz
, delta
;
754 /* Generate a friendly debug log message about which process
755 * caused triggering of this bus name. This simply peeks the
756 * metadata of the first queued message and logs it. */
760 /* Let's shortcut things a bit, if debug logging is turned off
763 if (log_get_max_level() < LOG_DEBUG
)
766 r
= ioctl(n
->starter_fd
, KDBUS_CMD_RECV
, &cmd_recv
);
768 if (errno
== EINTR
|| errno
== EAGAIN
)
771 return log_unit_error_errno(UNIT(n
), errno
, "Failed to query activation message: %m");
774 /* We map as late as possible, and unmap imemdiately after
775 * use. On 32bit address space is scarce and we want to be
776 * able to handle a lot of activator connections at the same
777 * time, and hence shouldn't keep the mmap()s around for
778 * longer than necessary. */
781 start
= (cmd_recv
.msg
.offset
/ ps
) * ps
;
782 delta
= cmd_recv
.msg
.offset
- start
;
783 sz
= PAGE_ALIGN(delta
+ cmd_recv
.msg
.msg_size
);
785 p
= mmap(NULL
, sz
, PROT_READ
, MAP_SHARED
, n
->starter_fd
, start
);
786 if (p
== MAP_FAILED
) {
787 r
= log_unit_error_errno(UNIT(n
), errno
, "Failed to map activation message: %m");
791 k
= (struct kdbus_msg
*) ((uint8_t *) p
+ delta
);
792 KDBUS_ITEM_FOREACH(d
, k
, items
) {
795 case KDBUS_ITEM_PIDS
:
799 case KDBUS_ITEM_PID_COMM
:
806 log_unit_debug(UNIT(n
), "Activation triggered by process " PID_FMT
" (%s)", pid
, strna(comm
));
812 (void) munmap(p
, sz
);
814 cmd_free
.offset
= cmd_recv
.msg
.offset
;
815 if (ioctl(n
->starter_fd
, KDBUS_CMD_FREE
, &cmd_free
) < 0)
816 log_unit_warning(UNIT(n
), "Failed to free peeked message, ignoring: %m");
821 static int busname_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
) {
822 BusName
*n
= userdata
;
827 if (n
->state
!= BUSNAME_LISTENING
)
830 log_unit_debug(UNIT(n
), "Activation request");
832 if (revents
!= EPOLLIN
) {
833 log_unit_error(UNIT(n
), "Got unexpected poll event (0x%x) on starter fd.", revents
);
837 busname_peek_message(n
);
838 busname_enter_running(n
);
842 busname_enter_dead(n
, BUSNAME_FAILURE_RESOURCES
);
846 static void busname_sigchld_event(Unit
*u
, pid_t pid
, int code
, int status
) {
847 BusName
*n
= BUSNAME(u
);
853 if (pid
!= n
->control_pid
)
858 if (is_clean_exit(code
, status
, NULL
))
860 else if (code
== CLD_EXITED
)
861 f
= BUSNAME_FAILURE_EXIT_CODE
;
862 else if (code
== CLD_KILLED
)
863 f
= BUSNAME_FAILURE_SIGNAL
;
864 else if (code
== CLD_DUMPED
)
865 f
= BUSNAME_FAILURE_CORE_DUMP
;
867 assert_not_reached("Unknown sigchld code");
869 log_unit_full(u
, f
== BUSNAME_SUCCESS
? LOG_DEBUG
: LOG_NOTICE
, 0,
870 "Control process exited, code=%s status=%i", sigchld_code_to_string(code
), status
);
872 if (f
!= BUSNAME_SUCCESS
)
878 if (f
== BUSNAME_SUCCESS
)
879 busname_enter_listening(n
);
881 busname_enter_signal(n
, BUSNAME_SIGTERM
, f
);
884 case BUSNAME_SIGTERM
:
885 case BUSNAME_SIGKILL
:
886 busname_enter_dead(n
, f
);
890 assert_not_reached("Uh, control process died at wrong time.");
893 /* Notify clients about changed exit status */
894 unit_add_to_dbus_queue(u
);
897 static int busname_dispatch_timer(sd_event_source
*source
, usec_t usec
, void *userdata
) {
898 BusName
*n
= BUSNAME(userdata
);
901 assert(n
->timer_event_source
== source
);
906 log_unit_warning(UNIT(n
), "Making timed out. Terminating.");
907 busname_enter_signal(n
, BUSNAME_SIGTERM
, BUSNAME_FAILURE_TIMEOUT
);
910 case BUSNAME_SIGTERM
:
911 log_unit_warning(UNIT(n
), "Stopping timed out. Killing.");
912 busname_enter_signal(n
, BUSNAME_SIGKILL
, BUSNAME_FAILURE_TIMEOUT
);
915 case BUSNAME_SIGKILL
:
916 log_unit_warning(UNIT(n
), "Processes still around after SIGKILL. Ignoring.");
917 busname_enter_dead(n
, BUSNAME_FAILURE_TIMEOUT
);
921 assert_not_reached("Timeout at wrong time.");
927 static void busname_reset_failed(Unit
*u
) {
928 BusName
*n
= BUSNAME(u
);
932 if (n
->state
== BUSNAME_FAILED
)
933 busname_set_state(n
, BUSNAME_DEAD
);
935 n
->result
= BUSNAME_SUCCESS
;
938 static void busname_trigger_notify(Unit
*u
, Unit
*other
) {
939 BusName
*n
= BUSNAME(u
);
945 if (!IN_SET(n
->state
, BUSNAME_RUNNING
, BUSNAME_LISTENING
))
948 if (other
->load_state
!= UNIT_LOADED
|| other
->type
!= UNIT_SERVICE
)
953 if (s
->state
== SERVICE_FAILED
&& s
->result
== SERVICE_FAILURE_START_LIMIT
)
954 busname_enter_dead(n
, BUSNAME_FAILURE_SERVICE_FAILED_PERMANENT
);
955 else if (IN_SET(s
->state
,
956 SERVICE_DEAD
, SERVICE_FAILED
,
957 SERVICE_STOP
, SERVICE_STOP_SIGTERM
, SERVICE_STOP_SIGKILL
,
958 SERVICE_STOP_POST
, SERVICE_FINAL_SIGTERM
, SERVICE_FINAL_SIGKILL
,
959 SERVICE_AUTO_RESTART
))
960 busname_enter_listening(n
);
963 static int busname_kill(Unit
*u
, KillWho who
, int signo
, sd_bus_error
*error
) {
964 return unit_kill_common(u
, who
, signo
, -1, BUSNAME(u
)->control_pid
, error
);
967 static int busname_get_timeout(Unit
*u
, uint64_t *timeout
) {
968 BusName
*n
= BUSNAME(u
);
971 if (!n
->timer_event_source
)
974 r
= sd_event_source_get_time(n
->timer_event_source
, timeout
);
981 static bool busname_supported(void) {
982 static int supported
= -1;
985 supported
= is_kdbus_available();
990 static const char* const busname_state_table
[_BUSNAME_STATE_MAX
] = {
991 [BUSNAME_DEAD
] = "dead",
992 [BUSNAME_MAKING
] = "making",
993 [BUSNAME_REGISTERED
] = "registered",
994 [BUSNAME_LISTENING
] = "listening",
995 [BUSNAME_RUNNING
] = "running",
996 [BUSNAME_SIGTERM
] = "sigterm",
997 [BUSNAME_SIGKILL
] = "sigkill",
998 [BUSNAME_FAILED
] = "failed",
1001 DEFINE_STRING_TABLE_LOOKUP(busname_state
, BusNameState
);
1003 static const char* const busname_result_table
[_BUSNAME_RESULT_MAX
] = {
1004 [BUSNAME_SUCCESS
] = "success",
1005 [BUSNAME_FAILURE_RESOURCES
] = "resources",
1006 [BUSNAME_FAILURE_TIMEOUT
] = "timeout",
1007 [BUSNAME_FAILURE_EXIT_CODE
] = "exit-code",
1008 [BUSNAME_FAILURE_SIGNAL
] = "signal",
1009 [BUSNAME_FAILURE_CORE_DUMP
] = "core-dump",
1010 [BUSNAME_FAILURE_SERVICE_FAILED_PERMANENT
] = "service-failed-permanent",
1013 DEFINE_STRING_TABLE_LOOKUP(busname_result
, BusNameResult
);
1015 const UnitVTable busname_vtable
= {
1016 .object_size
= sizeof(BusName
),
1022 .private_section
= "BusName",
1025 .no_instances
= true,
1027 .init
= busname_init
,
1028 .done
= busname_done
,
1029 .load
= busname_load
,
1031 .coldplug
= busname_coldplug
,
1033 .dump
= busname_dump
,
1035 .start
= busname_start
,
1036 .stop
= busname_stop
,
1038 .kill
= busname_kill
,
1040 .get_timeout
= busname_get_timeout
,
1042 .serialize
= busname_serialize
,
1043 .deserialize_item
= busname_deserialize_item
,
1045 .active_state
= busname_active_state
,
1046 .sub_state_to_string
= busname_sub_state_to_string
,
1048 .sigchld_event
= busname_sigchld_event
,
1050 .trigger_notify
= busname_trigger_notify
,
1052 .reset_failed
= busname_reset_failed
,
1054 .supported
= busname_supported
,
1056 .bus_interface
= "org.freedesktop.systemd1.BusName",
1057 .bus_vtable
= bus_busname_vtable
,
1059 .status_message_formats
= {
1060 .finished_start_job
= {
1061 [JOB_DONE
] = "Listening on %s.",
1062 [JOB_FAILED
] = "Failed to listen on %s.",
1063 [JOB_DEPENDENCY
] = "Dependency failed for %s.",
1064 [JOB_TIMEOUT
] = "Timed out starting %s.",
1066 .finished_stop_job
= {
1067 [JOB_DONE
] = "Closed %s.",
1068 [JOB_FAILED
] = "Failed stopping %s.",
1069 [JOB_TIMEOUT
] = "Timed out stopping %s.",