mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-05 23:18:08 +01:00
fix(connec_cmd): handle nested connections correctly
This commit is contained in:
parent
92d647e33c
commit
65c1eb9d84
4 changed files with 20 additions and 20 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/07 10:38:55 by khais #+# #+# */
|
||||
/* Updated: 2025/04/25 17:58:15 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/28 15:04:45 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,19 +16,15 @@
|
|||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static void connec_and_cmd_execute(t_connec_cmd *cmd, t_minishell *app,
|
||||
bool should_exit)
|
||||
static void connec_and_cmd_execute(t_connec_cmd *cmd, t_minishell *app)
|
||||
{
|
||||
(void)should_exit;
|
||||
cmd_execute(cmd->first, app, false);
|
||||
if (app->last_return_value == 0)
|
||||
cmd_execute(cmd->second, app, false);
|
||||
}
|
||||
|
||||
static void connec_or_cmd_execute(t_connec_cmd *cmd, t_minishell *app,
|
||||
bool should_exit)
|
||||
static void connec_or_cmd_execute(t_connec_cmd *cmd, t_minishell *app)
|
||||
{
|
||||
(void)should_exit;
|
||||
cmd_execute(cmd->first, app, false);
|
||||
if (app->last_return_value != 0)
|
||||
cmd_execute(cmd->second, app, false);
|
||||
|
|
@ -40,9 +36,11 @@ void connec_cmd_execute(t_connec_cmd *cmd, t_minishell *app,
|
|||
if (cmd == NULL)
|
||||
return ;
|
||||
if (cmd->connector == FT_AND)
|
||||
connec_and_cmd_execute(cmd, app, should_exit);
|
||||
connec_and_cmd_execute(cmd, app);
|
||||
if (cmd->connector == FT_OR)
|
||||
connec_or_cmd_execute(cmd, app, should_exit);
|
||||
connec_or_cmd_execute(cmd, app);
|
||||
if (cmd->connector == FT_PIPE)
|
||||
connec_pipe_cmd_execute(cmd, app, should_exit);
|
||||
connec_pipe_cmd_execute(cmd, app);
|
||||
if (should_exit)
|
||||
exit(app->last_return_value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/11 12:01:29 by khais #+# #+# */
|
||||
/* Updated: 2025/04/16 16:56:55 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/28 15:04:17 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -46,8 +46,7 @@ static void close_and_wait(t_minishell *app, int pid1, int pid2, int pipefd[2])
|
|||
do_waitpid(app, pid2);
|
||||
}
|
||||
|
||||
void connec_pipe_cmd_execute(t_connec_cmd *cmd, t_minishell *app,
|
||||
bool should_exit)
|
||||
void connec_pipe_cmd_execute(t_connec_cmd *cmd, t_minishell *app)
|
||||
{
|
||||
int pid1;
|
||||
int pid2;
|
||||
|
|
@ -69,9 +68,5 @@ void connec_pipe_cmd_execute(t_connec_cmd *cmd, t_minishell *app,
|
|||
cmd_execute(cmd->second, app, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
close_and_wait(app, pid1, pid2, pipefd);
|
||||
if (should_exit)
|
||||
exit(app->last_return_value);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/11 11:56:45 by khais #+# #+# */
|
||||
/* Updated: 2025/04/16 16:56:43 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/28 15:04:23 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
# include "../../minishell.h"
|
||||
|
||||
void connec_pipe_cmd_execute(t_connec_cmd *cmd, t_minishell *app,
|
||||
bool should_exit);
|
||||
void connec_pipe_cmd_execute(t_connec_cmd *cmd, t_minishell *app);
|
||||
|
||||
#endif // CONNEC_PIPE_CMD_EXECUTE_H
|
||||
|
|
|
|||
8
test.sh
8
test.sh
|
|
@ -1441,4 +1441,12 @@ minishell: infile: No such file or directory
|
|||
1
|
||||
EOF
|
||||
|
||||
when_run <<EOF "nested connections"
|
||||
(echo hi||pwd)&&(echo hello||pwd)
|
||||
EOF
|
||||
expecting <<EOF
|
||||
hi
|
||||
hello
|
||||
EOF
|
||||
|
||||
finalize
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue