Fix setup of udev context before loading any plugins
authorMarcel Holtmann <marcel@holtmann.org>
Thu, 23 Jul 2009 07:14:58 +0000 (09:14 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 23 Jul 2009 07:14:58 +0000 (09:14 +0200)
src/connman.h
src/element.c
src/main.c
src/rtnl.c
src/udev-compat.c
src/udev.c

index d23ff63..93d508f 100644 (file)
@@ -201,6 +201,7 @@ void __connman_connection_cleanup(void);
 gboolean __connman_connection_update_gateway(void);
 
 int __connman_udev_init(void);
+void __connman_udev_start(void);
 void __connman_udev_cleanup(void);
 char *__connman_udev_get_devtype(const char *ifname);
 char *__connman_udev_get_mbm_devnode(const char *ifname);
@@ -319,6 +320,7 @@ void __connman_notifier_offlinemode(connman_bool_t enabled);
 #include <connman/rtnl.h>
 
 int __connman_rtnl_init(void);
+void __connman_rtnl_start(void);
 void __connman_rtnl_cleanup(void);
 
 int __connman_rtnl_send(const void *buf, size_t len);
index a5af1a7..60fbca1 100644 (file)
@@ -1609,8 +1609,8 @@ void __connman_element_start(void)
 
        started = TRUE;
 
-       __connman_rtnl_init();
-       __connman_udev_init();
+       __connman_rtnl_start();
+       __connman_udev_start();
 
        __connman_connection_init();
        __connman_ipv4_init();
index c35d0d8..ede37a0 100644 (file)
@@ -205,6 +205,8 @@ int main(int argc, char *argv[])
        __connman_profile_init(conn);
 
        __connman_resolver_init();
+       __connman_rtnl_init();
+       __connman_udev_init();
 
        __connman_plugin_init(option_plugin, option_noplugin);
 
index 70e8c3c..5b07865 100644 (file)
@@ -759,6 +759,11 @@ int __connman_rtnl_init(void)
        return 0;
 }
 
+void __connman_rtnl_start(void)
+{
+       DBG("");
+}
+
 void __connman_rtnl_cleanup(void)
 {
        GSList *list;
index 448a18f..3ac069b 100644 (file)
@@ -127,17 +127,16 @@ void __connman_udev_rfkill(const char *sysname, connman_bool_t blocked)
 
 int __connman_udev_init(void)
 {
-       int err;
-
        DBG("");
 
-       err = connman_rtnl_register(&detect_rtnl);
-       if (err < 0)
-               return err;
+       return connman_rtnl_register(&detect_rtnl);
+}
 
-       connman_rtnl_send_getlink();
+void __connman_udev_start(void)
+{
+       DBG("");
 
-       return 0;
+       connman_rtnl_send_getlink();
 }
 
 void __connman_udev_cleanup(void)
index b14b625..f65f1f5 100644 (file)
@@ -35,7 +35,6 @@
 #include "connman.h"
 
 #ifdef NEED_UDEV_MONITOR_FILTER
-#if 0
 static int udev_monitor_filter_add_match_subsystem_devtype(struct udev_monitor *udev_monitor,
                                const char *subsystem, const char *devtype)
 {
@@ -50,7 +49,6 @@ static int udev_monitor_filter_remove(struct udev_monitor *udev_monitor)
        return -EINVAL;
 }
 #endif
-#endif
 
 static GSList *device_list = NULL;
 
@@ -480,9 +478,6 @@ void __connman_udev_rfkill(const char *sysname, connman_bool_t blocked)
 
 int __connman_udev_init(void)
 {
-       GIOChannel *channel;
-       int fd;
-
        DBG("");
 
        udev_ctx = udev_new();
@@ -499,12 +494,26 @@ int __connman_udev_init(void)
                return -1;
        }
 
+       udev_monitor_filter_add_match_subsystem_devtype(udev_mon,
+                                                       "net", NULL);
+       udev_monitor_filter_add_match_subsystem_devtype(udev_mon,
+                                                       "rfkill", NULL);
+
+       udev_monitor_filter_update(udev_mon);
+
+       return 0;
+}
+
+void __connman_udev_start(void)
+{
+       GIOChannel *channel;
+       int fd;
+
+       DBG("");
+
        if (udev_monitor_enable_receiving(udev_mon) < 0) {
                connman_error("Failed to enable udev monitor");
-               udev_unref(udev_ctx);
-               udev_ctx = NULL;
-               udev_monitor_unref(udev_mon);
-               return -1;
+               return;
        }
 
        enumerate_devices(udev_ctx);
@@ -513,13 +522,11 @@ int __connman_udev_init(void)
 
        channel = g_io_channel_unix_new(fd);
        if (channel == NULL)
-               return 0;
+               return;
 
        udev_watch = g_io_add_watch(channel, G_IO_IN, udev_event, udev_mon);
 
        g_io_channel_unref(channel);
-
-       return 0;
 }
 
 void __connman_udev_cleanup(void)
@@ -544,6 +551,8 @@ void __connman_udev_cleanup(void)
        if (udev_ctx == NULL)
                return;
 
+       udev_monitor_filter_remove(udev_mon);
+
        udev_monitor_unref(udev_mon);
        udev_unref(udev_ctx);
 }