summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Bacci <luca.bacci982@gmail.com>2022-07-28 12:21:50 +0200
committerLuca Bacci <luca.bacci982@gmail.com>2022-08-02 16:38:32 +0200
commit45bdeeddff4b3bfcfff146023b2b7fd69ff2d0a3 (patch)
tree3612385da47e2dd733e57960abae3c2ff35f850a
parent9bc9a9b62adc3f78c89509eccebec25b781af8bc (diff)
downloadglib-45bdeeddff4b3bfcfff146023b2b7fd69ff2d0a3.tar.gz
GWin32AppInfo: Actually report the GPid in the GAppLaunchContext::launched signal
We need to pass the G_SPAWN_DO_NOT_REAP_CHILD flag to g_spawn_async, otherwise the returned child_pid will always be 0.
-rw-r--r--gio/gappinfo.c5
-rw-r--r--gio/gwin32appinfo.c4
-rw-r--r--glib/gspawn-win32.c3
3 files changed, 11 insertions, 1 deletions
diff --git a/gio/gappinfo.c b/gio/gappinfo.c
index f1e866dda..17f453ada 100644
--- a/gio/gappinfo.c
+++ b/gio/gappinfo.c
@@ -1439,6 +1439,11 @@ g_app_launch_context_class_init (GAppLaunchContextClass *klass)
* example if the process was launched via D-Bus). The `pid` may not be
* set at all in subsequent releases.
*
+ * On Windows, `pid` is guaranteed to be valid only for the duration of the
+ * #GAppLaunchContext::launched signal emission; after the signal is emitted,
+ * GLib will call g_spawn_close_pid(). If you need to keep the #GPid after the
+ * signal has been emitted, then you can duplicate `pid` using `DuplicateHandle()`.
+ *
* Since: 2.36
*/
signals[LAUNCHED] = g_signal_new (I_("launched"),
diff --git a/gio/gwin32appinfo.c b/gio/gwin32appinfo.c
index cdb486843..0960eef5c 100644
--- a/gio/gwin32appinfo.c
+++ b/gio/gwin32appinfo.c
@@ -4845,7 +4845,8 @@ g_win32_app_info_launch_internal (GWin32AppInfo *info,
if (!g_spawn_async (NULL,
argv,
envp,
- spawn_flags,
+ spawn_flags |
+ G_SPAWN_DO_NOT_REAP_CHILD,
NULL,
NULL,
&pid,
@@ -4871,6 +4872,7 @@ g_win32_app_info_launch_internal (GWin32AppInfo *info,
g_variant_unref (platform_data);
}
+ g_spawn_close_pid (pid);
g_strfreev (argv);
argv = NULL;
}
diff --git a/glib/gspawn-win32.c b/glib/gspawn-win32.c
index 3ce21819f..5ac4910f8 100644
--- a/glib/gspawn-win32.c
+++ b/glib/gspawn-win32.c
@@ -1417,6 +1417,9 @@ g_spawn_command_line_async (const gchar *command_line,
void
g_spawn_close_pid (GPid pid)
{
+ /* CRT functions such as _wspawn* return (HANDLE)-1
+ * on failure, so check also for that value. */
+ if (pid != NULL && pid != (HANDLE) -1)
CloseHandle (pid);
}