]>
Commit | Line | Data |
---|---|---|
60f067b4 JS |
1 | |
2 | /*** | |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2013 Tom Gundersen <teg@jklm.no> | |
6 | ||
7 | systemd is free software; you can redistribute it and/or modify it | |
8 | under the terms of the GNU Lesser General Public License as published by | |
9 | the Free Software Foundation; either version 2.1 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | systemd is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public License | |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ***/ | |
20 | ||
60f067b4 JS |
21 | #include <getopt.h> |
22 | ||
60f067b4 | 23 | #include "sd-daemon.h" |
5eef597e | 24 | |
60f067b4 JS |
25 | #include "networkd-wait-online.h" |
26 | ||
60f067b4 | 27 | #include "strv.h" |
60f067b4 JS |
28 | #include "build.h" |
29 | ||
30 | static bool arg_quiet = false; | |
31 | static char **arg_interfaces = NULL; | |
32 | ||
5eef597e | 33 | static void help(void) { |
60f067b4 JS |
34 | printf("%s [OPTIONS...]\n\n" |
35 | "Block until network is configured.\n\n" | |
36 | " -h --help Show this help\n" | |
37 | " --version Print version string\n" | |
38 | " -q --quiet Do not show status information\n" | |
5eef597e MP |
39 | " -i --interface=INTERFACE Block until at least these interfaces have appeared\n" |
40 | , program_invocation_short_name); | |
60f067b4 JS |
41 | } |
42 | ||
43 | static int parse_argv(int argc, char *argv[]) { | |
44 | ||
45 | enum { | |
46 | ARG_VERSION = 0x100, | |
47 | }; | |
48 | ||
49 | static const struct option options[] = { | |
50 | { "help", no_argument, NULL, 'h' }, | |
51 | { "version", no_argument, NULL, ARG_VERSION }, | |
52 | { "quiet", no_argument, NULL, 'q' }, | |
53 | { "interface", required_argument, NULL, 'i' }, | |
54 | {} | |
55 | }; | |
56 | ||
57 | int c; | |
58 | ||
59 | assert(argc >= 0); | |
60 | assert(argv); | |
61 | ||
5eef597e | 62 | while ((c = getopt_long(argc, argv, "+hiq", options, NULL)) >= 0) |
60f067b4 JS |
63 | |
64 | switch (c) { | |
65 | ||
66 | case 'h': | |
5eef597e MP |
67 | help(); |
68 | return 0; | |
60f067b4 JS |
69 | |
70 | case 'q': | |
71 | arg_quiet = true; | |
72 | break; | |
73 | ||
74 | case ARG_VERSION: | |
75 | puts(PACKAGE_STRING); | |
76 | puts(SYSTEMD_FEATURES); | |
77 | return 0; | |
78 | ||
79 | case 'i': | |
80 | if (strv_extend(&arg_interfaces, optarg) < 0) | |
81 | return log_oom(); | |
82 | ||
83 | break; | |
84 | ||
85 | case '?': | |
86 | return -EINVAL; | |
87 | ||
88 | default: | |
89 | assert_not_reached("Unhandled option"); | |
90 | } | |
60f067b4 JS |
91 | |
92 | return 1; | |
93 | } | |
94 | ||
60f067b4 | 95 | int main(int argc, char *argv[]) { |
5eef597e MP |
96 | _cleanup_(manager_freep) Manager *m = NULL; |
97 | int r; | |
60f067b4 | 98 | |
5eef597e | 99 | log_set_target(LOG_TARGET_AUTO); |
60f067b4 JS |
100 | log_parse_environment(); |
101 | log_open(); | |
102 | ||
5eef597e MP |
103 | umask(0022); |
104 | ||
60f067b4 JS |
105 | r = parse_argv(argc, argv); |
106 | if (r <= 0) | |
107 | return r; | |
108 | ||
109 | if (arg_quiet) | |
110 | log_set_max_level(LOG_WARNING); | |
111 | ||
5eef597e | 112 | assert_se(sigprocmask_many(SIG_BLOCK, SIGTERM, SIGINT, -1) == 0); |
60f067b4 | 113 | |
5eef597e | 114 | r = manager_new(&m, arg_interfaces); |
60f067b4 | 115 | if (r < 0) { |
f47781d8 | 116 | log_error_errno(r, "Could not create manager: %m"); |
5eef597e | 117 | goto finish; |
60f067b4 JS |
118 | } |
119 | ||
5eef597e | 120 | if (manager_all_configured(m)) { |
60f067b4 | 121 | r = 0; |
5eef597e | 122 | goto finish; |
60f067b4 JS |
123 | } |
124 | ||
125 | sd_notify(false, | |
126 | "READY=1\n" | |
127 | "STATUS=Waiting for network connections..."); | |
128 | ||
129 | r = sd_event_loop(m->event); | |
130 | if (r < 0) { | |
f47781d8 | 131 | log_error_errno(r, "Event loop failed: %m"); |
5eef597e | 132 | goto finish; |
60f067b4 JS |
133 | } |
134 | ||
5eef597e MP |
135 | finish: |
136 | sd_notify(false, "STATUS=All interfaces configured..."); | |
60f067b4 JS |
137 | |
138 | return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; | |
139 | } |