From c109164a9f68935098a4915e7237828cafdef5f7 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 6 Oct 2026 11:28:06 +0000 Subject: fix non-signal-safe exit, and refactor signal handlers --- src/signal/sigtstp_handler.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/signal/sigtstp_handler.cc (limited to 'src/signal/sigtstp_handler.cc') diff --git a/src/signal/sigtstp_handler.cc b/src/signal/sigtstp_handler.cc new file mode 100644 index 0000000..7b32d31 --- /dev/null +++ b/src/signal/sigtstp_handler.cc @@ -0,0 +1,32 @@ +#include "signal_handler.h" + +#include + +namespace ov4 +{ + +/* + * sigtstp_handler - The kernel sends a SIGTSTP to the shell whenever + * the user types ctrl-z at the keyboard. Catch it and suspend the + * foreground job by sending it a SIGTSTP. + */ +void sigtstp_handler([[maybe_unused]] int sig) +{ + int errno_backup = errno; + + sigset_t prev; + block_handler(&prev); + + int pid = fgpid(); + if (pid != 0) + { + kill(-pid, SIGTSTP); + } + + sigprocmask(SIG_SETMASK, &prev, nullptr); + + errno = errno_backup; + return; +} + +} \ No newline at end of file -- cgit v1.3.1-4-g156e