@@ -735,20 +735,19 @@ static int DeepState_RunTestNoFork(struct DeepState_TestInfo *test) {
735735/* Fork and run `test`. */
736736static enum DeepState_TestRunResult
737737DeepState_ForkAndRunTest (struct DeepState_TestInfo *test) {
738+ pid_t test_pid;
739+ if (FLAGS_fork) {
738740
739- /* If flag is set, install a signal handler for SIGCHLD */
740- /* TODO(alan): use handler as robust "multiplexer" and handle child signal */
741- if (FLAGS_verbose_crash_trace) {
742- struct sigaction sigact, oldact;
741+ /* If flag is set, install a signal handler for SIGCHLD */
742+ if (FLAGS_verbose_crash_trace) {
743+ struct sigaction sigact, oldact;
743744
744- sigact.sa_flags = SA_SIGINFO | SA_NOCLDWAIT;
745- sigact.sa_sigaction = DeepState_EmitBacktrace;
745+ sigact.sa_flags = SA_SIGINFO | SA_NOCLDWAIT;
746+ sigact.sa_sigaction = DeepState_EmitBacktrace;
746747
747- sigaction (SIGCHLD, &sigact, &oldact);
748- }
748+ sigaction (SIGCHLD, &sigact, &oldact);
749+ }
749750
750- pid_t test_pid;
751- if (FLAGS_fork) {
752751 test_pid = fork ();
753752 if (!test_pid) {
754753 DeepState_RunTest (test);
@@ -759,6 +758,19 @@ DeepState_ForkAndRunTest(struct DeepState_TestInfo *test) {
759758 if (FLAGS_fork) {
760759 waitpid (test_pid, &wstatus, 0 );
761760 } else {
761+
762+ /* If flag is set, install a signal handler for any arbitrary crash*/
763+ if (FLAGS_verbose_crash_trace) {
764+
765+ struct sigaction sigact, oldact;
766+
767+ sigact.sa_flags = SA_SIGINFO | SA_NODEFER;
768+ sigact.sa_sigaction = DeepState_EmitBacktrace;
769+
770+ sigaction (SIGBUS, &sigact, &oldact);
771+ sigaction (SIGSEGV, &sigact, &oldact);
772+ }
773+
762774 wstatus = DeepState_RunTestNoFork (test);
763775 DeepState_CleanUp ();
764776 }
0 commit comments