diff options
author | Tom Gundersen <teg@jklm.no> | 2015-02-04 15:00:20 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2015-02-05 12:04:19 +0100 |
commit | a97dcc12e486ecff531809802930a26c4da827f2 (patch) | |
tree | 6314e0f416f940baf01cb4cb219c8ce62dc9bec9 /src/network/networkd-manager.c | |
parent | 3f171cabadfcd8699def3732d264f63f8e800562 (diff) |
networkd: exit on idle
We will be woken up on rtnl or dbus activity, so let's just quit if some time has passed and that is the only thing that can happen.
Note that we will always stay around if we expect network activity (e.g. DHCP is enabled), as we are not restarted on that.
Diffstat (limited to 'src/network/networkd-manager.c')
-rw-r--r-- | src/network/networkd-manager.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index 40328a36c9..02ab9f95ef 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -31,6 +31,8 @@ #include "libudev-private.h" #include "udev-util.h" #include "rtnl-util.h" +#include "bus-util.h" +#include "def.h" #include "mkdir.h" #include "virt.h" @@ -497,6 +499,46 @@ void manager_free(Manager *m) { free(m); } +static bool manager_check_idle(void *userdata) { + Manager *m = userdata; + Link *link; + Iterator i; + + assert(m); + + HASHMAP_FOREACH(link, m->links, i) { + /* we are not woken on udev activity, so let's just wait for the + * pending udev event */ + if (link->state == LINK_STATE_PENDING) + return false; + + if (!link->network) + continue; + + /* we are not woken on netork activity, so let's stay around */ + if (link_lldp_enabled(link) || + link_ipv4ll_enabled(link) || + link_dhcp4_server_enabled(link) || + link_dhcp4_enabled(link) || + link_dhcp6_enabled(link)) + return false; + } + + return true; +} + +int manager_run(Manager *m) { + assert(m); + + return bus_event_loop_with_idle( + m->event, + m->bus, + "org.freedesktop.network1", + DEFAULT_EXIT_USEC, + manager_check_idle, + m); +} + int manager_load_config(Manager *m) { int r; |