diff options
author | ngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-15 14:26:22 +0000 |
---|---|---|
committer | ngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-15 14:26:22 +0000 |
commit | d367f7df0e753bc6ba4f4623cc77da5bf7ecd1fd (patch) | |
tree | 815ae3e106a6a6741fc7dfdb93215a05d9c0f875 | |
parent | 533d985e59f2afd70d51a39356c3f2abc910cdc4 (diff) | |
download | ruby-d367f7df0e753bc6ba4f4623cc77da5bf7ecd1fd.tar.gz |
* 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
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | process.c | 18 | ||||
-rw-r--r-- | thread_pthread.c | 9 |
3 files changed, 31 insertions, 8 deletions
@@ -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 @@ -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 /* diff --git a/thread_pthread.c b/thread_pthread.c index 84228c8c53..71edee18b0 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -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 { |