From 1f6a0db1889d2e6a703046749fe38b1b721ca299 Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 12 Jul 2023 13:52:49 +0200 Subject: [PATCH] su: Handle more signals gracefully --- apps/su.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/su.cpp b/apps/su.cpp index a0c95f6c..cd965894 100644 --- a/apps/su.cpp +++ b/apps/su.cpp @@ -14,10 +14,10 @@ void restore_terminal() ioctl(fileno(stdin), TCSETS, &orig); } -void sigint_handler(int) +void signal_handler(int signo) { restore_terminal(); - raise(SIGINT); + raise(signo); } char* getpass() @@ -41,10 +41,12 @@ char* getpass() } struct sigaction sa; - sa.sa_handler = sigint_handler; + sa.sa_handler = signal_handler; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESETHAND; sigaction(SIGINT, &sa, NULL); + sigaction(SIGTERM, &sa, NULL); + sigaction(SIGQUIT, &sa, NULL); atexit(restore_terminal);