summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--configure.in5
-rw-r--r--io.c38
-rw-r--r--process.c30
4 files changed, 45 insertions, 36 deletions
diff --git a/ChangeLog b/ChangeLog
index e21995c7b9..26509650b6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Wed Sep 3 07:50:15 2014 Tanaka Akira <akr@fsij.org>
+
+ * configure.in: Use AC_FUNC_FORK.
+
+ * io.c: Use HAVE_WORKING_FORK instead of HAVE_FORK.
+
+ * process.c: Ditto.
+
Wed Sep 3 00:12:44 2014 Tanaka Akira <akr@fsij.org>
* process.c (retry_fork_async_signal_safe): Don't return on in child
diff --git a/configure.in b/configure.in
index 19b2522648..5bd006f865 100644
--- a/configure.in
+++ b/configure.in
@@ -1962,6 +1962,8 @@ else
AC_LIBOBJ([signbit])
fi
+AC_FUNC_FORK
+
AC_CHECK_FUNCS(__syscall)
AC_CHECK_FUNCS(_longjmp) # used for AC_ARG_WITH(setjmp-type)
AC_CHECK_FUNCS(_setjmp) # used for AC_ARG_WITH(setjmp-type)
@@ -1984,7 +1986,6 @@ AC_CHECK_FUNCS(fchown)
AC_CHECK_FUNCS(fcntl)
AC_CHECK_FUNCS(fdatasync)
AC_CHECK_FUNCS(fmod)
-AC_CHECK_FUNCS(fork)
AC_CHECK_FUNCS(fsync)
AC_CHECK_FUNCS(ftruncate)
AC_CHECK_FUNCS(ftruncate64) # used for Win32 platform
@@ -2662,7 +2663,7 @@ if test x"$ac_cv_header_ucontext_h" = xyes; then
fi
fi
-if test "$ac_cv_func_fork" = "yes" -a "$rb_with_pthread" = "yes"; then
+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([
#include <stdlib.h>
diff --git a/io.c b/io.c
index e55caeafcf..7301cbd6d3 100644
--- a/io.c
+++ b/io.c
@@ -5665,7 +5665,7 @@ rb_file_open(const char *fname, const char *modestr)
return rb_file_open_internal(io_alloc(rb_cFile), rb_str_new_cstr(fname), modestr);
}
-#if defined(__CYGWIN__) || !defined(HAVE_FORK)
+#if defined(__CYGWIN__) || !defined(HAVE_WORKING_FORK)
static struct pipe_list {
rb_io_t *fptr;
struct pipe_list *next;
@@ -5721,7 +5721,7 @@ pipe_atexit(void)
static void
pipe_finalize(rb_io_t *fptr, int noraise)
{
-#if !defined(HAVE_FORK) && !defined(_WIN32)
+#if !defined(HAVE_WORKING_FORK) && !defined(_WIN32)
int status = 0;
if (fptr->stdio_file) {
status = pclose(fptr->stdio_file);
@@ -5773,7 +5773,7 @@ rb_pipe(int *pipes)
#define spawn(mode, cmd) rb_w32_uspawn((mode), (cmd), 0)
#endif
-#if defined(HAVE_FORK) || defined(HAVE_SPAWNV)
+#if defined(HAVE_WORKING_FORK) || defined(HAVE_SPAWNV)
struct popen_arg {
VALUE execarg_obj;
struct rb_execarg *eargp;
@@ -5783,7 +5783,7 @@ struct popen_arg {
};
#endif
-#ifdef HAVE_FORK
+#ifdef HAVE_WORKING_FORK
static void
popen_redirect(struct popen_arg *p)
{
@@ -5918,11 +5918,11 @@ pipe_open(VALUE execarg_obj, const char *modestr, int fmode, convconfig_t *convc
VALUE port;
rb_io_t *write_fptr;
VALUE write_port;
-#if defined(HAVE_FORK)
+#if defined(HAVE_WORKING_FORK)
int status;
char errmsg[80] = { '\0' };
#endif
-#if defined(HAVE_FORK) || defined(HAVE_SPAWNV)
+#if defined(HAVE_WORKING_FORK) || defined(HAVE_SPAWNV)
int state;
struct popen_arg arg;
int e = 0;
@@ -5937,20 +5937,20 @@ pipe_open(VALUE execarg_obj, const char *modestr, int fmode, convconfig_t *convc
spawnv(P_NOWAIT, (cmd), (args)) : \
spawn(P_NOWAIT, (cmd)))
# endif
-# if !defined(HAVE_FORK)
+# if !defined(HAVE_WORKING_FORK)
char **args = NULL;
# if defined(HAVE_SPAWNVE)
char **envp = NULL;
# endif
# endif
#endif
-#if !defined(HAVE_FORK)
+#if !defined(HAVE_WORKING_FORK)
struct rb_execarg sarg, *sargp = &sarg;
#endif
FILE *fp = 0;
int fd = -1;
int write_fd = -1;
-#if !defined(HAVE_FORK)
+#if !defined(HAVE_WORKING_FORK)
const char *cmd = 0;
#if !defined(HAVE_SPAWNV)
int argc;
@@ -5961,13 +5961,13 @@ pipe_open(VALUE execarg_obj, const char *modestr, int fmode, convconfig_t *convc
cmd = StringValueCStr(prog);
#endif
-#if defined(HAVE_FORK) || defined(HAVE_SPAWNV)
+#if defined(HAVE_WORKING_FORK) || defined(HAVE_SPAWNV)
arg.execarg_obj = execarg_obj;
arg.eargp = eargp;
arg.modef = fmode;
arg.pair[0] = arg.pair[1] = -1;
arg.write_pair[0] = arg.write_pair[1] = -1;
-# if !defined(HAVE_FORK)
+# if !defined(HAVE_WORKING_FORK)
if (eargp && !eargp->use_shell) {
args = ARGVSTR2ARGV(eargp->invoke.cmd.argv_str);
}
@@ -6013,7 +6013,7 @@ pipe_open(VALUE execarg_obj, const char *modestr, int fmode, convconfig_t *convc
rb_jump_tag(state);
}
-# if defined(HAVE_FORK)
+# if defined(HAVE_WORKING_FORK)
pid = rb_fork_async_signal_safe(&status, popen_exec, &arg, arg.eargp->redirect_fds, errmsg, sizeof(errmsg));
# else
rb_execarg_run_options(eargp, sargp, NULL, 0);
@@ -6037,7 +6037,7 @@ pipe_open(VALUE execarg_obj, const char *modestr, int fmode, convconfig_t *convc
# endif
}
else {
-# if defined(HAVE_FORK)
+# if defined(HAVE_WORKING_FORK)
pid = rb_fork_ruby(&status);
if (pid == 0) { /* child */
rb_thread_atfork();
@@ -6053,7 +6053,7 @@ pipe_open(VALUE execarg_obj, const char *modestr, int fmode, convconfig_t *convc
/* parent */
if (pid == -1) {
-# if defined(HAVE_FORK)
+# if defined(HAVE_WORKING_FORK)
e = errno;
# endif
close(arg.pair[0]);
@@ -6063,7 +6063,7 @@ pipe_open(VALUE execarg_obj, const char *modestr, int fmode, convconfig_t *convc
close(arg.write_pair[1]);
}
errno = e;
-# if defined(HAVE_FORK)
+# if defined(HAVE_WORKING_FORK)
if (errmsg[0])
rb_sys_fail(errmsg);
# endif
@@ -6134,7 +6134,7 @@ pipe_open(VALUE execarg_obj, const char *modestr, int fmode, convconfig_t *convc
rb_ivar_set(port, rb_intern("@tied_io_for_writing"), write_port);
}
-#if defined (__CYGWIN__) || !defined(HAVE_FORK)
+#if defined (__CYGWIN__) || !defined(HAVE_WORKING_FORK)
fptr->finalize = pipe_finalize;
pipe_add_fptr(fptr);
#endif
@@ -6145,7 +6145,7 @@ static int
is_popen_fork(VALUE prog)
{
if (RSTRING_LEN(prog) == 1 && RSTRING_PTR(prog)[0] == '-') {
-#if !defined(HAVE_FORK)
+#if !defined(HAVE_WORKING_FORK)
rb_raise(rb_eNotImpError,
"fork() function is unimplemented on this machine");
#else
@@ -6669,7 +6669,7 @@ io_reopen(VALUE io, VALUE nfile)
if (RTEST(orig->pathv)) fptr->pathv = orig->pathv;
else if (!IS_PREP_STDIO(fptr)) fptr->pathv = Qnil;
fptr->finalize = orig->finalize;
-#if defined (__CYGWIN__) || !defined(HAVE_FORK)
+#if defined (__CYGWIN__) || !defined(HAVE_WORKING_FORK)
if (fptr->finalize == pipe_finalize)
pipe_add_fptr(fptr);
#endif
@@ -6837,7 +6837,7 @@ rb_io_init_copy(VALUE dest, VALUE io)
fptr->lineno = orig->lineno;
if (!NIL_P(orig->pathv)) fptr->pathv = orig->pathv;
fptr->finalize = orig->finalize;
-#if defined (__CYGWIN__) || !defined(HAVE_FORK)
+#if defined (__CYGWIN__) || !defined(HAVE_WORKING_FORK)
if (fptr->finalize == pipe_finalize)
pipe_add_fptr(fptr);
#endif
diff --git a/process.c b/process.c
index c08ad8c223..89f829c846 100644
--- a/process.c
+++ b/process.c
@@ -1181,7 +1181,7 @@ security(const char *str)
}
}
-#if defined(HAVE_FORK) && !defined(__native_client__)
+#if defined(HAVE_WORKING_FORK) && !defined(__native_client__)
/* try_with_sh and exec_with_sh should be async-signal-safe. Actually it is.*/
#define try_with_sh(prog, argv, envp) ((saved_errno == ENOEXEC) ? exec_with_sh((prog), (argv), (envp)) : (void)0)
@@ -1382,7 +1382,7 @@ export_dup(VALUE str)
# define EXPORT_DUP(str) rb_str_dup(str)
#endif
-#if !defined(HAVE_FORK) && defined(HAVE_SPAWNV)
+#if !defined(HAVE_WORKING_FORK) && defined(HAVE_SPAWNV)
# define USE_SPAWNV 1
#else
# define USE_SPAWNV 0
@@ -2883,7 +2883,7 @@ run_exec_rlimit(VALUE ary, struct rb_execarg *sargp, char *errmsg, size_t errmsg
}
#endif
-#if !defined(HAVE_FORK)
+#if !defined(HAVE_WORKING_FORK)
static VALUE
save_env_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, ary))
{
@@ -2937,7 +2937,7 @@ rb_execarg_run_options(const struct rb_execarg *eargp, struct rb_execarg *sargp,
}
#endif
-#if !defined(HAVE_FORK)
+#if !defined(HAVE_WORKING_FORK)
if (eargp->unsetenv_others_given && eargp->unsetenv_others_do) {
save_env(sargp);
rb_env_clear();
@@ -2984,7 +2984,7 @@ rb_execarg_run_options(const struct rb_execarg *eargp, struct rb_execarg *sargp,
}
}
-#ifdef HAVE_FORK
+#ifdef HAVE_WORKING_FORK
if (!eargp->close_others_given || eargp->close_others_do) {
rb_close_before_exec(3, eargp->close_others_maxhint, eargp->redirect_fds); /* async-signal-safe */
}
@@ -3049,7 +3049,7 @@ rb_execarg_run_options(const struct rb_execarg *eargp, struct rb_execarg *sargp,
int
rb_exec_async_signal_safe(const struct rb_execarg *eargp, char *errmsg, size_t errmsg_buflen)
{
-#if !defined(HAVE_FORK)
+#if !defined(HAVE_WORKING_FORK)
struct rb_execarg sarg, *const sargp = &sarg;
#else
struct rb_execarg *const sargp = NULL;
@@ -3070,7 +3070,7 @@ rb_exec_async_signal_safe(const struct rb_execarg *eargp, char *errmsg, size_t e
abspath = RSTRING_PTR(eargp->invoke.cmd.command_abspath);
proc_exec_cmd(abspath, eargp->invoke.cmd.argv_str, eargp->envp_str); /* async-signal-safe */
}
-#if !defined(HAVE_FORK)
+#if !defined(HAVE_WORKING_FORK)
preserving_errno(rb_execarg_run_options(sargp, NULL, errmsg, errmsg_buflen));
#endif
@@ -3091,7 +3091,7 @@ rb_exec_without_timer_thread(const struct rb_execarg *eargp, char *errmsg, size_
}
#endif
-#ifdef HAVE_FORK
+#ifdef HAVE_WORKING_FORK
/* This function should be async-signal-safe. Hopefully it is. */
static int
rb_exec_atfork(void* arg, char *errmsg, size_t errmsg_buflen)
@@ -3100,7 +3100,7 @@ rb_exec_atfork(void* arg, char *errmsg, size_t errmsg_buflen)
}
#endif
-#ifdef HAVE_FORK
+#ifdef HAVE_WORKING_FORK
#if SIZEOF_INT == SIZEOF_LONG
#define proc_syswait (VALUE (*)(VALUE))rb_syswait
#else
@@ -3387,7 +3387,7 @@ rb_fork_ruby(int *status)
#endif
-#if defined(HAVE_FORK) && !defined(CANNOT_FORK_WITH_PTHREAD)
+#if defined(HAVE_WORKING_FORK) && !defined(CANNOT_FORK_WITH_PTHREAD)
/*
* call-seq:
* Kernel.fork [{ block }] -> fixnum or nil
@@ -3617,12 +3617,12 @@ rb_spawn_process(struct rb_execarg *eargp, char *errmsg, size_t errmsg_buflen)
#if !USE_SPAWNV
int status;
#endif
-#if !defined HAVE_FORK || USE_SPAWNV
+#if !defined HAVE_WORKING_FORK || USE_SPAWNV
VALUE prog;
struct rb_execarg sarg;
#endif
-#if defined HAVE_FORK && !USE_SPAWNV
+#if defined HAVE_WORKING_FORK && !USE_SPAWNV
pid = rb_fork_async_signal_safe(&status, rb_exec_atfork, eargp, eargp->redirect_fds, errmsg, errmsg_buflen);
#else
prog = eargp->use_shell ? eargp->invoke.sh.shell_script : eargp->invoke.cmd.command_name;
@@ -3737,7 +3737,7 @@ rb_f_system(int argc, VALUE *argv)
chfunc = signal(SIGCHLD, SIG_DFL);
#endif
pid = rb_spawn_internal(argc, argv, NULL, 0);
-#if defined(HAVE_FORK) || defined(HAVE_SPAWNV)
+#if defined(HAVE_WORKING_FORK) || defined(HAVE_SPAWNV)
if (pid > 0) {
int ret, status;
ret = rb_waitpid(pid, &status, 0);
@@ -4045,7 +4045,7 @@ rb_f_spawn(int argc, VALUE *argv)
}
rb_sys_fail(prog);
}
-#if defined(HAVE_FORK) || defined(HAVE_SPAWNV)
+#if defined(HAVE_WORKING_FORK) || defined(HAVE_SPAWNV)
return PIDT2NUM(pid);
#else
return Qnil;
@@ -5681,7 +5681,7 @@ proc_setmaxgroups(VALUE obj, VALUE val)
#define proc_setmaxgroups rb_f_notimplement
#endif
-#if defined(HAVE_DAEMON) || (defined(HAVE_FORK) && defined(HAVE_SETSID))
+#if defined(HAVE_DAEMON) || (defined(HAVE_WORKING_FORK) && defined(HAVE_SETSID))
static int rb_daemon(int nochdir, int noclose);
/*