From: Roy Marples Date: Mon, 9 Sep 2013 20:21:03 +0000 (+0000) Subject: Improve udev handling a little. X-Git-Tag: v6.1.0~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e5e6db157ba654e01cf82a459a4901a45d9c6598;p=thirdparty%2Fdhcpcd.git Improve udev handling a little. --- diff --git a/dev/udev.c b/dev/udev.c index 5cd99297..19243fb5 100644 --- a/dev/udev.c +++ b/dev/udev.c @@ -43,16 +43,19 @@ int libudev_settled(const char *ifname) { struct udev_device *device; + int r; device = udev_device_new_from_subsystem_sysname(udev, "net", ifname); - return device ? 1 : 0; + r = device ? 1 : 0; + udev_device_unref(device); + return r; } static void libudev_handledata(__unused void *arg) { struct udev_device *device; - const char *ifname, *action; + const char *subsystem, *ifname, *action; device = udev_monitor_receive_device(monitor); if (device == NULL) { @@ -60,24 +63,25 @@ libudev_handledata(__unused void *arg) return; } - /* udev filter documentation says "usually" so double check */ - action = udev_device_get_subsystem(device); - if (strcmp(action, "net")) - return; - + subsystem = udev_device_get_subsystem(device); ifname = udev_device_get_sysname(device); action = udev_device_get_action(device); - if (strcmp(action, "add") == 0) - handle_interface(1, ifname); - else if (strcmp(action, "remove") == 0) - handle_interface(-1, ifname); + udev_device_unref(device); + + /* udev filter documentation says "usually" so double check */ + if (strcmp(subsystem, "net") == 0) { + if (strcmp(action, "add") == 0) + handle_interface(1, ifname); + else if (strcmp(action, "remove") == 0) + handle_interface(-1, ifname); + } } int libudev_listening(void) { - return monitor == NULL ? 0 : 1; + return monitor ? 1 : 0; } void