-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpipe.c
73 lines (67 loc) · 2.2 KB
/
pipe.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pipe.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: djames <djames@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/05 12:48:45 by djames #+# #+# */
/* Updated: 2023/07/18 15:37:43 by djames ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int ft_execaux(int i, pid_t *pid, int **fd)
{
int j;
int madona;
j = 0;
madona = -1;
close_pipe(fd, i);
while (j <= i)
{
waitpid(pid[j], &madona, 0);
j++;
}
g_data.flag = WEXITSTATUS(madona);
if (WIFSIGNALED(madona))
{
if (WTERMSIG(madona) == SIGQUIT)
write(STDERR_FILENO, "Quit: 3\n", 8);
else if (WTERMSIG(madona) == SIGSEGV)
write(STDERR_FILENO, "Segmentation fault: 11\n", 23);
g_data.flag = (128 + WTERMSIG(madona));
}
ft_free(fd, pid, i);
return (madona);
}
void command_not_found(char *command)
{
write (2, "MINISHELL: ", 11);
write (2, command, ft_strlen(command));
write (2, ": command not found\n", 20);
exit(127);
}
void ft_exec35(t_command *command, int i, int **fd, int j)
{
int madona;
madona = 258;
disable_rawmode();
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
madona = check_redirect_in(command->redir, command->here_doc);
if (madona < 0)
exit(errno);
if (!madona && j != 0)
dup2(fd[j - 1][0], STDIN_FILENO);
madona = check_redirect_out(command->redir);
if (madona < 0)
exit(errno);
if (!madona && j <= (i - 1))
dup2(fd[j][1], STDOUT_FILENO);
close_pipe(fd, j);
madona = check_built(command->cmd, 1);
if (madona != 1)
exit(madona);
else if (execve(get_path(*command->cmd), command->cmd, g_data.envir) != 0)
command_not_found(*command->cmd);
}