summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-19 04:40:22 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-19 04:40:22 +0000
commit4ea96ece8400f1c6caa8a2429f6d93f15434238f (patch)
tree577fa0eb2d207dca593a9a0e8316dde7fa15ecfb
parentb945ad289f14c1b1ba65bdd9a4e1106f3cee134c (diff)
* internal.h: added a declaration of ruby_kill().
* thread.c (ruby_kill): helper function of kill(). * signal.c (rb_f_kill): use ruby_kill() instead of kill(). * signal.c (rb_f_kill): call rb_thread_execute_interrupts() to ensure that make SignalException if sent a signal to myself. [Bug #7951] [ruby-core:52864] * vm_core.h (typedef struct rb_thread_struct): added th->interrupt_cond. * thread.c (rb_threadptr_interrupt_common): added to initialization of th->interrupt_cond. * thread.c (thread_create_core): ditto. * test/ruby/test_signal.rb (TestSignal#test_hup_me): test for the above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39819 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog19
-rw-r--r--internal.h1
-rw-r--r--signal.c6
-rw-r--r--test/ruby/test_signal.rb7
-rw-r--r--thread.c23
-rw-r--r--vm_core.h1
6 files changed, 55 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index e1cce6861f..8f54d29bb0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+Sat Mar 16 01:44:29 2013 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
+
+ * internal.h: added a declaration of ruby_kill().
+ * thread.c (ruby_kill): helper function of kill().
+
+ * signal.c (rb_f_kill): use ruby_kill() instead of kill().
+ * signal.c (rb_f_kill): call rb_thread_execute_interrupts()
+ to ensure that make SignalException if sent a signal
+ to myself. [Bug #7951] [ruby-core:52864]
+
+ * vm_core.h (typedef struct rb_thread_struct): added
+ th->interrupt_cond.
+ * thread.c (rb_threadptr_interrupt_common): added to
+ initialization of th->interrupt_cond.
+ * thread.c (thread_create_core): ditto.
+
+ * test/ruby/test_signal.rb (TestSignal#test_hup_me): test for
+ the above.
+
Sat Mar 16 00:42:39 2013 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* io.c (linux_iocparm_len): enable only exist _IOC_SIZE().
diff --git a/internal.h b/internal.h
index b099f24352..65ce5203ef 100644
--- a/internal.h
+++ b/internal.h
@@ -308,6 +308,7 @@ VALUE rb_thread_shield_destroy(VALUE self);
void rb_mutex_allow_trap(VALUE self, int val);
VALUE rb_uninterruptible(VALUE (*b_proc)(ANYARGS), VALUE data);
VALUE rb_mutex_owned_p(VALUE self);
+void ruby_kill(pid_t pid, int sig);
/* thread_pthread.c, thread_win32.c */
void Init_native_thread(void);
diff --git a/signal.c b/signal.c
index 7ea63677f8..c29a3fbc42 100644
--- a/signal.c
+++ b/signal.c
@@ -18,6 +18,7 @@
#include <errno.h>
#include "ruby_atomic.h"
#include "eval_intern.h"
+#include "internal.h"
#if defined(__native_client__) && defined(NACL_NEWLIB)
# include "nacl/signal.h"
@@ -421,10 +422,11 @@ rb_f_kill(int argc, VALUE *argv)
}
else {
for (i=1; i<argc; i++) {
- if (kill(NUM2PIDT(argv[i]), sig) < 0)
- rb_sys_fail(0);
+ ruby_kill(NUM2PIDT(argv[i]), sig);
}
}
+ rb_thread_execute_interrupts(rb_thread_current());
+
return INT2FIX(i-1);
}
diff --git a/test/ruby/test_signal.rb b/test/ruby/test_signal.rb
index 1de522ee2e..bfc94e8dcb 100644
--- a/test/ruby/test_signal.rb
+++ b/test/ruby/test_signal.rb
@@ -273,4 +273,11 @@ EOS
sleep 0.1
INPUT
end
+
+ def test_hup_me
+ # [Bug #7951] [ruby-core:52864]
+ assert_raise(SignalException) {
+ Process.kill('HUP',Process.pid)
+ }
+ end
end
diff --git a/thread.c b/thread.c
index 955c5f9e5f..7e38ce40b9 100644
--- a/thread.c
+++ b/thread.c
@@ -337,6 +337,7 @@ rb_threadptr_interrupt_common(rb_thread_t *th, int trap)
else {
/* none */
}
+ native_cond_signal(&th->interrupt_cond);
native_mutex_unlock(&th->interrupt_lock);
}
@@ -624,6 +625,7 @@ thread_create_core(VALUE thval, VALUE args, VALUE (*fn)(ANYARGS))
th->interrupt_mask = 0;
native_mutex_initialize(&th->interrupt_lock);
+ native_cond_initialize(&th->interrupt_cond, RB_CONDATTR_CLOCK_MONOTONIC);
/* kick thread */
err = native_thread_create(th);
@@ -5055,6 +5057,8 @@ Init_Thread(void)
gvl_acquire(th->vm, th);
native_mutex_initialize(&th->vm->thread_destruct_lock);
native_mutex_initialize(&th->interrupt_lock);
+ native_cond_initialize(&th->interrupt_cond,
+ RB_CONDATTR_CLOCK_MONOTONIC);
th->pending_interrupt_queue = rb_ary_tmp_new(0);
th->pending_interrupt_queue_checked = 0;
@@ -5198,3 +5202,22 @@ rb_uninterruptible(VALUE (*b_proc)(ANYARGS), VALUE data)
return rb_ensure(b_proc, data, rb_ary_pop, cur_th->pending_interrupt_mask_stack);
}
+
+void
+ruby_kill(pid_t pid, int sig)
+{
+ int err;
+ rb_thread_t *th = GET_THREAD();
+ rb_vm_t *vm = GET_VM();
+
+ if ((th == vm->main_thread) && (pid == getpid())) {
+ native_mutex_lock(&th->interrupt_lock);
+ err = kill(pid, sig);
+ native_cond_wait(&th->interrupt_cond, &th->interrupt_lock);
+ native_mutex_unlock(&th->interrupt_lock);
+ } else {
+ err = kill(pid, sig);
+ }
+ if (err < 0)
+ rb_sys_fail(0);
+}
diff --git a/vm_core.h b/vm_core.h
index 286831feba..5cce489e21 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -551,6 +551,7 @@ typedef struct rb_thread_struct {
rb_atomic_t interrupt_flag;
unsigned long interrupt_mask;
rb_thread_lock_t interrupt_lock;
+ rb_thread_cond_t interrupt_cond;
struct rb_unblock_callback unblock;
VALUE locking_mutex;
struct rb_mutex_struct *keeping_mutexes;