]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/systemctl/systemctl-is-system-running.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
6 #include "systemctl-util.h"
7 #include "systemctl-is-system-running.h"
11 #include "bus-locator.h"
12 #include "bus-error.h"
14 static int match_startup_finished(sd_bus_message
*m
, void *userdata
, sd_bus_error
*error
) {
15 char **state
= userdata
;
20 r
= bus_get_property_string(sd_bus_message_get_bus(m
), bus_systemd_mgr
, "SystemState", NULL
, state
);
22 sd_event_exit(sd_bus_get_event(sd_bus_message_get_bus(m
)), r
);
26 int is_system_running(int argc
, char *argv
[], void *userdata
) {
27 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
28 _cleanup_(sd_bus_slot_unrefp
) sd_bus_slot
*slot_startup_finished
= NULL
;
29 _cleanup_(sd_event_unrefp
) sd_event
* event
= NULL
;
30 _cleanup_free_
char *state
= NULL
;
34 if (running_in_chroot() > 0 || (arg_transport
== BUS_TRANSPORT_LOCAL
&& !sd_booted())) {
40 r
= acquire_bus(BUS_MANAGER
, &bus
);
45 r
= sd_event_default(&event
);
47 r
= sd_bus_attach_event(bus
, event
, 0);
49 r
= bus_match_signal_async(
51 &slot_startup_finished
,
54 match_startup_finished
, NULL
, &state
);
56 log_warning_errno(r
, "Failed to request match for StartupFinished: %m");
61 r
= bus_get_property_string(bus
, bus_systemd_mgr
, "SystemState", &error
, &state
);
63 log_warning_errno(r
, "Failed to query system state: %s", bus_error_message(&error
, r
));
70 if (arg_wait
&& STR_IN_SET(state
, "initializing", "starting")) {
71 r
= sd_event_loop(event
);
73 log_warning_errno(r
, "Failed to get property from event loop: %m");
83 return streq(state
, "running") ? EXIT_SUCCESS
: EXIT_FAILURE
;