1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* process.c (redirect_close, parent_redirect_close): should not close

reserved FD. It should be closed in the exec system call due to the
  O_CLOEXEC or FD_CLOEXEC flag. [Bug #11353] [ruby-core:69977]
    
* process.c (close_unless_reserved): new function to close FD unless
  it is reserved for internal communication.
      
* thread_pthread.c (rb_reserved_fd_p): should check owner_process pid
  to avoid false positive in forked child process.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51255 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ngoto 2015-07-15 14:26:22 +00:00
parent ae406d9e09
commit d1bce9ec55
3 changed files with 31 additions and 8 deletions

View file

@ -1,3 +1,15 @@
Wed Jul 15 23:01:22 2015 Naohisa Goto <ngotogenome@gmail.com>
* process.c (redirect_close, parent_redirect_close): should not close
reserved FD. It should be closed in the exec system call due to the
O_CLOEXEC or FD_CLOEXEC flag. [Bug #11353] [ruby-core:69977]
* process.c (close_unless_reserved): new function to close FD unless
it is reserved for internal communication.
* thread_pthread.c (rb_reserved_fd_p): should check owner_process pid
to avoid false positive in forked child process.
Wed Jul 15 18:31:18 2015 Eric Wong <e@80x24.org>
* proc.c (proc_mark): remove redundant check

View file

@ -294,6 +294,16 @@ extern ID ruby_static_id_status;
#define ALWAYS_NEED_ENVP 0
#endif
static inline int close_unless_reserved(fd)
{
/* Do nothing to the reserved fd because it should be closed in exec(2)
due to the O_CLOEXEC or FD_CLOEXEC flag. */
if (rb_reserved_fd_p(fd)) { /* async-signal-safe */
return 0;
}
return close(fd); /* async-signal-safe */
}
/*#define DEBUG_REDIRECT*/
#if defined(DEBUG_REDIRECT)
@ -342,7 +352,7 @@ static int
redirect_close(int fd)
{
int ret;
ret = close(fd);
ret = close_unless_reserved(fd);
ttyprintf("close(%d) => %d\n", fd, ret);
return ret;
}
@ -360,7 +370,7 @@ static int
parent_redirect_close(int fd)
{
int ret;
ret = close(fd);
ret = close_unless_reserved(fd);
ttyprintf("parent_close(%d) => %d\n", fd, ret);
return ret;
}
@ -368,9 +378,9 @@ parent_redirect_close(int fd)
#else
#define redirect_dup(oldfd) dup(oldfd)
#define redirect_dup2(oldfd, newfd) dup2((oldfd), (newfd))
#define redirect_close(fd) close(fd)
#define redirect_close(fd) close_unless_reserved(fd)
#define parent_redirect_open(pathname, flags, perm) rb_cloexec_open((pathname), (flags), (perm))
#define parent_redirect_close(fd) close(fd)
#define parent_redirect_close(fd) close_unless_reserved(fd)
#endif
/*

View file

@ -1692,10 +1692,11 @@ int
rb_reserved_fd_p(int fd)
{
#if USE_SLEEPY_TIMER_THREAD
if (fd == timer_thread_pipe.normal[0] ||
fd == timer_thread_pipe.normal[1] ||
fd == timer_thread_pipe.low[0] ||
fd == timer_thread_pipe.low[1]) {
if ((fd == timer_thread_pipe.normal[0] ||
fd == timer_thread_pipe.normal[1] ||
fd == timer_thread_pipe.low[0] ||
fd == timer_thread_pipe.low[1]) &&
timer_thread_pipe.owner_process == getpid()) { /* async-signal-safe */
return 1;
}
else {