1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
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/>.
23 #include "sd-daemon.h"
24 #include "sd-network.h"
28 static bool all_configured(void) {
29 _cleanup_free_ unsigned *indices = NULL;
30 bool one_ready = false;
33 n = sd_network_get_ifindices(&indices);
37 for (i = 0; i < n; i++) {
38 _cleanup_free_ char *state = NULL;
40 r = sd_network_get_link_state(indices[i], &state);
44 if (streq(state, "configured"))
47 if (!streq(state, "configured") && !streq(state, "unmanaged"))
57 static int event_handler(sd_event_source *s, int fd, uint32_t revents,
59 sd_event *event = userdata;
64 sd_event_exit(event, 0);
69 int main(int argc, char *argv[]) {
71 sd_event_source *event_source;
72 sd_network_monitor *monitor;
75 log_set_target(LOG_TARGET_AUTO);
76 log_parse_environment();
82 log_error("This program takes no arguments.");
87 r = sd_network_monitor_new(NULL, &monitor);
89 log_error("Could not create monitor: %s", strerror(-r));
93 r = sd_event_new(&event);
95 log_error("Could not create event: %s", strerror(-r));
99 fd = sd_network_monitor_get_fd(monitor);
101 log_error("Could not get monitor fd: %s", strerror(-r));
105 events = sd_network_monitor_get_events(monitor);
107 log_error("Could not get monitor events: %s", strerror(-r));
111 r = sd_event_add_io(event, &event_source, fd, events, &event_handler,
114 log_error("Could not add io event source: %s", strerror(-r));
118 if (all_configured()) {
125 "STATUS=Waiting for network connecitons...");
127 r = sd_event_loop(event);
129 log_error("Event loop failed: %s", strerror(-r));
135 "STATUS=All interfaces configured...");
137 sd_event_source_unref(event_source);
138 sd_event_unref(event);
139 sd_network_monitor_unref(monitor);
141 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;