tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / external / gpgmepp / macos-tdf152524.patch
blobc1cdd047dba8778311d616fccc5f9ec3416d740b
1 --- src/posix-io.c 2023-02-01 11:50:48
2 +++ src/posix-io.c 2024-03-21 09:50:24
3 @@ -67,6 +67,13 @@
4 #include "priv-io.h"
5 #include "sema.h"
6 #include "debug.h"
8 +#if HAVE_MACOS_SYSTEM
9 +#include <dispatch/dispatch.h>
10 +#include <spawn.h>
12 +extern char **environ;
13 +#endif
16 #ifdef USE_LINUX_GETDENTS
17 @@ -515,6 +522,15 @@
19 return 0;
23 +#if HAVE_MACOS_SYSTEM
24 +static int
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. */
33 @@ -523,6 +539,35 @@
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;
44 + if (!queue)
45 + queue = dispatch_queue_create ("gpgmepp",
46 + DISPATCH_QUEUE_CONCURRENT);
47 + if (!queue)
48 + return -1;
50 + __block int ret = -1;
51 + dispatch_sync(queue, ^{
52 + ret = _gpgme_io_spawn_macos (path, argv, flags,
53 + fd_list, atfork,
54 + atforkvalue, r_pid);
55 + });
57 + return ret;
60 +static int
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*/
67 pid_t pid;
68 int i;
69 @@ -552,8 +597,15 @@
70 if (!pid)
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*/
82 /* Child. */
83 int max_fds = -1;
84 int fd;
85 @@ -664,6 +716,9 @@
86 close (fd);
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
94 status-pipe. */
95 @@ -674,6 +729,7 @@
96 _exit (1);
97 else
98 _exit (0);
99 +#endif /*HAVE_MACOS_SYSTEM*/
102 TRACE_LOG ("waiting for child process pid=%i", pid);