From a401068e3cdb90f3e1e599e3c4982068a5a74c52 Mon Sep 17 00:00:00 2001 From: y-syo Date: Thu, 18 Jul 2024 14:28:19 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=8F=97=EF=B8=8F=E3=80=8D=20wip(e?= =?UTF-8?q?xec/exec=5Fcmd):=20fixing=20redirections=20with=20builtins?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/env.h | 4 ++-- include/execution.h | 4 +++- src/exec/exec_cmd.c | 21 ++++++++++++++++++++- src/exec/exec_split_cmd.c | 13 +++---------- src/parsing/check_error/run_checks.c | 5 +++-- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/include/env.h b/include/env.h index 8983df2..1118564 100644 --- a/include/env.h +++ b/include/env.h @@ -6,7 +6,7 @@ /* By: mmoussou cmd, cmd->argv, env, env_t); } + +int exec_single_cmd_execution(t_cmd *cmd, char **env, t_env *env_t, t_exec exec) +{ + int fork_pid; + + if (is_in_builtins(cmd->cmd) > 0 && is_in_builtins(cmd->cmd) < 5) + __fork_single_cmd(cmd, env, env_t, exec); + if (is_in_builtins(cmd->cmd) > 0 && is_in_builtins(cmd->cmd) < 5) + return (0); + fork_pid = fork(); + if (!fork_pid) + { + __fork_single_cmd(cmd, env, env_t, exec); + free_exec(env_t, env); + exit(get_exit_code(-1)); + } + return (fork_pid); +} diff --git a/src/exec/exec_split_cmd.c b/src/exec/exec_split_cmd.c index 42eb18e..d61d859 100644 --- a/src/exec/exec_split_cmd.c +++ b/src/exec/exec_split_cmd.c @@ -6,7 +6,7 @@ /* By: mmoussou cmd); @@ -66,14 +65,8 @@ int exec_single_cmd(t_cmd *cmd, char **env, t_env *env_t, int pipe_fd[2]) return (-1); } free(input); - if (is_in_builtins(cmd->cmd) > 0) - exec_cmd(cmd->cmd, cmd->argv, env, env_t); - if (is_in_builtins(cmd->cmd) > 0) - return (0); - fork_pid = fork(); - if (!fork_pid) - __fork_single_cmd(cmd, env, env_t, exec); - return (fork_pid); + exec.status = exec_single_cmd_execution(cmd, env, env_t, exec); + return (exec.status); } t_exec exec_pipe_unforked(t_exec exec, t_list *list_cmd, t_env *env) diff --git a/src/parsing/check_error/run_checks.c b/src/parsing/check_error/run_checks.c index 7a1be7c..376b457 100644 --- a/src/parsing/check_error/run_checks.c +++ b/src/parsing/check_error/run_checks.c @@ -3,15 +3,16 @@ /* ::: :::::::: */ /* run_checks.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: adjoly +#+ +:+ +#+ */ +/* By: mmoussou #include bool run_checks(char *rl)