This commit is contained in:
mdev9
2024-02-23 16:19:32 +01:00
parent 3fd1553fe4
commit 263e4e92a9

View File

@ -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 14:12:21 by marde-vr ### ########.fr */ /* Updated: 2024/02/23 16:18:56 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -161,7 +161,7 @@ int exec(t_msh *msh, t_cmd *cmd, char **cmd_args)
if (pipe(msh->fds) == -1) if (pipe(msh->fds) == -1)
{ {
perror("pipe"); perror("pipe");
ft_printf_fd(2, "exiting\n"); ft_printf_fd(2, "exiting (pipe)\n");
ft_exit(msh, 1); ft_exit(msh, 1);
} }
} }
@ -169,7 +169,7 @@ int exec(t_msh *msh, t_cmd *cmd, char **cmd_args)
if (pid == -1) if (pid == -1)
{ {
perror("fork"); perror("fork");
ft_printf_fd(2, "exiting\n"); ft_printf_fd(2, "exiting (fork)\n");
ft_exit(msh, 1); ft_exit(msh, 1);
} }
if (pid == 0) if (pid == 0)
@ -255,6 +255,14 @@ void remove_command_from_msh(t_msh *msh)
msh->type_in = 0; 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) void exec_command(t_msh *msh)
{ {
int cmd_count; int cmd_count;
@ -268,12 +276,9 @@ void exec_command(t_msh *msh)
msh->pids = ft_calloc(cmd_count, sizeof(int *)); msh->pids = ft_calloc(cmd_count, sizeof(int *));
if (!msh->pids) if (!msh->pids)
ft_exit(msh, 1); ft_exit(msh, 1);
if (cmd_count == 1)
msh->fds[1] = 1;
while (i < cmd_count) while (i < cmd_count)
{ {
//get_out_type get_fds(msh);
//msh->type_out =
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));
@ -283,11 +288,7 @@ void exec_command(t_msh *msh)
i = cmd_count; i = cmd_count;
while (i > 0) while (i > 0)
{ {
if (waitpid(msh->pids[i], 0, 0) < 0) waitpid(msh->pids[i], 0, 0);
{
ft_printf_fd(2, "exiting\n");
ft_exit(msh, 1);
}
i--; i--;
} }
} }