-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathms_signal.c
70 lines (65 loc) · 1.66 KB
/
ms_signal.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ms_signal.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sma <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/17 09:34:48 by ybong #+# #+# */
/* Updated: 2021/09/20 19:38:37 by sma ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void sig_set(int i)
{
if (i == 0)
{
signal(SIGINT, &sigint_handler);
signal(SIGQUIT, SIG_IGN);
}
else if (i == 1)
{
signal(SIGINT, child_handler);
signal(SIGQUIT, child_handler);
}
else if (i == 2)
{
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
}
}
void sigint_handler(int signo)
{
if (signo == SIGINT)
{
rl_on_new_line();
rl_redisplay();
printf("%c[K\n", 27);
rl_replace_line("", 1);
rl_on_new_line();
rl_redisplay();
g_status = 130;
}
}
void child_handler(int signo)
{
if (signo == SIGINT)
{
printf("%c[K\n", 27);
g_status = 130;
}
if (signo == SIGQUIT)
{
printf("Quit: 3\n");
g_status = 131;
}
}
void redirect_handler(int signo)
{
if (signo == SIGINT)
{
printf("%c[K\n", 27);
printf("\n");
g_status = 130;
}
}