maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
pipe.h File Reference
#include "shell.h"
#include "tokens.h"
Include dependency graph for pipe.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define WAIT_NEXT_COMMAND   1
 

Functions

int builtin_pipe (t_ast *node, t_ms_data *data)
 execute pipe when | is found in the command
 

Macro Definition Documentation

◆ WAIT_NEXT_COMMAND

#define WAIT_NEXT_COMMAND   1

Definition at line 19 of file pipe.h.

Function Documentation

◆ builtin_pipe()

int builtin_pipe ( t_ast node,
t_ms_data data 
)

execute pipe when | is found in the command

--

  • Parameters
    nodecurrent node in the AST
  • Parameters
    dataminishell structure data
  • Returns
    int return status:
  • - 0: success
  • - 1: error

Definition at line 35 of file pipe.c.

36{
37 int fd[2];
38 pid_t pid_1;
39 pid_t pid_2;
40 int status;
41
42 pid_2 = -1;
43 if (pipe(fd) == -1)
44 ft_perror("pipe");
45 pid_1 = execute_child(node->left, data, fd, 0);
46 if (node->right != NULL)
47 pid_2 = execute_child(node->right, data, fd, 1);
48 else
49 {
50 close(fd[1]);
51 data->std_in = fd[0];
52 return (WAIT_NEXT_COMMAND);
53 }
54 close_fds(fd[0], fd[1]);
55 if (pid_1 > 0)
56 waitpid(pid_1, &status, 0);
57 if (node->right != NULL && pid_2 > 0)
58 waitpid(pid_2, &status, 0);
59 return (WEXITSTATUS(status));
60}
void close_fds(int in, int out)
close two file descriptors
Definition utils_0.c:28
int ft_perror(char *str)
pid_t execute_child(t_ast *node, t_ms_data *data, int fd[2], int direction)
execute child process in the pipe context
Definition pipe.c:71
#define WAIT_NEXT_COMMAND
Definition pipe.h:19
struct s_ast * right
Definition tokens.h:54
struct s_ast * left
Definition tokens.h:53
int std_in
Definition shell.h:26

References close_fds(), execute_child(), ft_perror(), s_ast::left, s_ast::right, s_ms_data::std_in, and WAIT_NEXT_COMMAND.

Referenced by builtin_pipe_test(), and execute_ast().

Here is the call graph for this function:
Here is the caller graph for this function: