fixed waitpids
This commit is contained in:
24
srcs/exec.c
24
srcs/exec.c
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */
|
/* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/02/23 16:18:56 by marde-vr ### ########.fr */
|
/* Updated: 2024/02/25 07:32:05 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ void redirect_output(t_msh *msh)
|
|||||||
{
|
{
|
||||||
if (dup2(msh->fds[1], 1) < 0)
|
if (dup2(msh->fds[1], 1) < 0)
|
||||||
ft_exit(msh, 1);
|
ft_exit(msh, 1);
|
||||||
//close(msh->fds[1]);
|
close(msh->fds[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pipe_child(t_msh *msh, char **cmd_args)
|
void pipe_child(t_msh *msh, char **cmd_args)
|
||||||
@ -132,6 +132,8 @@ void pipe_child(t_msh *msh, char **cmd_args)
|
|||||||
redirect_output(msh);
|
redirect_output(msh);
|
||||||
close(msh->fds[1]);
|
close(msh->fds[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (msh->cmds->token && (!ft_strcmp(msh->cmds->token, "cd")
|
if (msh->cmds->token && (!ft_strcmp(msh->cmds->token, "cd")
|
||||||
|| !ft_strcmp(msh->cmds->token, "alias")
|
|| !ft_strcmp(msh->cmds->token, "alias")
|
||||||
|| !ft_strcmp(msh->cmds->token, "unalias")
|
|| !ft_strcmp(msh->cmds->token, "unalias")
|
||||||
@ -151,10 +153,9 @@ void pipe_parent(t_msh *msh)
|
|||||||
(void)msh;
|
(void)msh;
|
||||||
}
|
}
|
||||||
|
|
||||||
int exec(t_msh *msh, t_cmd *cmd, char **cmd_args)
|
int exec(t_msh *msh, t_cmd *cmd, char **cmd_args, int i)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int i;
|
|
||||||
|
|
||||||
if (msh->cmds != cmd)
|
if (msh->cmds != cmd)
|
||||||
{
|
{
|
||||||
@ -179,9 +180,6 @@ int exec(t_msh *msh, t_cmd *cmd, char **cmd_args)
|
|||||||
pipe_parent(msh);
|
pipe_parent(msh);
|
||||||
//rl_redisplay();
|
//rl_redisplay();
|
||||||
//waitpid(pid, 0, 0);
|
//waitpid(pid, 0, 0);
|
||||||
i = 0;
|
|
||||||
while (msh->pids[i])
|
|
||||||
i++;
|
|
||||||
msh->pids[i] = pid;
|
msh->pids[i] = pid;
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
@ -255,13 +253,14 @@ void remove_command_from_msh(t_msh *msh)
|
|||||||
msh->type_in = 0;
|
msh->type_in = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
void get_fds(t_msh *msh)
|
void get_fds(t_msh *msh)
|
||||||
{
|
{
|
||||||
msh->fds[1] = 1;
|
msh->fds[1] = 1;
|
||||||
|
|
||||||
//get_out_type
|
//get_out_type
|
||||||
//msh->type_out =
|
//msh->type_out =
|
||||||
}
|
}*/
|
||||||
|
|
||||||
void exec_command(t_msh *msh)
|
void exec_command(t_msh *msh)
|
||||||
{
|
{
|
||||||
@ -278,17 +277,18 @@ void exec_command(t_msh *msh)
|
|||||||
ft_exit(msh, 1);
|
ft_exit(msh, 1);
|
||||||
while (i < cmd_count)
|
while (i < cmd_count)
|
||||||
{
|
{
|
||||||
get_fds(msh);
|
|
||||||
if (!cmd_is_builtin(msh, msh->cmds->token))
|
if (!cmd_is_builtin(msh, msh->cmds->token))
|
||||||
get_cmd_path(msh);
|
get_cmd_path(msh);
|
||||||
exec(msh, msh->cmds, get_cmd_args(msh));
|
exec(msh, msh->cmds, get_cmd_args(msh), i);
|
||||||
remove_command_from_msh(msh);
|
remove_command_from_msh(msh);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
i = cmd_count;
|
i = cmd_count - 1;
|
||||||
while (i > 0)
|
while (i >= 0)
|
||||||
{
|
{
|
||||||
|
//ft_printf_fd(2, "pid: %d\n", msh->pids[i]);
|
||||||
waitpid(msh->pids[i], 0, 0);
|
waitpid(msh->pids[i], 0, 0);
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
|
//ft_printf_fd(2, "done waiting\n");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user