--- debugger.c 2007-04-07 10:17:12.000000000 +0200 +++ debugger.c-childhandler 2007-04-07 10:16:39.000000000 +0200 @@ -26,6 +26,13 @@ #endif } +static int attach_handler_count; + +static void attach_handler (int signo) +{ + attach_handler_count++; +} + /* Debugging only: Number of signal needing redelivery on PTRACE_ATTACH. */ int attach_redelivered; @@ -40,6 +47,17 @@ delay (); + attach_handler_count = 0; + /* Fill SA_SIGACTION _before_ SA_HANDLER as they may be in union! */ + act.sa_sigaction = NULL; + act.sa_handler = attach_handler; + i = sigemptyset (&act.sa_mask); + assert (i == 0); + act.sa_flags = + act.sa_restorer = NULL; + + attach_handler_orig = signal (SIGCHLD, attach_handler); + i = ptrace (PTRACE_ATTACH, pid, NULL, NULL); assert (i == 0); @@ -84,6 +102,22 @@ assert (i == 0); } + attach_handler_orig = signal (SIGCHLD, attach_handler_orig); + assert (attach_handler_orig == attach_handler); + + if (stopped == 1 && attach_handler_count == 2) + stopped = 0; + else if (stopped == 1 && attach_handler_count == 1) + stopped = 1; + else if (stopped == 0 && attach_handler_count == 1) + stopped = 0; + else + { + fprintf (stderr, "stopped = %d, attach_handler_count = %d\n", stopped, + attach_handler_count); + abort (); + } + delay (); return stopped;