summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-23 09:50:21 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-23 09:50:21 +0000
commitdedbe778faa8c7a5de321412e30588ff162fb34a (patch)
treec597230848c3e2a48636b4a01b288dbaac4efe37
parent276af3afbed6a555b5d08591de48d17a5f85ca4e (diff)
merge revision(s) 45899: [Backport #9751]
* thread.c (thread_start_func_2): stop if forked in a sub-thread, the thread has become the main thread. [ruby-core:62070] [Bug #9751] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@46518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--test/ruby/test_thread.rb21
-rw-r--r--thread.c3
-rw-r--r--version.h2
4 files changed, 31 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 70dc331f5e..f4dc059b8e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Mon Jun 23 18:50:13 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * thread.c (thread_start_func_2): stop if forked in a sub-thread,
+ the thread has become the main thread.
+ [ruby-core:62070] [Bug #9751]
+
Mon Jun 23 18:35:34 2014 Josh Goebel <dreamer3@gmail.com>
* net/protocol.rb (using_each_crlf_line): fix SMTP dot-stuffing
diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb
index 9ac2c30710..1e730a1452 100644
--- a/test/ruby/test_thread.rb
+++ b/test/ruby/test_thread.rb
@@ -964,4 +964,25 @@ Thread.new(Thread.current) {|mth|
pid, status = Process.waitpid2(pid)
assert_equal(false, status.success?, bug8433)
end if Process.respond_to?(:fork)
+
+ def test_fork_in_thread
+ bug9751 = '[ruby-core:62070] [Bug #9751]'
+ f = nil
+ th = Thread.start do
+ unless f = IO.popen("-")
+ STDERR.reopen(STDOUT)
+ exit
+ end
+ Process.wait2(f.pid)
+ end
+ unless th.join(3)
+ Process.kill(:QUIT, f.pid)
+ Process.kill(:KILL, f.pid) unless th.join(1)
+ end
+ _, status = th.value
+ output = f.read
+ f.close
+ assert_not_predicate(status, :signaled?, FailDesc[status, bug9751, output])
+ assert_predicate(status, :success?, bug9751)
+ end if Process.respond_to?(:fork)
end
diff --git a/thread.c b/thread.c
index 142ed5dbf5..5be0855040 100644
--- a/thread.c
+++ b/thread.c
@@ -552,6 +552,9 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_s
thread_debug("thread end: %p\n", (void *)th);
main_th = th->vm->main_thread;
+ if (main_th == th) {
+ ruby_stop(0);
+ }
if (RB_TYPE_P(errinfo, T_OBJECT)) {
/* treat with normal error object */
rb_threadptr_raise(main_th, 1, &errinfo);
diff --git a/version.h b/version.h
index d654f06ec9..15a9aec128 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.0.0"
#define RUBY_RELEASE_DATE "2014-06-23"
-#define RUBY_PATCHLEVEL 497
+#define RUBY_PATCHLEVEL 498
#define RUBY_RELEASE_YEAR 2014
#define RUBY_RELEASE_MONTH 6