su: Handle more signals gracefully
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-07-12 13:52:49 +02:00
parent 81e1fdf81e
commit 1f6a0db188
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -14,10 +14,10 @@ void restore_terminal()
ioctl(fileno(stdin), TCSETS, &orig); ioctl(fileno(stdin), TCSETS, &orig);
} }
void sigint_handler(int) void signal_handler(int signo)
{ {
restore_terminal(); restore_terminal();
raise(SIGINT); raise(signo);
} }
char* getpass() char* getpass()
@ -41,10 +41,12 @@ char* getpass()
} }
struct sigaction sa; struct sigaction sa;
sa.sa_handler = sigint_handler; sa.sa_handler = signal_handler;
sigemptyset(&sa.sa_mask); sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESETHAND; sa.sa_flags = SA_RESETHAND;
sigaction(SIGINT, &sa, NULL); sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGQUIT, &sa, NULL);
atexit(restore_terminal); atexit(restore_terminal);