From 027748a314899b45e7a57993a16ab8284ecefc10 Mon Sep 17 00:00:00 2001 From: usa Date: Fri, 12 Sep 2014 02:20:06 +0000 Subject: [PATCH] merge revision(s) 43373: [Backport #9036] * io.c (rb_io_reopen): create a new, temporary FD via rb_sysopen and call rb_cloexec_dup2 on it to atomically replace the file fptr->fd points to. This leaves no possible window where fptr->fd is invalid to userspace (even for any threads running w/o GVL). based on the patch by Eric Wong at [ruby-core:57943]. [Bug #9036] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47545 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 +++++++++ io.c | 12 ++++++++---- version.h | 6 +++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index d4003d5243..7b719d64ed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Fri Sep 12 11:15:04 2014 Nobuyoshi Nakada + + * io.c (rb_io_reopen): create a new, temporary FD via rb_sysopen and + call rb_cloexec_dup2 on it to atomically replace the file fptr->fd + points to. This leaves no possible window where fptr->fd is invalid + to userspace (even for any threads running w/o GVL). based on the + patch by Eric Wong at [ruby-core:57943]. + [Bug #9036] + Wed Sep 10 12:34:34 2014 Nobuyoshi Nakada * io.c (io_close): ignore only "closed stream" IOError and diff --git a/io.c b/io.c index b76521d985..4757331f17 100644 --- a/io.c +++ b/io.c @@ -6628,10 +6628,14 @@ rb_io_reopen(int argc, VALUE *argv, VALUE file) } } else { - if (close(fptr->fd) < 0) - rb_sys_fail_path(fptr->pathv); - fptr->fd = -1; - fptr->fd = rb_sysopen(fptr->pathv, oflags, 0666); + int tmpfd = rb_sysopen(fptr->pathv, oflags, 0666); + int err = 0; + if (rb_cloexec_dup2(tmpfd, fptr->fd) < 0) + err = errno; + (void)close(tmpfd); + if (err) { + rb_sys_fail_path(fptr->pathv); + } } return file; diff --git a/version.h b/version.h index 2996b5439d..96bc203cbb 100644 --- a/version.h +++ b/version.h @@ -1,10 +1,10 @@ #define RUBY_VERSION "2.0.0" -#define RUBY_RELEASE_DATE "2014-09-10" -#define RUBY_PATCHLEVEL 566 +#define RUBY_RELEASE_DATE "2014-09-12" +#define RUBY_PATCHLEVEL 567 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 9 -#define RUBY_RELEASE_DAY 10 +#define RUBY_RELEASE_DAY 12 #include "ruby/version.h"