Merge "Imported Upstream connman version 1.38" into tizen
[platform/upstream/connman.git] / src / rtnl.c
index aa5c07c..7c8c68b 100644 (file)
@@ -591,14 +591,15 @@ static void process_newlink(unsigned short type, int index, unsigned flags,
                __connman_technology_add_interface(interface->service_type,
                        interface->index, interface->ident);
 
-       for (list = watch_list; list; list = list->next) {
+       list = watch_list;
+       while (list) {
+               GSList *next = list->next;
                struct watch_data *watch = list->data;
 
-               if (watch->index != index)
-                       continue;
-
-               if (watch->newlink)
+               if (watch->index == index && watch->newlink)
                        watch->newlink(flags, change, watch->user_data);
+
+               list = next;
        }
 }
 
@@ -1586,8 +1587,15 @@ static gboolean netlink_event(GIOChannel *chan, GIOCondition cond, gpointer data
        ssize_t status;
        int fd;
 
+#if defined TIZEN_EXT
+       if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
+               __connman_rtnl_init(GIO_SOCKET_RETRY_COUNT);
+               return FALSE;
+       }
+#else /* TIZEN_EXT */
        if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR))
                return FALSE;
+#endif /* TIZEN_EXT */
 
        memset(buf, 0, sizeof(buf));
        memset(&nladdr, 0, sizeof(nladdr));
@@ -1600,11 +1608,21 @@ static gboolean netlink_event(GIOChannel *chan, GIOCondition cond, gpointer data
                if (errno == EINTR || errno == EAGAIN)
                        return TRUE;
 
+#if defined TIZEN_EXT
+               __connman_rtnl_init(GIO_SOCKET_RETRY_COUNT);
+#endif /* TIZEN_EXT */
                return FALSE;
        }
 
+#if defined TIZEN_EXT
+       if (status == 0) {
+               __connman_rtnl_init(GIO_SOCKET_RETRY_COUNT);
+               return FALSE;
+       }
+#else /* TIZEN_EXT */
        if (status == 0)
                return FALSE;
+#endif /* TIZEN_EXT */
 
        if (nladdr.nl_pid != 0) { /* not sent by kernel, ignore */
                DBG("Received msg from %u, ignoring it", nladdr.nl_pid);
@@ -1748,19 +1766,34 @@ int __connman_rtnl_request_update(void)
        return send_getlink();
 }
 
+#if defined TIZEN_EXT
+int __connman_rtnl_init(int retry_count)
+#else /* TIZEN_EXT */
 int __connman_rtnl_init(void)
+#endif /* TIZEN_EXT */
 {
        struct sockaddr_nl addr;
        int sk;
 
+#if defined TIZEN_EXT
+       if (retry_count < 0)
+               return -1;
+
+       DBG("retry_count %d", retry_count);
+#else /* TIZEN_EXT */
        DBG("");
+#endif /* TIZEN_EXT */
 
        interface_list = g_hash_table_new_full(g_direct_hash, g_direct_equal,
                                                        NULL, free_interface);
 
        sk = socket(PF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC, NETLINK_ROUTE);
        if (sk < 0)
+#if defined TIZEN_EXT
+               return __connman_rtnl_init(retry_count - 1);
+#else /* TIZEN_EXT */
                return -1;
+#endif /* TIZEN_EXT */
 
        memset(&addr, 0, sizeof(addr));
        addr.nl_family = AF_NETLINK;
@@ -1770,7 +1803,11 @@ int __connman_rtnl_init(void)
 
        if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
                close(sk);
+#if defined TIZEN_EXT
+               return __connman_rtnl_init(retry_count - 1);
+#else /* TIZEN_EXT */
                return -1;
+#endif /* TIZEN_EXT */
        }
 
        channel = g_io_channel_unix_new(sk);