mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-27 03:21:32 +03:00
inhibit: define main through macro
This commit is contained in:
parent
634a0ad3e5
commit
b453c447e0
@ -266,7 +266,7 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
static int run(int argc, char *argv[]) {
|
||||||
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
|
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
@ -274,23 +274,17 @@ int main(int argc, char *argv[]) {
|
|||||||
log_open();
|
log_open();
|
||||||
|
|
||||||
r = parse_argv(argc, argv);
|
r = parse_argv(argc, argv);
|
||||||
if (r < 0)
|
if (r <= 0)
|
||||||
return EXIT_FAILURE;
|
return r;
|
||||||
if (r == 0)
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
|
|
||||||
r = sd_bus_default_system(&bus);
|
r = sd_bus_default_system(&bus);
|
||||||
if (r < 0) {
|
if (r < 0)
|
||||||
log_error_errno(r, "Failed to connect to bus: %m");
|
return log_error_errno(r, "Failed to connect to bus: %m");
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg_action == ACTION_LIST) {
|
if (arg_action == ACTION_LIST) {
|
||||||
|
|
||||||
r = print_inhibitors(bus);
|
r = print_inhibitors(bus);
|
||||||
pager_close();
|
pager_close();
|
||||||
if (r < 0)
|
return r;
|
||||||
return EXIT_FAILURE;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||||
@ -308,14 +302,12 @@ int main(int argc, char *argv[]) {
|
|||||||
arg_mode = "block";
|
arg_mode = "block";
|
||||||
|
|
||||||
fd = inhibit(bus, &error);
|
fd = inhibit(bus, &error);
|
||||||
if (fd < 0) {
|
if (fd < 0)
|
||||||
log_error("Failed to inhibit: %s", bus_error_message(&error, fd));
|
return log_error("Failed to inhibit: %s", bus_error_message(&error, fd));
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
r = safe_fork("(inhibit)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_CLOSE_ALL_FDS|FORK_LOG, &pid);
|
r = safe_fork("(inhibit)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_CLOSE_ALL_FDS|FORK_LOG, &pid);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return EXIT_FAILURE;
|
return r;
|
||||||
if (r == 0) {
|
if (r == 0) {
|
||||||
/* Child */
|
/* Child */
|
||||||
execvp(argv[optind], argv + optind);
|
execvp(argv[optind], argv + optind);
|
||||||
@ -324,9 +316,8 @@ int main(int argc, char *argv[]) {
|
|||||||
_exit(EXIT_FAILURE);
|
_exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
r = wait_for_terminate_and_check(argv[optind], pid, WAIT_LOG);
|
return wait_for_terminate_and_check(argv[optind], pid, WAIT_LOG);
|
||||||
return r < 0 ? EXIT_FAILURE : r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run);
|
||||||
|
Loading…
Reference in New Issue
Block a user