From: Roy Marples Date: Mon, 9 Sep 2013 18:17:54 +0000 (+0000) Subject: Only start on settled devices. X-Git-Tag: v6.1.0~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c0dd39cd086bdab38ca824dc260a00430f6fb2fa;p=thirdparty%2Fdhcpcd.git Only start on settled devices. --- diff --git a/dev/udev.c b/dev/udev.c index 207253e8..5cd99297 100644 --- a/dev/udev.c +++ b/dev/udev.c @@ -36,8 +36,18 @@ #include "../eloop.h" #include "udev.h" +static struct udev *udev; static struct udev_monitor *monitor; +int +libudev_settled(const char *ifname) +{ + struct udev_device *device; + + device = udev_device_new_from_subsystem_sysname(udev, "net", ifname); + return device ? 1 : 0; +} + static void libudev_handledata(__unused void *arg) { @@ -73,22 +83,28 @@ libudev_listening(void) void libudev_stop(void) { - struct udev *udev; if (monitor) { - udev = udev_monitor_get_udev(monitor); - udev_unref(udev); udev_monitor_unref(monitor); monitor = NULL; } + + if (udev) { + udev_unref(udev); + udev = NULL; + } } int libudev_start(void) { - struct udev *udev; int fd; + if (udev) { + syslog(LOG_ERR, "libudev: already started"); + return -1; + } + syslog(LOG_DEBUG, "libudev: starting"); udev = udev_new(); if (udev == NULL) { diff --git a/dev/udev.h b/dev/udev.h index a1702ffd..0d785726 100644 --- a/dev/udev.h +++ b/dev/udev.h @@ -27,6 +27,7 @@ #ifndef LIBUDEV_H #define LIBUDEV_H +int libudev_settled(const char *); int libudev_listening(void); int libudev_start(void); void libudev_stop(void); diff --git a/net.c b/net.c index 0720a0f4..cbdde113 100644 --- a/net.c +++ b/net.c @@ -73,6 +73,9 @@ #include "ipv4.h" #include "ipv6nd.h" #include "net.h" +#ifdef LIBUDEV +#include "dev/udev.h" +#endif int socket_afnet = -1; @@ -267,6 +270,11 @@ discover_interfaces(int argc, char * const *argv) #endif } +#ifdef LIBUDEV + if (!libudev_settled(ifa->ifa_name)) + continue; +#endif + /* It's possible for an interface to have >1 AF_LINK. * For our purposes, we use the first one. */ TAILQ_FOREACH(ifp, ifs, next) {