-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathms_sig_hook.c
56 lines (50 loc) · 1.53 KB
/
ms_sig_hook.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ms_sig_hook.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: flormich <flormich@student.42wolfsburg.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/27 11:48:42 by pnuti #+# #+# */
/* Updated: 2021/12/20 11:50:30 by flormich ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell_libs.h"
void sigint_handle(int signum)
{
static int check;
if (signum == SIGUSR1)
{
if (!check)
check = 1;
else
check = 0;
}
if (signum == SIGINT)
{
g_exit_value = 130;
printf("\n");
rl_replace_line("", 0);
rl_on_new_line();
if (!check)
rl_redisplay();
}
}
void sig_handle(int signum)
{
if (signum == SIGINT)
sigint_handle(signum);
else if (signum == SIGQUIT)
printf("\b\b \b\b");
}
int ms_sig_hook(void)
{
struct sigaction sa;
sa.sa_handler = &sig_handle;
sa.sa_flags = SA_RESTART;
if (sigaction(SIGINT, &sa, NULL) == -1)
return (-1);
if (sigaction(SIGQUIT, &sa, NULL) == -1)
return (-2);
return (0);
}