mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-25 23:21:33 +03:00
wait-online: define main through macro
This commit is contained in:
parent
82310c7981
commit
c03a80c419
@ -4,6 +4,8 @@
|
||||
|
||||
#include "sd-daemon.h"
|
||||
|
||||
#include "daemon-util.h"
|
||||
#include "main-func.h"
|
||||
#include "manager.h"
|
||||
#include "pretty-print.h"
|
||||
#include "signal-util.h"
|
||||
@ -14,6 +16,9 @@ static usec_t arg_timeout = 120 * USEC_PER_SEC;
|
||||
static char **arg_interfaces = NULL;
|
||||
static char **arg_ignore = NULL;
|
||||
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_interfaces, strv_freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_ignore, strv_freep);
|
||||
|
||||
static int help(void) {
|
||||
_cleanup_free_ char *link = NULL;
|
||||
int r;
|
||||
@ -105,7 +110,8 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
static int run(int argc, char *argv[]) {
|
||||
_cleanup_(notify_on_cleanup) const char *notify_message = NULL;
|
||||
_cleanup_(manager_freep) Manager *m = NULL;
|
||||
int r;
|
||||
|
||||
@ -123,37 +129,24 @@ int main(int argc, char *argv[]) {
|
||||
assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT, -1) >= 0);
|
||||
|
||||
r = manager_new(&m, arg_interfaces, arg_ignore, arg_timeout);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not create manager: %m");
|
||||
goto finish;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not create manager: %m");
|
||||
|
||||
if (manager_all_configured(m)) {
|
||||
r = 0;
|
||||
goto finish;
|
||||
}
|
||||
if (manager_all_configured(m))
|
||||
goto success;
|
||||
|
||||
sd_notify(false,
|
||||
"READY=1\n"
|
||||
"STATUS=Waiting for network connections...");
|
||||
notify_message = notify_start("READY=1\n"
|
||||
"STATUS=Waiting for network connections...",
|
||||
"STATUS=Failed to wait for network connectivity...");
|
||||
|
||||
r = sd_event_loop(m->event);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Event loop failed: %m");
|
||||
goto finish;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Event loop failed: %m");
|
||||
|
||||
finish:
|
||||
strv_free(arg_interfaces);
|
||||
strv_free(arg_ignore);
|
||||
success:
|
||||
notify_message = "STATUS=All interfaces configured...";
|
||||
|
||||
if (r >= 0) {
|
||||
sd_notify(false, "STATUS=All interfaces configured...");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
sd_notify(false, "STATUS=Failed waiting for network connectivity...");
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_MAIN_FUNCTION(run);
|
||||
|
Loading…
Reference in New Issue
Block a user