From 6ac6f778e30e208d7ce534a615a8537587b67716 Mon Sep 17 00:00:00 2001 From: y-syo Date: Thu, 18 Jul 2024 14:43:30 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix(exec):=20f?= =?UTF-8?q?ds=20for=20non-forked=20cmds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/builtins.h | 6 +++--- include/execution.h | 4 ++-- src/builtins/ft_echo.c | 5 +++-- src/builtins/ft_export.c | 10 +++++----- src/exec/exec_cmd.c | 24 ++++++++++++------------ src/exec/exec_split_cmd.c | 2 +- 6 files changed, 26 insertions(+), 25 deletions(-) diff --git a/include/builtins.h b/include/builtins.h index 890e264..ff3b80d 100644 --- a/include/builtins.h +++ b/include/builtins.h @@ -6,7 +6,7 @@ /* By: mmoussou +#+ +:+ +#+ */ +/* By: mmoussou 0) new_line = false; diff --git a/src/builtins/ft_export.c b/src/builtins/ft_export.c index 9e8ed29..d9f9c34 100644 --- a/src/builtins/ft_export.c +++ b/src/builtins/ft_export.c @@ -6,14 +6,14 @@ /* By: mmoussou cmd); if (i) { if (i == 5) - ft_echo(argv + 1); + ft_echo(cmd->argv + 1, cmd->outfile); if (i == 2) - ft_cd(env_t, argv[1]); + ft_cd(env_t, (cmd->argv)[1]); if (i == 6) ft_pwd(); if (i == 4) - ft_export(argv + 1, env_t); + ft_export(cmd->argv + 1, env_t, cmd->outfile); if (i == 3) - ft_unset(&argv[1], env_t); + ft_unset(&(cmd->argv)[1], env_t); if (i == 7) ft_env(env_t); if (i == 1) - ft_exit(argv, ft_arrlen(argv), env, env_t); + ft_exit(cmd->argv, ft_arrlen(cmd->argv), env, env_t); } else { ft_envclear(&env_t, free); - execve(cmd, argv, env); + execve(cmd->cmd, cmd->argv, env); } } @@ -58,7 +58,7 @@ void __fork_single_cmd(t_cmd *cmd, char **env, t_env *env_t, t_exec exec) if (exec.pipe_fd[0] != -1) close(exec.pipe_fd[1]); if (exec.status != -1) - exec_cmd(cmd->cmd, cmd->argv, env, env_t); + exec_cmd(cmd, env, env_t); } int exec_single_cmd_execution(t_cmd *cmd, char **env, t_env *env_t, t_exec exec) @@ -66,14 +66,14 @@ 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); + exec_cmd(cmd, env, env_t); 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); + free_exit(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 d61d859..2968eff 100644 --- a/src/exec/exec_split_cmd.c +++ b/src/exec/exec_split_cmd.c @@ -6,7 +6,7 @@ /* By: mmoussou