1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
10 #include "alloc-util.h"
11 #include "bus-error.h"
13 #include "main-func.h"
14 #include "pretty-print.h"
15 #include "terminal-util.h"
18 static int help(void) {
19 _cleanup_free_
char *link
= NULL
;
22 r
= terminal_urlify_man("systemd-boot-check-no-failures.service", "8", &link
);
26 printf("%s [OPTIONS...]\n"
27 "\n%sVerify system operational state.%s\n\n"
28 " -h --help Show this help\n"
29 " --version Print version\n"
30 "\nSee the %s for details.\n"
31 , program_invocation_short_name
40 static int parse_argv(int argc
, char *argv
[]) {
46 static const struct option options
[] = {
47 { "help", no_argument
, NULL
, 'h' },
48 { "version", no_argument
, NULL
, ARG_VERSION
},
57 while ((c
= getopt_long(argc
, argv
, "h", options
, NULL
)) >= 0)
71 assert_not_reached("Unknown option");
77 static int run(int argc
, char *argv
[]) {
78 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
79 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
83 log_parse_environment();
86 r
= parse_argv(argc
, argv
);
90 r
= sd_bus_open_system(&bus
);
92 return log_error_errno(r
, "Failed to connect to system bus: %m");
94 r
= sd_bus_get_property_trivial(
96 "org.freedesktop.systemd1",
97 "/org/freedesktop/systemd1",
98 "org.freedesktop.systemd1.Manager",
104 return log_error_errno(r
, "Failed to get failed units counter: %s", bus_error_message(&error
, r
));
107 log_notice("Health check: %" PRIu32
" units have failed.", n
);
109 log_info("Health check: no failed units.");
114 DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run
);