-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignal_handler.c
82 lines (69 loc) · 2.34 KB
/
signal_handler.c
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "header.h"
// Signal handler function for stopping input. Empty, used as a handler
void signalStopInput(int signo)
{
}
// Function to set the shell in a mode where it can read input
void signalReadingMode()
{
// Setup to handle CTRL-C for exiting input process
struct sigaction action={0};
action.sa_handler = signalStopInput;
sigfillset(&action.sa_mask);
action.sa_flags = 0;
sigaction(SIGINT, &action, NULL);
// Setup to handle CTRL-Z for exiting input process
struct sigaction action2={0};
action2.sa_handler = signalStopInput;
sigfillset(&action2.sa_mask);
action2.sa_flags = 0;
sigaction(SIGTSTP, &action2, NULL);
}
// Function to set the shell in ignore mode for specific signals
void signalIgnoreMode(){
// Setup to ignore CTRL-C in the shell
struct sigaction action={0};
action.sa_handler = SIG_IGN;
sigfillset(&action.sa_mask);
action.sa_flags = SA_RESTART;
sigaction(SIGINT, &action, NULL);
// Setup to ignore CTRL-Z in the shell
struct sigaction action2={0};
action2.sa_handler = SIG_IGN;
sigfillset(&action2.sa_mask);
action2.sa_flags = SA_RESTART;
sigaction(SIGTSTP, &action2, NULL);
}
// Function to reset default signal handling
void signalDefaultMode(){
// Reset to default handling for CTRL-C
struct sigaction action={0};
action.sa_handler = SIG_DFL;
sigfillset(&action.sa_mask);
action.sa_flags = SA_RESTART;
sigaction(SIGINT, &action, NULL);
// Reset to default handling for CTRL-Z
struct sigaction action2={0};
action2.sa_handler = SIG_DFL;
sigfillset(&action2.sa_mask);
action2.sa_flags = SA_RESTART;
sigaction(SIGTSTP, &action2, NULL);
}
// Signal handler function for passing signals to child processes. Empty, used as a handler
void passToChild(int signo){
}
// Function to set the shell in a mode to wait for foreground processes
void signalFgWaitMode(){
// Setup to pass CTRL-C to child processes
struct sigaction action={0};
action.sa_handler = passToChild;
sigfillset(&action.sa_mask);
action.sa_flags = SA_RESTART;
sigaction(SIGINT, &action, NULL);
// Setup to pass CTRL-Z to child processes
struct sigaction action2={0};
action2.sa_handler = passToChild;
sigfillset(&action2.sa_mask);
action2.sa_flags = SA_RESTART;
sigaction(SIGTSTP, &action2, NULL);
}