1 /* SPDX-License-Identifier: LGPL-2.1+ */
10 #include "alloc-util.h"
11 #include "bus-error.h"
15 static int help(void) {
17 printf("%s [COMMAND] [OPTIONS...]\n"
19 "Verify system operational state.\n\n"
20 " -h --help Show this help\n"
21 " --version Print version\n",
22 program_invocation_short_name
);
27 static int parse_argv(int argc
, char *argv
[]) {
33 static const struct option options
[] = {
34 { "help", no_argument
, NULL
, 'h' },
35 { "version", no_argument
, NULL
, ARG_VERSION
},
44 while ((c
= getopt_long(argc
, argv
, "h", options
, NULL
)) >= 0)
58 assert_not_reached("Unknown option");
64 int main(int argc
, char *argv
[]) {
65 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
66 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
70 log_parse_environment();
73 r
= parse_argv(argc
, argv
);
77 r
= sd_bus_open_system(&bus
);
79 log_error_errno(r
, "Failed to connect to system bus: %m");
83 r
= sd_bus_get_property_trivial(
85 "org.freedesktop.systemd1",
86 "/org/freedesktop/systemd1",
87 "org.freedesktop.systemd1.Manager",
93 log_error_errno(r
, "Failed to get failed units counter: %s", bus_error_message(&error
, r
));
98 log_notice("Health check: %" PRIu32
" units have failed.", n
);
100 log_info("Health check: no failed units.");
102 r
= n
> 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;
105 return r
< 0 ? EXIT_FAILURE
: r
;