]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
gui: Kill process group *before* shutting down curses.
authorAndre Noll <maan@tuebingen.mpg.de>
Sat, 5 Mar 2016 21:10:32 +0000 (22:10 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Thu, 17 Mar 2016 16:21:53 +0000 (17:21 +0100)
Currently we perform shutdown on exit the other way round. Hence the
running external command may interfere with the shutdown of the curses
system. This patch changes die() to first signal the child processes,
then wait for them to terminate. This avoids the race.

gui.c

diff --git a/gui.c b/gui.c
index e85edba929780c440aa36915347bbb7fbca74911..83337f86a9dc8b814d77afca9db63bc40da49897 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -518,6 +518,14 @@ __noreturn __printf_2_3 static void die(int exit_code, const char* fmt, ...)
 {
        va_list argp;
 
+       /* Kill every process in our process group. */
+       para_sigaction(SIGTERM, SIG_IGN);
+       kill(0, SIGTERM);
+       /* Wait up to two seconds for child processes to die. */
+       alarm(2);
+       while (waitpid(0, NULL, 0) >= 0)
+               ; /* nothing */
+       alarm(0);
        /* mousemask() exists only in ncurses */
 #ifdef NCURSES_MOUSE_VERSION
        mousemask(~(mmask_t)0, NULL); /* Avoid bad terminal state with xterm. */
@@ -526,9 +534,6 @@ __noreturn __printf_2_3 static void die(int exit_code, const char* fmt, ...)
        va_start(argp, fmt);
        vfprintf(stderr, fmt, argp);
        va_end(argp);
-       /* kill every process in the process group and exit */
-       para_sigaction(SIGTERM, SIG_IGN);
-       kill(0, SIGTERM);
        exit(exit_code);
 }