-
Notifications
You must be signed in to change notification settings - Fork 0
/
parent.c
60 lines (56 loc) · 1.8 KB
/
parent.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parent.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ldoppler <ldoppler@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/16 17:38:45 by ldoppler #+# #+# */
/* Updated: 2024/01/29 09:24:56 by ldoppler ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex.h"
void parent_process_bis(int *pipefd, t_execve *info_execve, char **envp,
int fd)
{
close(pipefd[0]);
if (dup2(fd, STDOUT_FILENO) == -1)
{
free_everything(info_execve);
close(fd);
perror("dup2");
exit(EXIT_FAILURE);
}
close(fd);
if (-1 == execve(info_execve->exec_file_bis_path, info_execve->args_bis,
envp))
{
free_everything(info_execve);
perror("execve");
exit(EXIT_FAILURE);
}
}
void parent_process(int *pipefd, t_execve *info_execve, char **envp)
{
int fd;
close(pipefd[1]);
fd = open(info_execve->file2, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd < 0)
{
perror("open");
free_everything(info_execve);
close(fd);
close(info_execve->fd);
close(pipefd[0]);
exit(EXIT_FAILURE);
}
if (dup2(pipefd[0], STDIN_FILENO) == -1)
{
perror("dup2");
free_everything(info_execve);
close(fd);
close(pipefd[0]);
exit(EXIT_FAILURE);
}
parent_process_bis(pipefd, info_execve, envp, fd);
}