From f1f1c3cb732fdff37670b83de356a5dc8fba69fb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 12 May 2015 07:14:55 +0200 Subject: [PATCH] platform: reorder initialization First fully construct the GOjbect instance before starting to populate the cache. --- src/platform/nm-linux-platform.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index a1a7533aa8..10afa18ffc 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -4559,6 +4559,7 @@ nm_linux_platform_init (NMLinuxPlatform *self) priv->cache = nmp_cache_new (); priv->delayed_action.list = g_array_new (FALSE, FALSE, sizeof (DelayedActionData)); + priv->wifi_data = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) wifi_utils_deinit); } static void @@ -4573,10 +4574,12 @@ constructed (GObject *_object) GUdevEnumerator *enumerator; GList *devices, *iter; + _LOGD ("create"); + /* Initialize netlink socket for requests */ priv->nlh = setup_socket (FALSE, platform); g_assert (priv->nlh); - debug ("Netlink socket for requests established: %d", nl_socket_get_local_port (priv->nlh)); + debug ("Netlink socket for requests established: port=%u, fd=%d", nl_socket_get_local_port (priv->nlh), nl_socket_get_fd (priv->nlh)); /* Initialize netlink socket for events */ priv->nlh_event = setup_socket (TRUE, platform); @@ -4593,7 +4596,7 @@ constructed (GObject *_object) RTNLGRP_IPV4_ROUTE, RTNLGRP_IPV6_ROUTE, 0); g_assert (!nle); - debug ("Netlink socket for events established: %d", nl_socket_get_local_port (priv->nlh_event)); + debug ("Netlink socket for events established: port=%u, fd=%d", nl_socket_get_local_port (priv->nlh_event), nl_socket_get_fd (priv->nlh_event)); priv->event_channel = g_io_channel_unix_new (nl_socket_get_fd (priv->nlh_event)); g_io_channel_set_encoding (priv->event_channel, NULL, NULL); @@ -4604,24 +4607,26 @@ constructed (GObject *_object) channel_flags | G_IO_FLAG_NONBLOCK, NULL); g_assert (status); priv->event_id = g_io_add_watch (priv->event_channel, - (EVENT_CONDITIONS | ERROR_CONDITIONS | DISCONNECT_CONDITIONS), - event_handler, platform); - - _LOGD ("populate platform cache"); - delayed_action_schedule (platform, DELAYED_ACTION_TYPE_REFRESH_ALL, NULL); - delayed_action_handle_all (platform); + (EVENT_CONDITIONS | ERROR_CONDITIONS | DISCONNECT_CONDITIONS), + event_handler, platform); /* Set up udev monitoring */ priv->udev_client = g_udev_client_new (udev_subsys); g_signal_connect (priv->udev_client, "uevent", G_CALLBACK (handle_udev_event), platform); + /* complete construction of the GObject instance before populating the cache. */ + G_OBJECT_CLASS (nm_linux_platform_parent_class)->constructed (_object); + + _LOGD ("populate platform cache"); + /* request all IPv6 addresses (hopeing that there is at least one), to check for * the IFA_FLAGS attribute. */ nle = nl_rtgen_request (priv->nlh_event, RTM_GETADDR, AF_INET6, NLM_F_DUMP); if (nle < 0) nm_log_warn (LOGD_PLATFORM, "Netlink error: requesting RTM_GETADDR failed with %s", nl_geterror (nle)); - priv->wifi_data = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) wifi_utils_deinit); + delayed_action_schedule (platform, DELAYED_ACTION_TYPE_REFRESH_ALL, NULL); + delayed_action_handle_all (platform); /* And read initial device list */ enumerator = g_udev_enumerator_new (priv->udev_client); @@ -4636,8 +4641,6 @@ constructed (GObject *_object) } g_list_free (devices); g_object_unref (enumerator); - - G_OBJECT_CLASS (nm_linux_platform_parent_class)->constructed (_object); } static void @@ -4646,6 +4649,8 @@ dispose (GObject *object) NMPlatform *platform = NM_PLATFORM (object); NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform); + _LOGD ("dispose"); + g_array_set_size (priv->delayed_action.list, 0); nm_clear_g_source (&priv->delayed_action.idle_id);