mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* process.c: don't check the availability of FD_CLOEXEC. It should
be available if fork() is available. * io.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ba1c1786d6
commit
795c5f9b40
3 changed files with 7 additions and 18 deletions
|
@ -1,3 +1,10 @@
|
|||
Fri Jun 8 23:44:14 2012 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* process.c: don't check the availability of FD_CLOEXEC. It should
|
||||
be available if fork() is available.
|
||||
|
||||
* io.c: ditto.
|
||||
|
||||
Fri Jun 8 22:39:32 2012 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* process.c (rb_fork_err): revert r35955. The condition needs !chfunc
|
||||
|
|
4
io.c
4
io.c
|
@ -5444,14 +5444,10 @@ rb_close_before_exec(int lowfd, int maxhint, VALUE noclose_fds)
|
|||
if (!NIL_P(noclose_fds) &&
|
||||
RTEST(rb_hash_lookup(noclose_fds, INT2FIX(fd)))) /* async-signal-safe */
|
||||
continue;
|
||||
#ifdef FD_CLOEXEC
|
||||
ret = fcntl(fd, F_GETFD); /* async-signal-safe */
|
||||
if (ret != -1 && !(ret & FD_CLOEXEC)) {
|
||||
fcntl(fd, F_SETFD, ret|FD_CLOEXEC); /* async-signal-safe */
|
||||
}
|
||||
#else
|
||||
ret = close(fd); /* async-signal-safe */
|
||||
#endif
|
||||
#define CONTIGUOUS_CLOSED_FDS 20
|
||||
if (ret != -1) {
|
||||
if (max < fd + CONTIGUOUS_CLOSED_FDS)
|
||||
|
|
14
process.c
14
process.c
|
@ -2650,7 +2650,6 @@ rb_exec_atfork(void* arg, char *errmsg, size_t errmsg_buflen)
|
|||
#endif
|
||||
|
||||
#ifdef HAVE_FORK
|
||||
#ifdef FD_CLOEXEC
|
||||
#if SIZEOF_INT == SIZEOF_LONG
|
||||
#define proc_syswait (VALUE (*)(VALUE))rb_syswait
|
||||
#else
|
||||
|
@ -2661,7 +2660,6 @@ proc_syswait(VALUE pid)
|
|||
return Qnil;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static int
|
||||
move_fds_to_avoid_crash(int *fdp, int n, VALUE fds)
|
||||
|
@ -2755,10 +2753,8 @@ rb_fork_err(int *status, int (*chfunc)(void*, char *, size_t), void *charg, VALU
|
|||
{
|
||||
rb_pid_t pid;
|
||||
int err, state = 0;
|
||||
#ifdef FD_CLOEXEC
|
||||
int ep[2];
|
||||
VALUE io = Qnil;
|
||||
#endif
|
||||
|
||||
#define prefork() ( \
|
||||
rb_io_flush(rb_stdout), \
|
||||
|
@ -2766,7 +2762,6 @@ rb_fork_err(int *status, int (*chfunc)(void*, char *, size_t), void *charg, VALU
|
|||
)
|
||||
prefork();
|
||||
|
||||
#ifdef FD_CLOEXEC
|
||||
if (chfunc) {
|
||||
if (status) *status = 0;
|
||||
if (pipe_nocrash(ep, fds)) return -1;
|
||||
|
@ -2775,7 +2770,6 @@ rb_fork_err(int *status, int (*chfunc)(void*, char *, size_t), void *charg, VALU
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
for (; before_fork(), (pid = fork()) < 0; prefork()) {
|
||||
after_fork();
|
||||
switch (errno) {
|
||||
|
@ -2799,11 +2793,9 @@ rb_fork_err(int *status, int (*chfunc)(void*, char *, size_t), void *charg, VALU
|
|||
}
|
||||
/* fall through */
|
||||
default:
|
||||
#ifdef FD_CLOEXEC
|
||||
if (chfunc) {
|
||||
preserving_errno((close(ep[0]), close(ep[1])));
|
||||
}
|
||||
#endif
|
||||
if (state && !status) rb_jump_tag(state);
|
||||
return -1;
|
||||
}
|
||||
|
@ -2816,11 +2808,8 @@ rb_fork_err(int *status, int (*chfunc)(void*, char *, size_t), void *charg, VALU
|
|||
arg.arg = charg;
|
||||
arg.errmsg = errmsg;
|
||||
arg.buflen = errmsg_buflen;
|
||||
#ifdef FD_CLOEXEC
|
||||
close(ep[0]);
|
||||
#endif
|
||||
if (!(int)rb_protect(chfunc_protect, (VALUE)&arg, &state)) _exit(EXIT_SUCCESS);
|
||||
#ifdef FD_CLOEXEC
|
||||
if (write(ep[1], &state, sizeof(state)) == sizeof(state) && state) {
|
||||
VALUE errinfo = rb_errinfo();
|
||||
io = rb_io_fdopen(ep[1], O_WRONLY|O_BINARY, NULL);
|
||||
|
@ -2836,7 +2825,6 @@ rb_fork_err(int *status, int (*chfunc)(void*, char *, size_t), void *charg, VALU
|
|||
err = errno;
|
||||
}
|
||||
if (!NIL_P(io)) rb_io_close(io);
|
||||
#endif
|
||||
#if EXIT_SUCCESS == 127
|
||||
_exit(EXIT_FAILURE);
|
||||
#else
|
||||
|
@ -2845,7 +2833,6 @@ rb_fork_err(int *status, int (*chfunc)(void*, char *, size_t), void *charg, VALU
|
|||
}
|
||||
}
|
||||
after_fork();
|
||||
#ifdef FD_CLOEXEC
|
||||
if (pid && chfunc) {
|
||||
ssize_t size;
|
||||
VALUE exc = Qnil;
|
||||
|
@ -2884,7 +2871,6 @@ rb_fork_err(int *status, int (*chfunc)(void*, char *, size_t), void *charg, VALU
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return pid;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue