[前][次][番号順一覧][スレッド一覧]

ruby-changes:63961

From: Masaki <ko1@a...>
Date: Sun, 6 Dec 2020 01:33:07 +0900 (JST)
Subject: [ruby-changes:63961] 76439eee68 (master): Call cleanup function for getaddrinfo_a(3) only before fork()

https://git.ruby-lang.org/ruby.git/commit/?id=76439eee68

From 76439eee68d2f1e56ac7a6ab38aceacf0b4b40c8 Mon Sep 17 00:00:00 2001
From: Masaki Matsushita <glass.saga@g...>
Date: Sun, 6 Dec 2020 01:16:33 +0900
Subject: 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().

diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c
index 249ce03..c0cc0f3 100644
--- a/ext/socket/raddrinfo.c
+++ b/ext/socket/raddrinfo.c
@@ -442,7 +442,7 @@ gaicbs_wait_all(void) https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L442
     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) https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L2875
     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 5cc0ca2..fa920cd 100644
--- a/include/ruby/internal/intern/process.h
+++ b/include/ruby/internal/intern/process.h
@@ -28,7 +28,7 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/intern/process.h#L28
 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 3a0616d..0542aca 100644
--- a/process.c
+++ b/process.c
@@ -332,7 +332,7 @@ static ID id_MACH_ABSOLUTE_TIME_BASED_CLOCK_MONOTONIC; https://github.com/ruby/ruby/blob/trunk/process.c#L332
 #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) https://github.com/ruby/ruby/blob/trunk/process.c#L1548
 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) https://github.com/ruby/ruby/blob/trunk/process.c#L1621
 }
 
 #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)
 {
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]