1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 Copyright © 2013 Tom Gundersen <teg@jklm.no>
12 #include "signal-util.h"
15 static bool arg_quiet
= false;
16 static usec_t arg_timeout
= 120 * USEC_PER_SEC
;
17 static char **arg_interfaces
= NULL
;
18 static char **arg_ignore
= NULL
;
20 static void help(void) {
21 printf("%s [OPTIONS...]\n\n"
22 "Block until network is configured.\n\n"
23 " -h --help Show this help\n"
24 " --version Print version string\n"
25 " -q --quiet Do not show status information\n"
26 " -i --interface=INTERFACE Block until at least these interfaces have appeared\n"
27 " --ignore=INTERFACE Don't take these interfaces into account\n"
28 " --timeout=SECS Maximum time to wait for network connectivity\n"
29 , program_invocation_short_name
);
32 static int parse_argv(int argc
, char *argv
[]) {
40 static const struct option options
[] = {
41 { "help", no_argument
, NULL
, 'h' },
42 { "version", no_argument
, NULL
, ARG_VERSION
},
43 { "quiet", no_argument
, NULL
, 'q' },
44 { "interface", required_argument
, NULL
, 'i' },
45 { "ignore", required_argument
, NULL
, ARG_IGNORE
},
46 { "timeout", required_argument
, NULL
, ARG_TIMEOUT
},
55 while ((c
= getopt_long(argc
, argv
, "+hi:q", options
, NULL
)) >= 0)
71 if (strv_extend(&arg_interfaces
, optarg
) < 0)
77 if (strv_extend(&arg_ignore
, optarg
) < 0)
83 r
= parse_sec(optarg
, &arg_timeout
);
93 assert_not_reached("Unhandled option");
99 int main(int argc
, char *argv
[]) {
100 _cleanup_(manager_freep
) Manager
*m
= NULL
;
103 log_set_target(LOG_TARGET_AUTO
);
104 log_parse_environment();
109 r
= parse_argv(argc
, argv
);
114 log_set_max_level(LOG_WARNING
);
116 assert_se(sigprocmask_many(SIG_BLOCK
, NULL
, SIGTERM
, SIGINT
, -1) >= 0);
118 r
= manager_new(&m
, arg_interfaces
, arg_ignore
, arg_timeout
);
120 log_error_errno(r
, "Could not create manager: %m");
124 if (manager_all_configured(m
)) {
131 "STATUS=Waiting for network connections...");
133 r
= sd_event_loop(m
->event
);
135 log_error_errno(r
, "Event loop failed: %m");
140 strv_free(arg_interfaces
);
141 strv_free(arg_ignore
);
144 sd_notify(false, "STATUS=All interfaces configured...");
148 sd_notify(false, "STATUS=Failed waiting for network connectivity...");