From 3a9c5a32bec18dc1cca68af46fd1aebfad7e9fd7 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Thu, 8 May 2014 13:14:42 +0200 Subject: networkd-wait-online: flush monitor events after processing Otherwise the event will trigger immediately again. --- src/network/networkd-wait-online.c | 27 ++++++++++++++------------- src/network/networkd-wait-online.h | 1 + 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/network/networkd-wait-online.c b/src/network/networkd-wait-online.c index a42fef26b9..3ea7a8384e 100644 --- a/src/network/networkd-wait-online.c +++ b/src/network/networkd-wait-online.c @@ -202,6 +202,8 @@ static int monitor_event_handler(sd_event_source *s, int fd, uint32_t revents, if (all_configured(m)) sd_event_exit(m->event, 0); + sd_network_monitor_flush(m->monitor); + return 1; } @@ -218,7 +220,6 @@ void manager_free(Manager *m) { int main(int argc, char *argv[]) { _cleanup_manager_free_ Manager *m = NULL; _cleanup_event_source_unref_ sd_event_source *event_source = NULL; - _cleanup_network_monitor_unref_ sd_network_monitor *monitor = NULL; int r, fd, events; umask(0022); @@ -237,25 +238,31 @@ int main(int argc, char *argv[]) { if (!m) return log_oom(); - r = sd_network_monitor_new(NULL, &monitor); + r = sd_event_new(&m->event); if (r < 0) { - log_error("Could not create monitor: %s", strerror(-r)); + log_error("Could not create event: %s", strerror(-r)); goto out; } - r = sd_event_new(&m->event); + r = sd_rtnl_open(&m->rtnl, 0); if (r < 0) { - log_error("Could not create event: %s", strerror(-r)); + log_error("Could not create rtnl: %s", strerror(-r)); goto out; } - fd = sd_network_monitor_get_fd(monitor); + r = sd_network_monitor_new(NULL, &m->monitor); + if (r < 0) { + log_error("Could not create monitor: %s", strerror(-r)); + goto out; + } + + fd = sd_network_monitor_get_fd(m->monitor); if (fd < 0) { log_error("Could not get monitor fd: %s", strerror(-r)); goto out; } - events = sd_network_monitor_get_events(monitor); + events = sd_network_monitor_get_events(m->monitor); if (events < 0) { log_error("Could not get monitor events: %s", strerror(-r)); goto out; @@ -268,12 +275,6 @@ int main(int argc, char *argv[]) { goto out; } - r = sd_rtnl_open(&m->rtnl, 0); - if (r < 0) { - log_error("Could not create rtnl: %s", strerror(-r)); - goto out; - } - if (all_configured(m)) { r = 0; goto out; diff --git a/src/network/networkd-wait-online.h b/src/network/networkd-wait-online.h index 91edce1f60..e894351d2e 100644 --- a/src/network/networkd-wait-online.h +++ b/src/network/networkd-wait-online.h @@ -29,6 +29,7 @@ typedef struct Manager { sd_event *event; sd_rtnl *rtnl; + sd_network_monitor *monitor; } Manager; void manager_free(Manager *m); -- cgit v1.2.3-54-g00ecf