aboutsummaryrefslogtreecommitdiff
path: root/src/signal/misc.cc
blob: e8b780efcab9c25b000946308866ea52d4b67b30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

#include "signal_handler.h"

#include <errno.h>

namespace ov4
{

void signal_init()
{
    /* Install the signal handlers */
    
    sigemptyset(&block_job);
    sigemptyset(&block_sig_TTOU);
    sigemptyset(&block_io);

    sigaddset(&block_job, SIGINT);
    sigaddset(&block_job, SIGTSTP);
    sigaddset(&block_job, SIGCHLD);
    
    sigaddset(&block_sig_TTOU, SIGTTOU);

    sigaddset(&block_io, SIGTTOU);
    sigaddset(&block_io, SIGTTIN);

    Signal(SIGINT,  sigint_handler);   /* ctrl-c */
    Signal(SIGTSTP, sigtstp_handler);  /* ctrl-z */
    Signal(SIGCHLD, sigchld_handler);  /* Terminated or stopped child */

    /* This one provides a clean way to kill the shell */
    Signal(SIGQUIT, sigquit_handler); 
}

/*
 * Signal - wrapper for the sigaction function
 */
handler_t *Signal([[maybe_unused]] 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);
}

int block_all(sigset_t *prev)
{
    sigset_t set;
    sigfillset(&set);
    return sigprocmask(SIG_SETMASK, &set, prev);
}

int block_handler(sigset_t *prev)
{
    return sigprocmask(SIG_BLOCK, &block_job, prev);
}

}