]> granicus.if.org Git - strace/commitdiff
Simplify SIGCHLD handler setting
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 15 Mar 2012 16:27:49 +0000 (17:27 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 15 Mar 2012 16:27:49 +0000 (17:27 +0100)
* strace.c (init): Set SIGCHLD to SIG_DFL earlier.
(startup_child): Do not bother restoring SIGCHLD handler.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
strace.c

index dda340465a7b415909edb650086be62b03404f8d..f452254e13ecf65e5ddd869c94cb162680ec5ce1 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -873,21 +873,11 @@ startup_child(char **argv)
                        if (!strace_vforked)
                                kill(pid, SIGSTOP);
                } else {
-                       struct sigaction sv_sigchld;
-                       sigaction(SIGCHLD, NULL, &sv_sigchld);
-                       /*
-                        * Make sure it is not SIG_IGN, otherwise wait
-                        * will not block.
-                        */
-                       signal(SIGCHLD, SIG_DFL);
-                       /*
-                        * Wait for grandchild to attach to us.
-                        * It kills child after that, and wait() unblocks.
-                        */
                        alarm(3);
+                       /* we depend on SIGCHLD set to SIG_DFL by init code */
+                       /* if it happens to be SIG_IGN'ed, wait won't block */
                        wait(NULL);
                        alarm(0);
-                       sigaction(SIGCHLD, &sv_sigchld, NULL);
                }
 
                execv(pathname, argv);
@@ -1235,6 +1225,13 @@ init(int argc, char *argv[])
 
        progname = argv[0] ? argv[0] : "strace";
 
+       /* Make sure SIGCHLD has the default action so that waitpid
+          definitely works without losing track of children.  The user
+          should not have given us a bogus state to inherit, but he might
+          have.  Arguably we should detect SIG_IGN here and pass it on
+          to children, but probably noone really needs that.  */
+       signal(SIGCHLD, SIG_DFL);
+
        strace_tracer_pid = getpid();
 
        os_release = get_os_release();
@@ -1502,14 +1499,6 @@ init(int argc, char *argv[])
                sigaction(SIGPIPE, &sa, NULL);
                sigaction(SIGTERM, &sa, NULL);
        }
-       /* Make sure SIGCHLD has the default action so that waitpid
-          definitely works without losing track of children.  The user
-          should not have given us a bogus state to inherit, but he might
-          have.  Arguably we should detect SIG_IGN here and pass it on
-          to children, but probably noone really needs that.  */
-       sa.sa_handler = SIG_DFL;
-       sigaction(SIGCHLD, &sa, NULL);
-
        if (nprocs != 0 || daemonized_tracer)
                startup_attach();