[前][次][番号順一覧][スレッド一覧]

ruby-changes:34113

From: normal <ko1@a...>
Date: Wed, 28 May 2014 09:53:27 +0900 (JST)
Subject: [ruby-changes:34113] normal:r46194 (trunk): signal: remove window for SignalException on IGNORE

normal	2014-05-28 09:53:11 +0900 (Wed, 28 May 2014)

  New Revision: 46194

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=46194

  Log:
    signal: remove window for SignalException on IGNORE
    
    * signal.c (signal_exec): ignore immediate cmd for SIG_IGN
    * signal.c (trap_handler): set cmd to true for SIG_IGN
    * signal.c (trap): handle nil and true values for oldcmd
      [Bug #9835]

  Modified files:
    trunk/ChangeLog
    trunk/signal.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46193)
+++ ChangeLog	(revision 46194)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed May 28 09:30:51 2014  Eric Wong  <e@8...>
+
+	* signal.c (signal_exec): ignore immediate cmd for SIG_IGN
+	* signal.c (trap_handler): set cmd to true for SIG_IGN
+	* signal.c (trap): handle nil and true values for oldcmd
+	  [Bug #9835]
+
 Wed May 28 01:02:54 2014  Tanaka Akira  <akr@f...>
 
 	* lib/tempfile.rb (Tempfile#inspect): Show "(closed)" if the tempfile
Index: signal.c
===================================================================
--- signal.c	(revision 46193)
+++ signal.c	(revision 46194)
@@ -826,6 +826,15 @@ signal_exec(VALUE cmd, int safe, int sig https://github.com/ruby/ruby/blob/trunk/signal.c#L826
     volatile unsigned long old_interrupt_mask = cur_th->interrupt_mask;
     int state;
 
+    /*
+     * workaround the following race:
+     * 1. signal_enque queues signal for execution
+     * 2. user calls trap(sig, "IGNORE"), setting SIG_IGN
+     * 3. rb_signal_exec runs on queued signal
+     */
+    if (IMMEDIATE_P(cmd))
+	return;
+
     cur_th->interrupt_mask |= TRAP_INTERRUPT_MASK;
     TH_PUSH_TAG(cur_th);
     if ((state = EXEC_TAG()) == 0) {
@@ -977,7 +986,7 @@ trap_handler(VALUE *cmd, int sig) https://github.com/ruby/ruby/blob/trunk/signal.c#L986
 		if (strncmp(RSTRING_PTR(command), "SIG_IGN", 7) == 0) {
 sig_ign:
                     func = SIG_IGN;
-                    *cmd = 0;
+                    *cmd = Qtrue;
 		}
 		else if (strncmp(RSTRING_PTR(command), "SIG_DFL", 7) == 0) {
 sig_dfl:
@@ -1058,11 +1067,14 @@ trap(int sig, sighandler_t func, VALUE c https://github.com/ruby/ruby/blob/trunk/signal.c#L1067
     oldcmd = vm->trap_list[sig].cmd;
     switch (oldcmd) {
       case 0:
+      case Qtrue:
 	if (oldfunc == SIG_IGN) oldcmd = rb_str_new2("IGNORE");
         else if (oldfunc == SIG_DFL) oldcmd = rb_str_new2("SYSTEM_DEFAULT");
 	else if (oldfunc == sighandler) oldcmd = rb_str_new2("DEFAULT");
 	else oldcmd = Qnil;
 	break;
+      case Qnil:
+	break;
       case Qundef:
 	oldcmd = rb_str_new2("EXIT");
 	break;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]