mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
* io.c (rb_cloexec_dup2): check oldfd == newfd at first.
pointed by KOSAKI Motohiro. [ruby-dev:44713] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33579 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
bdc85361e4
commit
da5ae5544d
2 changed files with 27 additions and 15 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Mon Oct 31 12:05:24 2011 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* io.c (rb_cloexec_dup2): check oldfd == newfd at first.
|
||||||
|
pointed by KOSAKI Motohiro. [ruby-dev:44713]
|
||||||
|
|
||||||
Mon Oct 31 10:50:26 2011 NAKAMURA Usaku <usa@ruby-lang.org>
|
Mon Oct 31 10:50:26 2011 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* io.c (rb_cloexec_fcntl_dupfd): this function needs F_DUPFD.
|
* io.c (rb_cloexec_fcntl_dupfd): this function needs F_DUPFD.
|
||||||
|
|
7
io.c
7
io.c
|
@ -239,6 +239,12 @@ rb_cloexec_dup2(int oldfd, int newfd)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
/* When oldfd == newfd, dup2 succeeds but dup3 fails with EINVAL.
|
||||||
|
* rb_cloexec_dup2 succeeds as dup2. */
|
||||||
|
if (oldfd == newfd) {
|
||||||
|
ret = newfd;
|
||||||
|
}
|
||||||
|
else {
|
||||||
#if defined(HAVE_DUP3) && defined(O_CLOEXEC)
|
#if defined(HAVE_DUP3) && defined(O_CLOEXEC)
|
||||||
static int try_dup3 = 1;
|
static int try_dup3 = 1;
|
||||||
if (2 < newfd && try_dup3) {
|
if (2 < newfd && try_dup3) {
|
||||||
|
@ -258,6 +264,7 @@ rb_cloexec_dup2(int oldfd, int newfd)
|
||||||
ret = dup2(oldfd, newfd);
|
ret = dup2(oldfd, newfd);
|
||||||
#endif
|
#endif
|
||||||
if (ret == -1) return -1;
|
if (ret == -1) return -1;
|
||||||
|
}
|
||||||
fd_set_cloexec(ret);
|
fd_set_cloexec(ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue