connec_cmd_execute: naive recursive pipe implementation (does not handle redirection)

This commit is contained in:
Khaïs COLIN 2025-04-07 10:50:54 +02:00
parent df73b3d0c7
commit 6f75f2d181
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo

View file

@ -6,12 +6,14 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/07 10:38:55 by khais #+# #+# */
/* Updated: 2025/04/07 10:51:19 by khais ### ########.fr */
/* Updated: 2025/04/07 11:36:57 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "connec_cmd_execute.h"
#include "../cmd/cmd_execute.h"
#include "../common/do_waitpid.h"
#include <unistd.h>
static void connec_and_cmd_execute(t_connec_cmd *cmd, t_minishell *app)
{
@ -27,10 +29,27 @@ static void connec_or_cmd_execute(t_connec_cmd *cmd, t_minishell *app)
cmd_execute(cmd->second, app);
}
static void connec_pipe_cmd_execute(t_connec_cmd *cmd, t_minishell *app)
{
int pid1;
int pid2;
pid1 = fork();
if (pid1 == 0)
cmd_execute(cmd->first, app);
pid2 = fork();
if (pid2 == 0)
cmd_execute(cmd->second, app);
do_waitpid(app, pid1);
do_waitpid(app, pid2);
}
void connec_cmd_execute(t_connec_cmd *cmd, t_minishell *app)
{
if (cmd->connector == FT_AND)
connec_and_cmd_execute(cmd, app);
if (cmd->connector == FT_OR)
connec_or_cmd_execute(cmd, app);
if (cmd->connector == FT_PIPE)
connec_pipe_cmd_execute(cmd, app);
}