1 /* SPDX-License-Identifier: LGPL-2.1+ */
7 #include "daemon-util.h"
10 #include "pretty-print.h"
11 #include "signal-util.h"
14 static bool arg_quiet
= false;
15 static usec_t arg_timeout
= 120 * USEC_PER_SEC
;
16 static char **arg_interfaces
= NULL
;
17 static char **arg_ignore
= NULL
;
19 STATIC_DESTRUCTOR_REGISTER(arg_interfaces
, strv_freep
);
20 STATIC_DESTRUCTOR_REGISTER(arg_ignore
, strv_freep
);
22 static int help(void) {
23 _cleanup_free_
char *link
= NULL
;
26 r
= terminal_urlify_man("systemd-networkd-wait-online.service", "8", &link
);
30 printf("%s [OPTIONS...]\n\n"
31 "Block until network is configured.\n\n"
32 " -h --help Show this help\n"
33 " --version Print version string\n"
34 " -q --quiet Do not show status information\n"
35 " -i --interface=INTERFACE Block until at least these interfaces have appeared\n"
36 " --ignore=INTERFACE Don't take these interfaces into account\n"
37 " --timeout=SECS Maximum time to wait for network connectivity\n"
38 "\nSee the %s for details.\n"
39 , program_invocation_short_name
46 static int parse_argv(int argc
, char *argv
[]) {
54 static const struct option options
[] = {
55 { "help", no_argument
, NULL
, 'h' },
56 { "version", no_argument
, NULL
, ARG_VERSION
},
57 { "quiet", no_argument
, NULL
, 'q' },
58 { "interface", required_argument
, NULL
, 'i' },
59 { "ignore", required_argument
, NULL
, ARG_IGNORE
},
60 { "timeout", required_argument
, NULL
, ARG_TIMEOUT
},
69 while ((c
= getopt_long(argc
, argv
, "+hi:q", options
, NULL
)) >= 0)
85 if (strv_extend(&arg_interfaces
, optarg
) < 0)
91 if (strv_extend(&arg_ignore
, optarg
) < 0)
97 r
= parse_sec(optarg
, &arg_timeout
);
107 assert_not_reached("Unhandled option");
113 static int run(int argc
, char *argv
[]) {
114 _cleanup_(notify_on_cleanup
) const char *notify_message
= NULL
;
115 _cleanup_(manager_freep
) Manager
*m
= NULL
;
122 r
= parse_argv(argc
, argv
);
127 log_set_max_level(LOG_WARNING
);
129 assert_se(sigprocmask_many(SIG_BLOCK
, NULL
, SIGTERM
, SIGINT
, -1) >= 0);
131 r
= manager_new(&m
, arg_interfaces
, arg_ignore
, arg_timeout
);
133 return log_error_errno(r
, "Could not create manager: %m");
135 if (manager_all_configured(m
))
138 notify_message
= notify_start("READY=1\n"
139 "STATUS=Waiting for network connections...",
140 "STATUS=Failed to wait for network connectivity...");
142 r
= sd_event_loop(m
->event
);
144 return log_error_errno(r
, "Event loop failed: %m");
147 notify_message
= "STATUS=All interfaces configured...";
152 DEFINE_MAIN_FUNCTION(run
);