summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMasaki Matsushita <glass.saga@gmail.com>2020-12-06 01:16:33 +0900
committerMasaki Matsushita <glass.saga@gmail.com>2020-12-06 01:32:43 +0900
commit76439eee68d2f1e56ac7a6ab38aceacf0b4b40c8 (patch)
treeaaf937f3916e0db6ef96bd24dc9e4d4358caf4eb
parenta38d4473564c5620d272305e91c4133f08034138 (diff)
Call cleanup function for getaddrinfo_a(3) only before fork()
Previously, rb_getaddrinfo_a_before_exec() is called from before_exec(). However, the function needs to be called only before fork(). The change moves it to before_fork().
-rw-r--r--ext/socket/raddrinfo.c4
-rw-r--r--include/ruby/internal/intern/process.h2
-rw-r--r--process.c23
3 files changed, 17 insertions, 12 deletions
diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c
index 249ce035fd..c0cc0f37ea 100644
--- a/ext/socket/raddrinfo.c
+++ b/ext/socket/raddrinfo.c
@@ -442,7 +442,7 @@ gaicbs_wait_all(void)
It cancels all outstanding requests and waits for ongoing requests.
Then, it waits internal worker threads in getaddrinfo_a(3) to be finished. */
void
-rb_getaddrinfo_a_before_exec(void)
+rb_getaddrinfo_a_before_fork(void)
{
gaicbs_cancel_all();
gaicbs_wait_all();
@@ -2875,6 +2875,6 @@ rsock_init_addrinfo(void)
rb_define_method(rb_cAddrinfo, "marshal_load", addrinfo_mload, 1);
#ifdef HAVE_GETADDRINFO_A
- rb_socket_before_exec_func = rb_getaddrinfo_a_before_exec;
+ rb_socket_before_fork_func = rb_getaddrinfo_a_before_fork;
#endif
}
diff --git a/include/ruby/internal/intern/process.h b/include/ruby/internal/intern/process.h
index 5cc0ca242e..fa920cd90a 100644
--- a/include/ruby/internal/intern/process.h
+++ b/include/ruby/internal/intern/process.h
@@ -28,7 +28,7 @@
RBIMPL_SYMBOL_EXPORT_BEGIN()
/* process.c */
-RUBY_EXTERN void (* rb_socket_before_exec_func)();
+RUBY_EXTERN void (* rb_socket_before_fork_func)();
void rb_last_status_set(int status, rb_pid_t pid);
VALUE rb_last_status_get(void);
diff --git a/process.c b/process.c
index 3a0616d6e3..0542aca2e4 100644
--- a/process.c
+++ b/process.c
@@ -332,7 +332,7 @@ 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;
+void (* rb_socket_before_fork_func)() = NULL;
#endif
/* execv and execl are async-signal-safe since SUSv4 (POSIX.1-2008, XPG7) */
@@ -1548,13 +1548,6 @@ 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
@@ -1628,7 +1621,19 @@ after_exec(void)
}
#if defined HAVE_WORKING_FORK || defined HAVE_DAEMON
-#define before_fork_ruby() before_exec()
+static void
+before_fork_ruby(void)
+{
+#ifdef HAVE_GETADDRINFO_A
+ if (rb_socket_before_fork_func) {
+ /* A mitigation for [Bug #17220]. See ext/socket/raddrinfo.c */
+ rb_socket_before_fork_func();
+ }
+#endif
+
+ before_exec();
+}
+
static void
after_fork_ruby(void)
{