# HG changeset patch # User Matt Johnston # Date 1392470037 -28800 # Node ID 860e3522f8fc1308cc41f563aa6eaae2a53e4104 # Parent ae766a2c8fa739ae23032acd56aea00882a41118 - Save errno in signal handlers - Use _exit() in segv handler diff -r ae766a2c8fa7 -r 860e3522f8fc svr-chansession.c --- a/svr-chansession.c Fri Feb 14 23:18:45 2014 +0800 +++ b/svr-chansession.c Sat Feb 15 21:13:57 2014 +0800 @@ -87,6 +87,8 @@ struct sigaction sa_chld; struct exitinfo *exit = NULL; + const int saved_errno = errno; + TRACE(("enter sigchld handler")) while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { TRACE(("sigchld handler: pid %d", pid)) @@ -140,6 +142,8 @@ sigemptyset(&sa_chld.sa_mask); sigaction(SIGCHLD, &sa_chld, NULL); TRACE(("leave sigchld handler")) + + errno = saved_errno; } /* send the exit status or the signal causing termination for a session */ diff -r ae766a2c8fa7 -r 860e3522f8fc svr-main.c --- a/svr-main.c Fri Feb 14 23:18:45 2014 +0800 +++ b/svr-main.c Sat Feb 15 21:13:57 2014 +0800 @@ -337,6 +337,8 @@ static void sigchld_handler(int UNUSED(unused)) { struct sigaction sa_chld; + const int saved_errno = errno; + while(waitpid(-1, NULL, WNOHANG) > 0); sa_chld.sa_handler = sigchld_handler; @@ -344,13 +346,14 @@ if (sigaction(SIGCHLD, &sa_chld, NULL) < 0) { dropbear_exit("signal() error"); } + errno = saved_errno; } /* catch any segvs */ static void sigsegv_handler(int UNUSED(unused)) { fprintf(stderr, "Aiee, segfault! You should probably report " "this as a bug to the developer\n"); - exit(EXIT_FAILURE); + _exit(EXIT_FAILURE); } /* catch ctrl-c or sigterm */