]> Sergey Matveev's repositories - nnn.git/commitdiff
Cleanly handle SIGTERM and SIGHUP
authorLéo Villeveygoux <l@vgx.fr>
Fri, 29 May 2020 16:40:45 +0000 (18:40 +0200)
committerLéo Villeveygoux <l@vgx.fr>
Fri, 29 May 2020 20:48:36 +0000 (22:48 +0200)
src/nnn.c

index de80d46c9e131a26e3f466b14d7b9ebf17a0caac..ce65eba89bac8859bdad0dd20d7fafb91b6b1521 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -704,6 +704,13 @@ static void sigint_handler(int UNUSED(sig))
        g_states |= STATE_INTERRUPTED;
 }
 
+static void clean_exit_sighandler(int UNUSED(sig))
+{
+       exitcurses();
+       /* This triggers cleanup() thanks to atexit() */
+       exit(EXIT_SUCCESS);
+}
+
 static char *xitoa(uint val)
 {
        static char ascbuf[32] = {0};
@@ -7230,6 +7237,8 @@ int main(int argc, char *argv[])
                xerror();
                return EXIT_FAILURE;
        }
+       signal(SIGTERM, clean_exit_sighandler);
+       signal(SIGHUP, clean_exit_sighandler);
        signal(SIGQUIT, SIG_IGN);
 
 #ifndef NOLOCALE