fixed waitpids

This commit is contained in:
mdev9
2024-02-25 07:32:33 +01:00
parent 263e4e92a9
commit e83d1734b6

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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)
ft_exit(msh, 1);
//close(msh->fds[1]);
close(msh->fds[1]);
}
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);
close(msh->fds[1]);
}
if (msh->cmds->token && (!ft_strcmp(msh->cmds->token, "cd")
|| !ft_strcmp(msh->cmds->token, "alias")
|| !ft_strcmp(msh->cmds->token, "unalias")
@ -151,10 +153,9 @@ void pipe_parent(t_msh *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;
int i;
if (msh->cmds != cmd)
{
@ -179,9 +180,6 @@ int exec(t_msh *msh, t_cmd *cmd, char **cmd_args)
pipe_parent(msh);
//rl_redisplay();
//waitpid(pid, 0, 0);
i = 0;
while (msh->pids[i])
i++;
msh->pids[i] = pid;
}
return (0);
@ -255,13 +253,14 @@ void remove_command_from_msh(t_msh *msh)
msh->type_in = 0;
}
/*
void get_fds(t_msh *msh)
{
msh->fds[1] = 1;
//get_out_type
//msh->type_out =
}
}*/
void exec_command(t_msh *msh)
{
@ -278,17 +277,18 @@ void exec_command(t_msh *msh)
ft_exit(msh, 1);
while (i < cmd_count)
{
get_fds(msh);
if (!cmd_is_builtin(msh, msh->cmds->token))
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);
i++;
}
i = cmd_count;
while (i > 0)
i = cmd_count - 1;
while (i >= 0)
{
//ft_printf_fd(2, "pid: %d\n", msh->pids[i]);
waitpid(msh->pids[i], 0, 0);
i--;
}
//ft_printf_fd(2, "done waiting\n");
}