summaryrefslogtreecommitdiff
path: root/process.c
diff options
context:
space:
mode:
authorMasaki Matsushita <glass.saga@gmail.com>2020-11-26 16:07:28 +0900
committerMasaki Matsushita <glass.saga@gmail.com>2020-12-04 23:31:51 +0900
commit94d49ed31c39002335eeee65d42463139f561954 (patch)
tree86ca5d184fb8e52540664ec8b087bdb93a2e0c5b /process.c
parent1cfc6e7b7a92c1a624182392ba702d3dcb2eba98 (diff)
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]
Diffstat (limited to 'process.c')
-rw-r--r--process.c10
1 files changed, 10 insertions, 0 deletions
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