From c9c3b2f4357e30dd078075b3259d86adca6958e3 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 1 Sep 2026 06:21:08 +0000 Subject: 1 --- src/handler.cc | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/handler.cc') diff --git a/src/handler.cc b/src/handler.cc index afc1fc1..5356d47 100644 --- a/src/handler.cc +++ b/src/handler.cc @@ -6,12 +6,33 @@ namespace ov4 extern char **environ; sigset_t BLOCK_HANDLER; -void init() +void signal_init() { sigemptyset(&BLOCK_HANDLER); sigaddset(&BLOCK_HANDLER, SIGINT); sigaddset(&BLOCK_HANDLER, SIGTSTP); sigaddset(&BLOCK_HANDLER, SIGCHLD); + + Signal(SIGINT, sigint_handler); /* ctrl-c */ + Signal(SIGTSTP, sigtstp_handler); /* ctrl-z */ + Signal(SIGCHLD, sigchld_handler); /* Terminated or stopped child */ +} + +/* + * Signal - wrapper for the sigaction function + */ + +handler_t *Signal(int signum, handler_t *handler) +{ + struct sigaction action, old_action; + + action.sa_handler = handler; + sigemptyset(&action.sa_mask); /* block sigs of type being handled */ + action.sa_flags = SA_RESTART; /* restart syscalls if possible */ + + if (sigaction(signum, &action, &old_action) < 0) + unix_error("Signal error"); + return (old_action.sa_handler); } /* -- cgit v1.3.1-4-g156e