From c67b08300a7fcec8e47af37d7882f78f23bb05e2 Mon Sep 17 00:00:00 2001 From: Hein-Pieter van Braam Date: Thu, 9 Feb 2017 22:01:45 +0100 Subject: [PATCH] Add a simple signal handler for SIGCHLD on Unix This fixes #6631 (cherry picked from commit cff6840ff7da010112b94f9be13deaa8288e90cd) --- drivers/unix/os_unix.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 7fcaab870d..ce5712f24d 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -115,6 +115,13 @@ int OS_Unix::unix_initialize_audio(int p_audio_driver) { static MemoryPoolStaticMalloc *mempool_static=NULL; static MemoryPoolDynamicStatic *mempool_dynamic=NULL; +// Very simple signal handler to reap processes where ::execute was called with +// !p_blocking +void handle_sigchld(int sig) { + int saved_errno = errno; + while (waitpid((pid_t)(-1), 0, WNOHANG) > 0) {} + errno = saved_errno; +} void OS_Unix::initialize_core() { @@ -146,6 +153,14 @@ void OS_Unix::initialize_core() { ticks_start=0; ticks_start=get_ticks_usec(); + + struct sigaction sa; + sa.sa_handler = &handle_sigchld; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_RESTART | SA_NOCLDSTOP; + if (sigaction(SIGCHLD, &sa, 0) == -1) { + perror("ERROR sigaction() failed:"); + } } void OS_Unix::finalize_core() {