subshell pipe combo
This commit is contained in:
@@ -175,7 +175,6 @@ int exec_builtin(t_ast_n *node)
|
|||||||
ret = builtin_cd(node->args, node);
|
ret = builtin_cd(node->args, node);
|
||||||
else
|
else
|
||||||
ret = builtin_export(node->args, node);
|
ret = builtin_export(node->args, node);
|
||||||
reset_redir();
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,7 +301,7 @@ void exec_pchild(int *pipes, int index, t_ast_n *pcmd, int cmds)
|
|||||||
if (pcmd->state == _CMD)
|
if (pcmd->state == _CMD)
|
||||||
exec_pcmd(pcmd);
|
exec_pcmd(pcmd);
|
||||||
else if (pcmd->state == _SUBSH)
|
else if (pcmd->state == _SUBSH)
|
||||||
execute_shcommand(pcmd->left);
|
exit (execute_shcommand(pcmd->left));
|
||||||
}
|
}
|
||||||
|
|
||||||
int end_pline(pid_t last_pid, t_ast_n **pline)
|
int end_pline(pid_t last_pid, t_ast_n **pline)
|
||||||
@@ -331,7 +330,7 @@ int exec_pline(t_ast_n **pline)
|
|||||||
i = -1;
|
i = -1;
|
||||||
while (pline[++i])
|
while (pline[++i])
|
||||||
{
|
{
|
||||||
ft_fprintf(2, "test\n");
|
/*ft_fprintf(2, "test\n");*/
|
||||||
pipe(pline[i]->fds);
|
pipe(pline[i]->fds);
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
@@ -356,7 +355,7 @@ int exec_shcmd(t_ast_n *node)
|
|||||||
int status;
|
int status;
|
||||||
|
|
||||||
if (is_builtin(node->cmd))
|
if (is_builtin(node->cmd))
|
||||||
exit (exec_builtin(node));
|
return (exec_builtin(node));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pid = fork();
|
pid = fork();
|
||||||
@@ -366,13 +365,13 @@ int exec_shcmd(t_ast_n *node)
|
|||||||
{
|
{
|
||||||
waitpid(pid, &status, 0);
|
waitpid(pid, &status, 0);
|
||||||
if (WIFEXITED(status))
|
if (WIFEXITED(status))
|
||||||
exit (WEXITSTATUS(status));
|
return (WEXITSTATUS(status));
|
||||||
else
|
else
|
||||||
exit (1);
|
return (1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
perror("fork");
|
perror("fork");
|
||||||
exit (1);
|
return (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -414,13 +413,16 @@ int exec_subsh(t_ast_n *node)
|
|||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
{
|
{
|
||||||
// handle_redir(node);
|
// handle_redir(node);
|
||||||
return (execute_shcommand(node));
|
exit (execute_shcommand(node));
|
||||||
}
|
}
|
||||||
else if (pid > 0)
|
else if (pid > 0)
|
||||||
{
|
{
|
||||||
waitpid(pid, &status, 0);
|
waitpid(pid, &status, 0);
|
||||||
if (WIFEXITED(status))
|
reset_redir();
|
||||||
|
if (WIFEXITED(status) && node->parent->state != _PLINE)
|
||||||
return (WEXITSTATUS(status));
|
return (WEXITSTATUS(status));
|
||||||
|
else if (WIFEXITED(status) && node->parent->state == _PLINE)
|
||||||
|
exit (WEXITSTATUS(status));
|
||||||
else
|
else
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
@@ -436,24 +438,25 @@ int execute_command(t_ast_n *node)
|
|||||||
int status;
|
int status;
|
||||||
|
|
||||||
if (node->state == _CMD)
|
if (node->state == _CMD)
|
||||||
return (exec_scmd(node));
|
status = exec_scmd(node);
|
||||||
else if (node->state == _AND)
|
else if (node->state == _AND)
|
||||||
{
|
{
|
||||||
status = execute_command(node->left);
|
status = execute_command(node->left);
|
||||||
if (status == 0)
|
if (status == 0)
|
||||||
return (execute_command(node->right));
|
status = execute_command(node->right);
|
||||||
return (status);
|
/*return (status);*/
|
||||||
}
|
}
|
||||||
else if (node->state == _OR)
|
else if (node->state == _OR)
|
||||||
{
|
{
|
||||||
status = execute_command(node->left);
|
status = execute_command(node->left);
|
||||||
if (status != 0)
|
if (status != 0)
|
||||||
return (execute_command(node->right));
|
status = execute_command(node->right);
|
||||||
return (status);
|
/*return (status);*/
|
||||||
}
|
}
|
||||||
else if (node->state == _PLINE)
|
else if (node->state == _PLINE)
|
||||||
return (exec_pline(node->pline));
|
status = exec_pline(node->pline);
|
||||||
else if (node->state == _SUBSH)
|
else if (node->state == _SUBSH)
|
||||||
return (exec_subsh(node->left));
|
status = exec_subsh(node->left);
|
||||||
return (0);
|
reset_redir();
|
||||||
|
return (status);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user