1 /* SPDX-License-Identifier: LGPL-2.1+ */
10 #include "alloc-util.h"
11 #include "bus-error.h"
13 #include "main-func.h"
16 static int help(void) {
18 printf("%s [COMMAND] [OPTIONS...]\n"
20 "Verify system operational state.\n\n"
21 " -h --help Show this help\n"
22 " --version Print version\n",
23 program_invocation_short_name
);
28 static int parse_argv(int argc
, char *argv
[]) {
34 static const struct option options
[] = {
35 { "help", no_argument
, NULL
, 'h' },
36 { "version", no_argument
, NULL
, ARG_VERSION
},
45 while ((c
= getopt_long(argc
, argv
, "h", options
, NULL
)) >= 0)
59 assert_not_reached("Unknown option");
65 static int run(int argc
, char *argv
[]) {
66 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
67 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
71 log_parse_environment();
74 r
= parse_argv(argc
, argv
);
78 r
= sd_bus_open_system(&bus
);
80 return log_error_errno(r
, "Failed to connect to system bus: %m");
82 r
= sd_bus_get_property_trivial(
84 "org.freedesktop.systemd1",
85 "/org/freedesktop/systemd1",
86 "org.freedesktop.systemd1.Manager",
92 return log_error_errno(r
, "Failed to get failed units counter: %s", bus_error_message(&error
, r
));
95 log_notice("Health check: %" PRIu32
" units have failed.", n
);
97 log_info("Health check: no failed units.");
102 DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run
);