From 94d49ed31c39002335eeee65d42463139f561954 Mon Sep 17 00:00:00 2001 From: Masaki Matsushita Date: Thu, 26 Nov 2020 16:07:28 +0900 Subject: Add a hook before fork() for getaddrinfo_a() We need stop worker threads in getaddrinfo_a() before fork(). This change adds a hook before fork() that cancel all outstanding requests and wait for all ongoing requests. Then, it waits for all worker threads to be finished. Fixes [Bug #17220] --- process.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'process.c') diff --git a/process.c b/process.c index 612d319947..3a0616d6e3 100644 --- a/process.c +++ b/process.c @@ -331,6 +331,9 @@ static ID id_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID; static ID id_MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC; #endif static ID id_hertz; +#ifdef HAVE_GETADDRINFO_A +void (* rb_socket_before_exec_func)() = NULL; +#endif /* execv and execl are async-signal-safe since SUSv4 (POSIX.1-2008, XPG7) */ #if defined(__sun) && !defined(_XPG7) /* Solaris 10, 9, ... */ @@ -1545,6 +1548,13 @@ before_exec_async_signal_safe(void) static void before_exec_non_async_signal_safe(void) { +#ifdef HAVE_GETADDRINFO_A + if (rb_socket_before_exec_func) { + /* A mitigation for [Bug #17220]. See ext/socket/raddrinfo.c */ + rb_socket_before_exec_func(); + } +#endif + /* * On Mac OS X 10.5.x (Leopard) or earlier, exec() may return ENOTSUP * if the process have multiple threads. Therefore we have to kill -- cgit v1.2.3