Merge branch 'g-win32-app-info-launched-signal-actually-report-pid' into 'main'

GWin32AppInfo: Fix PID reporting in launched signal

See merge request GNOME/glib!2299
This commit is contained in:
Luca Bacci 2022-08-02 14:51:26 +00:00
commit 0cb43a4965
3 changed files with 11 additions and 1 deletions

View File

@ -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 * example if the process was launched via D-Bus). The `pid` may not be
* set at all in subsequent releases. * 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 * Since: 2.36
*/ */
signals[LAUNCHED] = g_signal_new (I_("launched"), signals[LAUNCHED] = g_signal_new (I_("launched"),

View File

@ -4845,7 +4845,8 @@ g_win32_app_info_launch_internal (GWin32AppInfo *info,
if (!g_spawn_async (NULL, if (!g_spawn_async (NULL,
argv, argv,
envp, envp,
spawn_flags, spawn_flags |
G_SPAWN_DO_NOT_REAP_CHILD,
NULL, NULL,
NULL, NULL,
&pid, &pid,
@ -4871,6 +4872,7 @@ g_win32_app_info_launch_internal (GWin32AppInfo *info,
g_variant_unref (platform_data); g_variant_unref (platform_data);
} }
g_spawn_close_pid (pid);
g_strfreev (argv); g_strfreev (argv);
argv = NULL; argv = NULL;
} }

View File

@ -1417,6 +1417,9 @@ g_spawn_command_line_async (const gchar *command_line,
void void
g_spawn_close_pid (GPid pid) 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); CloseHandle (pid);
} }