From 2ba55c0e323e224db31b51c068d6726fe7204b4b Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 24 Jan 2005 21:53:39 +0000 Subject: [PATCH] 2005-01-24 Dan Williams * src/NetworkManagerDevice.c src/NetworkManagerDevicePrivate.h - Block nm_device_new() until our device's worker thread has had a chance to start up. Fixes a race between main thread and worker thread starting that caused activation requests to get lost. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@396 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 8 ++++++++ src/NetworkManagerDevice.c | 14 +++++++++++++- src/NetworkManagerDevicePrivate.h | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 2fd18b5b6..59070b9f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-01-24 Dan Williams + + * src/NetworkManagerDevice.c + src/NetworkManagerDevicePrivate.h + - Block nm_device_new() until our device's worker thread has had a + chance to start up. Fixes a race between main thread and worker + thread starting that caused activation requests to get lost. + 2005-01-24 Dan Williams * initscript/RedHat/NetworkManager diff --git a/src/NetworkManagerDevice.c b/src/NetworkManagerDevice.c index a26f9b88e..c642cbfb5 100644 --- a/src/NetworkManagerDevice.c +++ b/src/NetworkManagerDevice.c @@ -319,6 +319,12 @@ NMDevice *nm_device_new (const char *iface, const char *udi, gboolean test_dev, dev = NULL; } + /* Block until our device thread has actually had a chance to start. */ + syslog (LOG_ERR, "nm_device_new(): waiting for device's worker thread to start.\n"); + while (dev->worker_started == FALSE) + g_usleep (G_USEC_PER_SEC / 2); + syslog (LOG_ERR, "nm_device_new(): device's worker thread started, continuing.\n"); + return (dev); } @@ -391,11 +397,17 @@ static gpointer nm_device_worker (gpointer user_data) { NMDevice *dev = (NMDevice *)user_data; - g_return_val_if_fail (dev != NULL, NULL); + if (!dev) + { + syslog (LOG_CRIT, "nm_device_worker(): received NULL device object, NetworkManager cannot continue.\n"); + exit (1); + } dev->context = g_main_context_new (); dev->loop = g_main_loop_new (dev->context, FALSE); + dev->worker_started = TRUE; + /* Do an initial wireless scan */ if (nm_device_is_wireless (dev)) { diff --git a/src/NetworkManagerDevicePrivate.h b/src/NetworkManagerDevicePrivate.h index c26d03cc2..1abec2277 100644 --- a/src/NetworkManagerDevicePrivate.h +++ b/src/NetworkManagerDevicePrivate.h @@ -104,6 +104,7 @@ struct NMDevice GMainContext *context; GMainLoop *loop; gboolean worker_done; + gboolean worker_started; guint renew_timeout; guint rebind_timeout;