-
Notifications
You must be signed in to change notification settings - Fork 0
/
signal.c
67 lines (61 loc) · 1.75 KB
/
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* signal.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zhabri <zhabri@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/23 10:32:29 by zhabri #+# #+# */
/* Updated: 2023/01/12 14:12:54 by zhabri ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static void handler(int sig)
{
if (sig == SIGINT)
handle_sigint();
else if (sig == SIGQUIT)
handle_sigquit();
}
void ignore_sig(int sig)
{
(void)sig;
}
void init_sig_callbacks(int process)
{
if (process == 0)
{
signal(SIGINT, handler);
signal(SIGQUIT, handler);
}
else
{
signal(SIGINT, ignore_sig);
signal(SIGQUIT, ignore_sig);
}
}
void change_sig_handling(char *cmd, int *pipes, int *children_pid)
{
char **cmd_split;
char *sum;
sum = NULL;
if (cmd)
{
if (cmd[0])
{
cmd_split = ft_split_sep(cmd, " \t");
cmd_split[0] = get_path(cmd_split[0], true);
if (cmd_split[0] != NULL)
{
get_sum(cmd_split, &sum, pipes, children_pid);
if (ft_strncmp(sum, g_glob->minishell_sum, 41) == 0)
init_sig_callbacks(42);
free(sum);
}
if (cmd_split[0])
free_tab(cmd_split);
else
free_tab_bis(cmd_split);
}
}
}