This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexec.c
93 lines (85 loc) · 2.36 KB
/
exec.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exec.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ebouvier <ebouvier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/14 11:37:55 by mhoyer #+# #+# */
/* Updated: 2023/09/04 15:07:23 by ebouvier ### ########.fr */
/* */
/* ************************************************************************** */
#include "exec.h"
#include "minishell.h"
#include <stdio.h>
void wait_all(t_minishell *minishell)
{
t_list *parc;
parc = minishell->pids;
while (parc)
{
waitpid(parc->n, &minishell->last_status, 0);
parc = parc->next;
}
if (WIFEXITED(minishell->last_status))
minishell->last_status = WEXITSTATUS(minishell->last_status);
else if (WIFSIGNALED(minishell->last_status))
{
if (minishell->last_status == SIGTERM)
ft_dprintf(2, "Terminated\n");
minishell->last_status += 128;
}
}
int init_exec(t_node *node, int pipefd[2][2])
{
init_pipes(pipefd);
if (!node)
return (0);
return (1);
}
int exec(t_node *node, t_minishell *minishell)
{
int pipefd[2][2];
if (init_exec(node, pipefd) == 0)
return (0);
if (node->type == PIPE)
{
if (exec_pipe(node, minishell, pipefd))
return (1);
}
else if (node->type == OR)
{
if (exec_or(node, minishell))
return (1);
}
else if (node->type == AND)
{
if (exec_and(node, minishell))
return (1);
}
else if (node->type == COMMAND)
{
if (exec_cmd(node, minishell))
return (1);
}
return (0);
}
void clear_exec(t_minishell *minishell)
{
g_sigint = 0;
set_signals();
dup2(minishell->m_fd[1], 1);
dup2(minishell->m_fd[0], 0);
close_minishell_dup(minishell);
ft_lstclear(&minishell->pids, nothing);
unlink(FILE_HEREDOC);
}
int prep_exec(t_minishell *minishell)
{
dup_minishell(minishell);
signal(SIGINT, sig_handler_job);
signal(SIGQUIT, sig_handler_job);
exec(minishell->root, minishell);
clear_exec(minishell);
return (0);
}