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().
This commit is contained in:
Masaki Matsushita 2020-12-06 01:16:33 +09:00
parent a38d447356
commit 76439eee68
3 changed files with 17 additions and 12 deletions

View File

@ -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
}

View File

@ -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);

View File

@ -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)
{