summaryrefslogtreecommitdiff
path: root/process.c
diff options
context:
space:
mode:
authorngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-16 13:06:13 +0000
committerngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-16 13:06:13 +0000
commitf242e17f9b011e1e78cf64eabf1d39d67a7ca274 (patch)
tree0c55e26fb6b4a592dc09521917cbd4f5e525a25c /process.c
parent7b08338ab19b635a9da4584ba3ac0ebf845b051e (diff)
* process.c (redirect_dup2): when the new FD of dup2() coflicts
with one of the timer thread FDs, the internal FD is diverted. [Bug #11336] [ruby-core:69886] [Bug #11350] [ruby-core:69961] * process.c (dup2_with_divert): new function for the above purpose. * thread_pthread.c (rb_divert_reserved_fd): new function for diverting reserved FD. If the given FD is the same as one of the reserved FDs, the reserved FD number is internally changed. It returns -1 when error. Otherwise, returns 0. It also returns 0 if there is no need to change reserved FD number. * thread_win32.c (rb_divert_reserved_fd): always returns 0 because of no reserved FDs. * internal.h (rb_divert_reserved_fd): prototype declaration. It is Ruby internal use only. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'process.c')
-rw-r--r--process.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/process.c b/process.c
index 7d3b1f5..daf2eab 100644
--- a/process.c
+++ b/process.c
@@ -305,6 +305,16 @@ close_unless_reserved(int fd)
return close(fd); /* async-signal-safe */
}
+static inline int
+dup2_with_divert(int oldfd, int newfd)
+{
+ if (rb_divert_reserved_fd(newfd) == -1) { /* async-signal-safe if no error occurred */
+ return -1;
+ } else {
+ return dup2(oldfd, newfd); /* async-signal-safe */
+ }
+}
+
/*#define DEBUG_REDIRECT*/
#if defined(DEBUG_REDIRECT)
@@ -344,7 +354,7 @@ static int
redirect_dup2(int oldfd, int newfd)
{
int ret;
- ret = dup2(oldfd, newfd);
+ ret = dup2_with_divert(oldfd, newfd);
ttyprintf("dup2(%d, %d) => %d\n", oldfd, newfd, ret);
return ret;
}
@@ -378,7 +388,7 @@ parent_redirect_close(int fd)
#else
#define redirect_dup(oldfd) dup(oldfd)
-#define redirect_dup2(oldfd, newfd) dup2((oldfd), (newfd))
+#define redirect_dup2(oldfd, newfd) dup2_with_divert((oldfd), (newfd))
#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_unless_reserved(fd)