1 --- src/posix-io.c 2023-02-01 11:50:48
2 +++ src/posix-io.c 2024-03-21 09:50:24
9 +#include <dispatch/dispatch.h>
12 +extern char **environ;
16 #ifdef USE_LINUX_GETDENTS
23 +#if HAVE_MACOS_SYSTEM
25 +_gpgme_io_spawn_macos (const char *path, char *const argv[], unsigned int flags,
26 + struct spawn_fd_item_s *fd_list,
27 + void (*atfork) (void *opaque, int reserved),
28 + void *atforkvalue, pid_t *r_pid);
29 +#endif /*HAVE_MACOS_SYSTEM*/
32 /* Returns 0 on success, -1 on error. */
34 struct spawn_fd_item_s *fd_list,
35 void (*atfork) (void *opaque, int reserved),
36 void *atforkvalue, pid_t *r_pid)
37 +#if HAVE_MACOS_SYSTEM
39 + /* tdf#152524 fork() and exec() in a separate libdispatch queue
40 + * This is another attempt to stop the crashing in libdispatch by
41 + * running fork() and exec() within a libdispatch task that will
42 + * run in a sequential queue in a non-main thread. */
43 + static dispatch_queue_t queue = NULL;
45 + queue = dispatch_queue_create ("gpgmepp",
46 + DISPATCH_QUEUE_CONCURRENT);
50 + __block int ret = -1;
51 + dispatch_sync(queue, ^{
52 + ret = _gpgme_io_spawn_macos (path, argv, flags,
54 + atforkvalue, r_pid);
61 +_gpgme_io_spawn_macos (const char *path, char *const argv[], unsigned int flags,
62 + struct spawn_fd_item_s *fd_list,
63 + void (*atfork) (void *opaque, int reserved),
64 + void *atforkvalue, pid_t *r_pid)
65 +#endif /*HAVE_MACOS_SYSTEM*/
72 /* Intermediate child to prevent zombie processes. */
73 +#if HAVE_MACOS_SYSTEM
74 + /* tdf#152524 fix crash by skipping second fork()
75 + * Instead of calling a second fork() in the child process, replace
76 + * execv() with posix_spawn(). posix_spawn() does not call any atfork
77 + * handlers so the atfork handler that crashes will be skipped. */
78 +#else /*HAVE_MACOS_SYSTEM*/
79 if ((pid = fork ()) == 0)
81 +#endif /*HAVE_MACOS_SYSTEM*/
89 +#if HAVE_MACOS_SYSTEM
90 + _exit(posix_spawn(NULL, path, NULL, NULL, argv, environ));
91 +#else /*HAVE_MACOS_SYSTEM*/
92 execv (path, (char *const *) argv);
93 /* Hmm: in that case we could write a special status code to the
99 +#endif /*HAVE_MACOS_SYSTEM*/
102 TRACE_LOG ("waiting for child process pid=%i", pid);