-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_sigaction.c
70 lines (61 loc) · 1.96 KB
/
ft_sigaction.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sigaction.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ralopez- <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/10 13:46:35 by ralopez- #+# #+# */
/* Updated: 2023/03/10 13:46:35 by ralopez- ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ignore_sigquit(void)
{
struct sigaction act;
ft_memset(&act, 0, sizeof(act));
act.sa_handler = SIG_IGN;
sigaction(SIGQUIT, &act, NULL);
}
void signal_reset_prompt(int signal)
{
if (signal == SIGINT)
{
(void)signal;
g_info.last_code = 130;
printf("\n");
rl_on_new_line();
rl_replace_line("", 0);
rl_redisplay();
}
else if (signal == SIGQUIT)
SIG_IGN ;
}
void signal_print_newline(int signal)
{
(void)signal;
rl_on_new_line();
}
void set_signals_interactive(void)
{
struct sigaction act;
ignore_sigquit();
ft_memset(&act, 0, sizeof(act));
act.sa_handler = &signal_reset_prompt;
sigaction(SIGINT, &act, NULL);
}
/**
* set_signals_noninteractive:
* This function is called to make sure that the shell will ignore
* SIGINT and SIGQUIT signals. This is done to prevent the shell from
* exiting when the user presses Ctrl-C, Ctrl-\ or Ctrl-D.
*
*/
void set_signals_noninteractive(void)
{
struct sigaction act;
ft_memset(&act, 0, sizeof(act));
act.sa_handler = &signal_print_newline;
sigaction(SIGINT, &act, NULL);
sigaction(SIGQUIT, &act, NULL);
}