diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-06 11:28:06 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-06 11:28:06 +0000 |
| commit | c109164a9f68935098a4915e7237828cafdef5f7 (patch) | |
| tree | c96582cc3e9e7ffa752631fd68bd084982503224 /src/signal/sigint_handler.cc | |
| parent | c0dc27b0e94d8aca60fc47c9dee09eb170cb79dd (diff) | |
fix non-signal-safe exit, and refactor signal handlers
Diffstat (limited to 'src/signal/sigint_handler.cc')
| -rw-r--r-- | src/signal/sigint_handler.cc | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/signal/sigint_handler.cc b/src/signal/sigint_handler.cc new file mode 100644 index 0000000..706c041 --- /dev/null +++ b/src/signal/sigint_handler.cc @@ -0,0 +1,37 @@ +#include "signal_handler.h" + +#include <errno.h> +#include <termios.h> +#include <sys/ioctl.h> + +namespace ov4 +{ + +/* + * sigint_handler - The kernel sends a SIGINT to the shell whenver the + * user types ctrl-c at the keyboard. Catch it and send it along + * to the foreground job. + */ +void sigint_handler([[maybe_unused]] int sig) +{ + int errno_backup = errno; + + sigset_t prev; + block_handler(&prev); + + int pid = fgpid(); + if (pid != 0) + { + kill(-pid, SIGINT); + } else { + tcflush(STDIN_FILENO, TCIFLUSH); + ioctl(STDIN_FILENO, TIOCSTI, "\n"); + } + + sigprocmask(SIG_SETMASK, &prev, nullptr); + + errno = errno_backup; + return; +} + +}
\ No newline at end of file |
