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

ruby-changes:43493

From: normal <ko1@a...>
Date: Sun, 3 Jul 2016 06:13:33 +0900 (JST)
Subject: [ruby-changes:43493] normal:r55566 (trunk): process.c (disable_child_handler_fork_child): simplify

normal	2016-07-03 06:13:26 +0900 (Sun, 03 Jul 2016)

  New Revision: 55566

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55566

  Log:
    process.c (disable_child_handler_fork_child): simplify
    
    signal(2) is portable for SIG_DFL and SIG_IGN, so we do not
    need the extra code for sigaction(2).
    
    Also, execve will reset all signal handlers to default
    anyways, so there is little sense in preserving old
    signal handler besides SIG_IGN.
    
    Hopefully this makes the code easier-to-understand and
    maintain.
    
    * process.c (disable_child_handler_fork_child): simplify
      [ruby-core:75781] [Misc #12439]

  Modified files:
    trunk/ChangeLog
    trunk/process.c
Index: process.c
===================================================================
--- process.c	(revision 55565)
+++ process.c	(revision 55566)
@@ -3497,44 +3497,10 @@ disable_child_handler_fork_child(struct https://github.com/ruby/ruby/blob/trunk/process.c#L3497
 {
     int sig;
     int ret;
-#ifdef POSIX_SIGNAL
-    struct sigaction act, oact;
-
-    act.sa_handler = SIG_DFL;
-    act.sa_flags = 0;
-    ret = sigemptyset(&act.sa_mask); /* async-signal-safe */
-    if (ret == -1) {
-        ERRMSG("sigemptyset");
-        return -1;
-    }
-#else
-    sig_t handler;
-#endif
 
     for (sig = 1; sig < NSIG; sig++) {
-        int reset = 0;
-#ifdef SIGPIPE
-        if (sig == SIGPIPE) {
-            reset = 1;
-#ifndef POSIX_SIGNAL
-            handler = SIG_DFL;
-#endif
-	}
-#endif
-        if (!reset) {
-#ifdef POSIX_SIGNAL
-            ret = sigaction(sig, NULL, &oact); /* async-signal-safe */
-            if (ret == -1 && errno == EINVAL) {
-                continue; /* Ignore invalid signal number. */
-            }
-            if (ret == -1) {
-                ERRMSG("sigaction to obtain old action");
-                return -1;
-            }
-            reset = (oact.sa_flags & SA_SIGINFO) ||
-                    (oact.sa_handler != SIG_IGN && oact.sa_handler != SIG_DFL);
-#else
-            handler = signal(sig, SIG_DFL);
+            sig_t handler = signal(sig, SIG_DFL);
+
             if (handler == SIG_ERR && errno == EINVAL) {
                 continue; /* Ignore invalid signal number */
             }
@@ -3542,24 +3508,15 @@ disable_child_handler_fork_child(struct https://github.com/ruby/ruby/blob/trunk/process.c#L3508
                 ERRMSG("signal to obtain old action");
                 return -1;
             }
-            reset = (handler != SIG_IGN && handler != SIG_DFL);
-#endif
-        }
-        if (reset) {
-#ifdef POSIX_SIGNAL
-            ret = sigaction(sig, &act, NULL); /* async-signal-safe */
-            if (ret == -1) {
-                ERRMSG("sigaction to set default action");
-                return -1;
+#ifdef SIGPIPE
+            if (sig == SIGPIPE) {
+                continue;
             }
-#else
-           handler = signal(sig, handler);
-           if (handler == SIG_ERR) {
-                ERRMSG("signal to set default action");
-                return -1;
-           }
 #endif
-        }
+            /* it will be reset to SIG_DFL at execve time, instead */
+            if (handler == SIG_IGN) {
+                signal(sig, SIG_IGN);
+            }
     }
 
     ret = sigprocmask(SIG_SETMASK, &old->sigmask, NULL); /* async-signal-safe */
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55565)
+++ ChangeLog	(revision 55566)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jul  3 06:04:09 2016  Eric Wong  <e@8...>
+
+	* process.c (disable_child_handler_fork_child): simplify
+	  [ruby-core:75781] [Misc #12439]
+
 Sun Jul  3 05:25:46 2016  Eric Wong  <e@8...>
 
 	* tool/asm_parse.rb: add description

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

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