-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_signals.c
50 lines (45 loc) · 1.55 KB
/
main_signals.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main_signals.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abelayad <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/17 18:24:00 by abelayad #+# #+# */
/* Updated: 2023/06/18 16:38:39 by abelayad ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static void ft_sigint_handler(int num)
{
(void)num;
if (g_minishell.signint_child)
{
ft_putstr_fd("\n", 1);
g_minishell.signint_child = false;
g_minishell.heredoc_sigint = true;
}
else
{
ft_putstr_fd("\n", 1);
rl_replace_line("", 0);
rl_on_new_line();
rl_redisplay();
}
}
void ft_sigquit_handler(int num)
{
(void)num;
ft_putstr_fd("Quit: 3\n", 1);
}
void ft_init_signals(void)
{
struct termios term;
term = g_minishell.original_term;
term.c_lflag &= ~ECHOCTL;
tcsetattr(STDIN_FILENO, TCSANOW, &term);
g_minishell.heredoc_sigint = false;
g_minishell.signint_child = false;
signal(SIGINT, ft_sigint_handler);
signal(SIGQUIT, SIG_IGN);
}