]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
dbus-spawn-win: Move _dbus_spawn_program() to main thread
authorSimon McVittie <smcv@collabora.com>
Thu, 20 Dec 2018 15:17:13 +0000 (15:17 +0000)
committerRalf <ralf@linux1.fritz.box>
Sat, 5 Jan 2019 10:41:58 +0000 (11:41 +0100)
We would like to stop taking ownership of envp, but we can't do that
without a deep copy if a different thread might still be using it
(asynchronously) after the main thread has returned from
_dbus_spawn_async_with_babysitter().

Originally part of a larger commit by Ralf Habacker.

Signed-off-by: Simon McVittie <smcv@collabora.com>
dbus/dbus-spawn-win.c

index 5ad561c2792f4d2fd77b7da02c93e0913225bcfe..c4b356c59cd97f9143e82c750af63ac57db4c447 100644 (file)
@@ -600,26 +600,7 @@ babysitter (void *parameter)
 {
   int ret = 0;
   DBusBabysitter *sitter = (DBusBabysitter *) parameter;
-  HANDLE handle;
-
-  PING();
-  _dbus_verbose ("babysitter: spawning %s\n", sitter->log_name);
 
-  PING();
-  handle = _dbus_spawn_program (sitter->log_name, sitter->argv, sitter->envp);
-
-  PING();
-  if (handle != INVALID_HANDLE_VALUE)
-    {
-      sitter->child_handle = handle;
-    }
-  else
-    {
-      sitter->child_handle = NULL;
-      sitter->have_spawn_errno = TRUE;
-      sitter->spawn_errno = GetLastError();
-    }
-  
   PING();
   SetEvent (sitter->start_sync_event);
 
@@ -663,7 +644,8 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter           **sitter_p,
 {
   DBusBabysitter *sitter;
   DWORD sitter_thread_id;
-  
+  HANDLE handle;
+
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
   _dbus_assert (argv[0] != NULL);
 
@@ -731,6 +713,24 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter           **sitter_p,
     }
   sitter->envp = envp;
 
+  PING();
+  _dbus_verbose ("babysitter: spawn child '%s'\n", sitter->argv[0]);
+
+  PING();
+  handle = _dbus_spawn_program (sitter->log_name, sitter->argv, sitter->envp);
+
+  PING();
+  if (handle != INVALID_HANDLE_VALUE)
+    {
+      sitter->child_handle = handle;
+    }
+  else
+    {
+      sitter->child_handle = NULL;
+      sitter->have_spawn_errno = TRUE;
+      sitter->spawn_errno = GetLastError();
+    }
+
   PING();
   sitter->thread_handle = (HANDLE) CreateThread (NULL, 0, babysitter,
                   _dbus_babysitter_ref (sitter), 0, &sitter_thread_id);