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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-09-07 01:10:43 +00:00
parent 11a8187bd1
commit e81a0d8f36
2 changed files with 16 additions and 8 deletions

View File

@ -2669,8 +2669,10 @@ if test x"$ac_cv_header_ucontext_h" = xyes; then
fi fi
fi fi
if test "$ac_cv_func_fork_works" = "yes" -a "$rb_with_pthread" = "yes"; then if test "$rb_with_pthread" = "yes"; then
AC_CACHE_CHECK([if fork works with pthread], rb_cv_fork_with_pthread, 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([ [AC_TRY_RUN([
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
@ -2710,7 +2712,7 @@ main(int argc, char *argv[])
{ {
pid_t pid; pid_t pid;
if (use_threads()) return EXIT_FAILURE; if (use_threads()) return EXIT_FAILURE;
pid = fork(); pid = $f();
if (pid) { if (pid) {
int loc; int loc;
@ -2728,10 +2730,14 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
}], }],
rb_cv_fork_with_pthread=yes, work=yes,
rb_cv_fork_with_pthread=no, work=no,
rb_cv_fork_with_pthread=yes)]) 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_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 fi

View File

@ -3281,6 +3281,7 @@ recv_child_error(int fd, int *errp, char *errmsg, size_t errmsg_buflen)
return size != 0; return size != 0;
} }
#if defined(HAVE_WORKING_VFORK) && !defined(CANNOT_VFORK_WITH_PTHREAD)
#if !defined(HAVE_GETRESUID) && defined(HAVE_GETUIDX) #if !defined(HAVE_GETRESUID) && defined(HAVE_GETUIDX)
/* AIX 7.1 */ /* AIX 7.1 */
static int static int
@ -3378,6 +3379,7 @@ has_privilege(void)
return 0; return 0;
} }
#endif
struct child_handler_disabler_state struct child_handler_disabler_state
{ {
@ -3489,7 +3491,7 @@ retry_fork_async_signal_safe(int *status, int *ep,
while (1) { while (1) {
prefork(); prefork();
disable_child_handler_before_fork(&old); disable_child_handler_before_fork(&old);
#ifdef HAVE_WORKING_VFORK #if defined(HAVE_WORKING_VFORK) && !defined(CANNOT_VFORK_WITH_PTHREAD)
if (!has_privilege()) if (!has_privilege())
pid = vfork(); pid = vfork();
else else