mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 03:16:51 +01:00
「🔨」 fix(exec): fixed fd
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/29 13:20:22 by mmoussou #+# #+# */
|
/* Created: 2024/04/29 13:20:22 by mmoussou #+# #+# */
|
||||||
/* Updated: 2024/08/13 13:44:32 by adjoly ### ########.fr */
|
/* Updated: 2024/08/13 16:35:17 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -41,6 +41,8 @@ int check_file(char *cmd, char *input);
|
|||||||
void free_exec(t_env *env, char **env_array);
|
void free_exec(t_env *env, char **env_array);
|
||||||
void ft_arrcpy(int *dst, int *src, int n);
|
void ft_arrcpy(int *dst, int *src, int n);
|
||||||
|
|
||||||
|
int close_cmd(t_cmd *cmd);
|
||||||
|
|
||||||
void exec_cmd(t_cmd *cmd, char **env, t_env *env_t);
|
void exec_cmd(t_cmd *cmd, char **env, t_env *env_t);
|
||||||
void __fork_single_cmd(t_cmd *cmd, char **env, t_env *env_t, t_exec exec);
|
void __fork_single_cmd(t_cmd *cmd, char **env, t_env *env_t, t_exec exec);
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/15 21:03:31 by mmoussou #+# #+# */
|
/* Created: 2024/07/15 21:03:31 by mmoussou #+# #+# */
|
||||||
/* Updated: 2024/08/09 17:59:41 by mmoussou ### ########.fr */
|
/* Updated: 2024/08/13 16:34:41 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -45,6 +45,8 @@ void exec_cmd(t_cmd *cmd, char **env, t_env *env_t)
|
|||||||
|
|
||||||
void __fork_single_cmd(t_cmd *cmd, char **env, t_env *env_t, t_exec exec)
|
void __fork_single_cmd(t_cmd *cmd, char **env, t_env *env_t, t_exec exec)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
exec.status = dup2(cmd->infile, STDIN_FILENO);
|
exec.status = dup2(cmd->infile, STDIN_FILENO);
|
||||||
if (cmd->infile != STDIN_FILENO)
|
if (cmd->infile != STDIN_FILENO)
|
||||||
close(cmd->infile);
|
close(cmd->infile);
|
||||||
@ -58,7 +60,15 @@ void __fork_single_cmd(t_cmd *cmd, char **env, t_env *env_t, t_exec exec)
|
|||||||
if (exec.pipe_fd[0] != -1)
|
if (exec.pipe_fd[0] != -1)
|
||||||
close(exec.pipe_fd[1]);
|
close(exec.pipe_fd[1]);
|
||||||
if (exec.status != -1)
|
if (exec.status != -1)
|
||||||
|
{
|
||||||
|
i = 3;
|
||||||
|
while (i < 1024)
|
||||||
|
{
|
||||||
|
close(i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
exec_cmd(cmd, 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)
|
int exec_single_cmd_execution(t_cmd *cmd, char **env, t_env *env_t, t_exec exec)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/06/01 14:55:06 by mmoussou #+# #+# */
|
/* Created: 2024/06/01 14:55:06 by mmoussou #+# #+# */
|
||||||
/* Updated: 2024/08/12 16:24:11 by mmoussou ### ########.fr */
|
/* Updated: 2024/08/13 16:32:29 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ int exec_fork_cmd(t_cmd *cmd, char **env, t_env *env_t, int pipe_fd[2])
|
|||||||
char *input;
|
char *input;
|
||||||
|
|
||||||
if (!cmd->cmd)
|
if (!cmd->cmd)
|
||||||
return (get_exit_code(0));
|
return (close_cmd(cmd));
|
||||||
ft_arrcpy(exec.pipe_fd, pipe_fd, 2);
|
ft_arrcpy(exec.pipe_fd, pipe_fd, 2);
|
||||||
input = ft_strdup(cmd->cmd);
|
input = ft_strdup(cmd->cmd);
|
||||||
exec.status = switch_cmd_path(cmd, env_t);
|
exec.status = switch_cmd_path(cmd, env_t);
|
||||||
@ -54,8 +54,7 @@ int exec_single_cmd(t_cmd *cmd, char **env, t_env *env_t, int pipe_fd[2])
|
|||||||
|
|
||||||
if (!cmd->cmd)
|
if (!cmd->cmd)
|
||||||
{
|
{
|
||||||
if (cmd->argv)
|
free_cmd(cmd);
|
||||||
ft_free("a", &(cmd->argv));
|
|
||||||
rl_clear_history();
|
rl_clear_history();
|
||||||
get_exit_code(0);
|
get_exit_code(0);
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/09 22:53:01 by adjoly #+# #+# */
|
/* Created: 2024/07/09 22:53:01 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/08/12 16:16:43 by mmoussou ### ########.fr */
|
/* Updated: 2024/08/13 16:34:54 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -46,3 +46,12 @@ void ft_arrcpy(int *dst, int *src, int n)
|
|||||||
while (n--)
|
while (n--)
|
||||||
dst[n] = src[n];
|
dst[n] = src[n];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int close_cmd(t_cmd *cmd)
|
||||||
|
{
|
||||||
|
if (cmd->infile != STDIN_FILENO)
|
||||||
|
close(cmd->infile);
|
||||||
|
if (cmd->outfile != STDOUT_FILENO)
|
||||||
|
close(cmd->outfile);
|
||||||
|
return (get_exit_code(0));
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user