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 "event-util.h"
24 #include "sd-daemon.h"
25 #include "sd-network.h"
26 #include "network-util.h"
30 static bool all_configured(void) {
31 _cleanup_free_ unsigned *indices = NULL;
32 bool one_ready = false;
35 n = sd_network_get_ifindices(&indices);
39 for (i = 0; i < n; i++) {
40 _cleanup_free_ char *state = NULL;
42 r = sd_network_get_link_state(indices[i], &state);
45 if (r < 0 || !streq(state, "configured"))
54 static int event_handler(sd_event_source *s, int fd, uint32_t revents,
56 sd_event *event = userdata;
61 sd_event_exit(event, 0);
66 int main(int argc, char *argv[]) {
67 _cleanup_event_unref_ sd_event *event = NULL;
68 _cleanup_event_source_unref_ sd_event_source *event_source = NULL;
69 _cleanup_network_monitor_unref_ sd_network_monitor *monitor = NULL;
72 log_set_target(LOG_TARGET_AUTO);
73 log_parse_environment();
79 log_error("This program takes no arguments.");
84 r = sd_network_monitor_new(NULL, &monitor);
86 log_error("Could not create monitor: %s", strerror(-r));
90 r = sd_event_new(&event);
92 log_error("Could not create event: %s", strerror(-r));
96 fd = sd_network_monitor_get_fd(monitor);
98 log_error("Could not get monitor fd: %s", strerror(-r));
102 events = sd_network_monitor_get_events(monitor);
104 log_error("Could not get monitor events: %s", strerror(-r));
108 r = sd_event_add_io(event, &event_source, fd, events, &event_handler,
111 log_error("Could not add io event source: %s", strerror(-r));
115 if (all_configured()) {
122 "STATUS=Waiting for network connections...");
124 r = sd_event_loop(event);
126 log_error("Event loop failed: %s", strerror(-r));
132 "STATUS=All interfaces configured...");
134 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;