1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 This file is part of systemd.
6 Copyright 2013 Tom Gundersen <teg@jklm.no>
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 #include "sd-daemon.h"
27 #include "signal-util.h"
30 static bool arg_quiet
= false;
31 static usec_t arg_timeout
= 120 * USEC_PER_SEC
;
32 static char **arg_interfaces
= NULL
;
33 static char **arg_ignore
= NULL
;
35 static void help(void) {
36 printf("%s [OPTIONS...]\n\n"
37 "Block until network is configured.\n\n"
38 " -h --help Show this help\n"
39 " --version Print version string\n"
40 " -q --quiet Do not show status information\n"
41 " -i --interface=INTERFACE Block until at least these interfaces have appeared\n"
42 " --ignore=INTERFACE Don't take these interfaces into account\n"
43 " --timeout=SECS Maximum time to wait for network connectivity\n"
44 , program_invocation_short_name
);
47 static int parse_argv(int argc
, char *argv
[]) {
55 static const struct option options
[] = {
56 { "help", no_argument
, NULL
, 'h' },
57 { "version", no_argument
, NULL
, ARG_VERSION
},
58 { "quiet", no_argument
, NULL
, 'q' },
59 { "interface", required_argument
, NULL
, 'i' },
60 { "ignore", required_argument
, NULL
, ARG_IGNORE
},
61 { "timeout", required_argument
, NULL
, ARG_TIMEOUT
},
70 while ((c
= getopt_long(argc
, argv
, "+hi:q", options
, NULL
)) >= 0)
86 if (strv_extend(&arg_interfaces
, optarg
) < 0)
92 if (strv_extend(&arg_ignore
, optarg
) < 0)
98 r
= parse_sec(optarg
, &arg_timeout
);
108 assert_not_reached("Unhandled option");
114 int main(int argc
, char *argv
[]) {
115 _cleanup_(manager_freep
) Manager
*m
= NULL
;
118 log_set_target(LOG_TARGET_AUTO
);
119 log_parse_environment();
124 r
= parse_argv(argc
, argv
);
129 log_set_max_level(LOG_WARNING
);
131 assert_se(sigprocmask_many(SIG_BLOCK
, NULL
, SIGTERM
, SIGINT
, -1) >= 0);
133 r
= manager_new(&m
, arg_interfaces
, arg_ignore
, arg_timeout
);
135 log_error_errno(r
, "Could not create manager: %m");
139 if (manager_all_configured(m
)) {
146 "STATUS=Waiting for network connections...");
148 r
= sd_event_loop(m
->event
);
150 log_error_errno(r
, "Event loop failed: %m");
155 strv_free(arg_interfaces
);
156 strv_free(arg_ignore
);
159 sd_notify(false, "STATUS=All interfaces configured...");
163 sd_notify(false, "STATUS=Failed waiting for network connectivity...");