From 811c0c8546d2c8fbe242284f78b061dc51ccb32c Mon Sep 17 00:00:00 2001 From: Bruno Lopes Date: Sun, 29 Mar 2026 21:54:34 -0300 Subject: [PATCH] app: Use posix_spawn on macOS Fixes a Apple Clang warning. vfork is considered deprecated and unsafe on such platform --- app/core/gimp-spawn.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/app/core/gimp-spawn.c b/app/core/gimp-spawn.c index bfa08e832b..27ebd04393 100644 --- a/app/core/gimp-spawn.c +++ b/app/core/gimp-spawn.c @@ -38,6 +38,10 @@ #include #endif +#ifdef __APPLE__ +#include +#endif + #include "core-types.h" #include "gimp-spawn.h" @@ -167,7 +171,7 @@ gimp_spawn_async (gchar **argv, g_return_val_if_fail (argv != NULL, FALSE); g_return_val_if_fail (argv[0] != NULL, FALSE); -#ifdef HAVE_VFORK +#if defined(HAVE_VFORK) && !defined(__APPLE__) if (flags == (G_SPAWN_LEAVE_DESCRIPTORS_OPEN | G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_CHILD_INHERITS_STDIN)) @@ -232,7 +236,36 @@ gimp_spawn_async (gchar **argv, return TRUE; } } -#endif /* HAVE_VFORK */ +#elif defined(__APPLE__) + if (flags == (G_SPAWN_LEAVE_DESCRIPTORS_OPEN | + G_SPAWN_DO_NOT_REAP_CHILD | + G_SPAWN_CHILD_INHERITS_STDIN)) + { + pid_t pid; + int status; + extern char **environ; + char **child_env = envp ? envp : environ; + + /* posix_spawn combines fork and exec */ + status = posix_spawn (&pid, argv[0], NULL, NULL, argv, child_env); + + if (status != 0) + { + g_set_error (error, + G_SPAWN_ERROR, + exec_err_to_g_error (status), + _("Failed to execute child process ā€œ%sā€ (%s)"), + argv[0], + g_strerror (status)); + + return FALSE; + } + + if (child_pid) *child_pid = pid; + + return TRUE; + } +#endif return g_spawn_async (NULL, argv, envp, flags, NULL, NULL, child_pid, error); }