-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignals_0.c
57 lines (50 loc) · 1.86 KB
/
signals_0.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* signals.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ngasco <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/07 11:13:57 by ngasco #+# #+# */
/* Updated: 2022/04/07 11:13:59 by ngasco ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
/* Handle for case when simulation is inside main process */
void ft_handle_signals(int sig)
{
if (sig == SIGINT)
{
printf("\n");
rl_on_new_line();
rl_replace_line("", 0);
rl_redisplay();
return ;
}
}
/* Case when simulation is inside main process */
void ft_shortcut_events(void)
{
struct sigaction sa;
memset(&sa, 0, sizeof(struct sigaction));
ft_ignore_signal(sa, SIGQUIT);
sa.sa_handler = &ft_handle_signals;
sigaction(SIGINT, &sa, NULL);
}
/* Handle for case when simulation is inside child process */
void ft_handle_signals_interactive(int sig)
{
if (sig == SIGINT)
printf("\n");
else if (sig == SIGQUIT)
printf("\n");
}
/* Case when simulation is inside child process) */
void ft_shortcut_events_interactive(void)
{
struct sigaction sa_interactive;
memset(&sa_interactive, 0, sizeof(struct sigaction));
sa_interactive.sa_handler = &ft_handle_signals_interactive;
sigaction(SIGQUIT, &sa_interactive, NULL);
sigaction(SIGINT, &sa_interactive, NULL);
}