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

ruby-changes:35357

From: nobu <ko1@a...>
Date: Sun, 7 Sep 2014 10:10:55 +0900 (JST)
Subject: [ruby-changes:35357] nobu:r47439 (trunk): process.c: vfork may not work with pthread

nobu	2014-09-07 10:10:43 +0900 (Sun, 07 Sep 2014)

  New Revision: 47439

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47439

  Log:
    process.c: vfork may not work with pthread
    
    * process.c (retry_fork_async_signal_safe): vfork may not work
      with pthread always even if fork works with it.

  Modified files:
    trunk/configure.in
    trunk/process.c
Index: configure.in
===================================================================
--- configure.in	(revision 47438)
+++ configure.in	(revision 47439)
@@ -2669,9 +2669,11 @@ if test x"$ac_cv_header_ucontext_h" = xy https://github.com/ruby/ruby/blob/trunk/configure.in#L2669
     fi
 fi
 
-if test "$ac_cv_func_fork_works" = "yes" -a "$rb_with_pthread" = "yes"; then
-    AC_CACHE_CHECK([if fork works with pthread], rb_cv_fork_with_pthread,
-	[AC_TRY_RUN([
+if test "$rb_with_pthread" = "yes"; then
+    for f in fork vfork; do
+	if eval 'test "$ac_cv_func_'$f'_works" = "yes"'; then
+	    AC_CACHE_CHECK([if $f works with pthread], rb_cv_${f}_with_pthread,
+		[AC_TRY_RUN([
 #include <stdlib.h>
 #include <unistd.h>
 #include <pthread.h>
@@ -2710,7 +2712,7 @@ main(int argc, char *argv[]) https://github.com/ruby/ruby/blob/trunk/configure.in#L2712
 {
     pid_t pid;
     if (use_threads()) return EXIT_FAILURE;
-    pid = fork();
+    pid = $f();
 
     if (pid) {
 	int loc;
@@ -2728,10 +2730,14 @@ main(int argc, char *argv[]) https://github.com/ruby/ruby/blob/trunk/configure.in#L2730
 
     return EXIT_SUCCESS;
 }],
-	rb_cv_fork_with_pthread=yes,
-	rb_cv_fork_with_pthread=no,
-	rb_cv_fork_with_pthread=yes)])
+		work=yes,
+		work=no,
+		work=yes)]
+	    eval rb_cv_${f}_with_pthread=$work)
+	fi
+    done
     test x$rb_cv_fork_with_pthread = xyes || AC_DEFINE(CANNOT_FORK_WITH_PTHREAD)
+    test x$rb_cv_vfork_with_pthread = xyes || AC_DEFINE(CANNOT_VFORK_WITH_PTHREAD)
 fi
 
 
Index: process.c
===================================================================
--- process.c	(revision 47438)
+++ process.c	(revision 47439)
@@ -3281,6 +3281,7 @@ recv_child_error(int fd, int *errp, char https://github.com/ruby/ruby/blob/trunk/process.c#L3281
     return size != 0;
 }
 
+#if defined(HAVE_WORKING_VFORK) && !defined(CANNOT_VFORK_WITH_PTHREAD)
 #if !defined(HAVE_GETRESUID) && defined(HAVE_GETUIDX)
 /* AIX 7.1 */
 static int
@@ -3378,6 +3379,7 @@ has_privilege(void) https://github.com/ruby/ruby/blob/trunk/process.c#L3379
 
     return 0;
 }
+#endif
 
 struct child_handler_disabler_state
 {
@@ -3489,7 +3491,7 @@ retry_fork_async_signal_safe(int *status https://github.com/ruby/ruby/blob/trunk/process.c#L3491
     while (1) {
         prefork();
         disable_child_handler_before_fork(&old);
-#ifdef HAVE_WORKING_VFORK
+#if defined(HAVE_WORKING_VFORK) && !defined(CANNOT_VFORK_WITH_PTHREAD)
         if (!has_privilege())
             pid = vfork();
         else

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

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