networkd-wait-online.c revision 3a67e927e3be7efb8edf314a31aa4f8f5cba4f53
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Tom Gundersen <teg@jklm.no>
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "sd-event.h"
#include "event-util.h"
#include "sd-rtnl.h"
#include "rtnl-util.h"
#include "sd-daemon.h"
#include "sd-network.h"
#include "network-util.h"
#include "network-internal.h"
#include "networkd-wait-online.h"
#include "conf-parser.h"
#include "strv.h"
#include "util.h"
static bool all_configured(Manager *m) {
char **ifname;
bool one_ready = false;
int r, n, i;
n = sd_network_get_ifindices(&indices);
if (n <= 0)
return false;
bool found = false;
int index;
if (r < 0) {
return false;
}
if (r < 0) {
return false;
}
if (r < 0) {
if (r != -ENODEV)
strerror(-r));
/* link does not yet exist */
return false;
}
if (r < 0) {
return false;
}
if (index <= 0) {
return false;
}
for (i = 0; i < n; i++) {
found = true;
break;
}
}
if (!found)
/* link exists, but networkd is not yet aware of it */
return false;
}
for (i = 0; i < n; i++) {
if (r == -EUNATCH) {
unsigned flags;
if (r < 0) {
return false;
}
if (r < 0) {
continue;
}
if (r < 0) {
return false;
}
if (r < 0) {
}
if (!(flags & IFF_LOOPBACK) &&
/* this link is not managed by us,
but something else may have
made it ready, so don't block */
one_ready = true;
}
continue;
return false;
/* we wait for at least one link to appear */
one_ready = true;
}
return one_ready;
}
void *userdata) {
assert(m);
if (all_configured(m))
sd_event_exit(m->event, 0);
return 1;
}
assert(m);
if (all_configured(m))
sd_event_exit(m->event, 0);
return 1;
}
static int parse_config_file(Manager *m) {
static const char fn[] = "/etc/systemd/networkd-wait-online.conf";
int r;
if (!f) {
return 0;
return -errno;
}
(void*) wait_online_gperf_lookup, false, false, m);
if (r < 0)
return r;
}
void manager_free(Manager *m) {
if (!m)
return;
sd_event_unref(m->event);
sd_rtnl_unref(m->rtnl);
strv_free(m->expected_links);
free(m);
}
log_open();
umask(0022);
if (argc != 1) {
log_error("This program takes no arguments.");
r = -EINVAL;
goto out;
}
if (!m)
return log_oom();
r = parse_config_file(m);
if (r < 0)
goto out;
if (r < 0) {
goto out;
}
r = sd_event_new(&m->event);
if (r < 0) {
goto out;
}
if (fd < 0) {
goto out;
}
if (events < 0) {
goto out;
}
m);
if (r < 0) {
goto out;
}
if (r < 0) {
goto out;
}
if (r < 0) {
return r;
}
if (r < 0)
return r;
if (all_configured(m)) {
r = 0;
goto out;
}
sd_notify(false,
"READY=1\n"
"STATUS=Waiting for network connections...");
r = sd_event_loop(m->event);
if (r < 0) {
goto out;
}
out:
sd_notify(false,
"STATUS=All interfaces configured...");
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}