fix fds ouverts

This commit is contained in:
2024-05-06 10:28:30 +02:00
parent 257e4829ba
commit d3e5d459cb
3 changed files with 20 additions and 7 deletions

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */ /* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */
/* Updated: 2024/05/03 13:10:12 by marde-vr ### ########.fr */ /* Updated: 2024/05/06 10:24:38 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -84,6 +84,13 @@ void exec_command(t_msh *msh, int i, int cmd_count)
get_cmd_path(msh); get_cmd_path(msh);
if ((msh->tokens && msh->tokens->value) || is_parenthesis(msh->cmds)) if ((msh->tokens && msh->tokens->value) || is_parenthesis(msh->cmds))
exec(msh, get_cmd_args(msh), i, cmd_count); exec(msh, get_cmd_args(msh), i, cmd_count);
else
{
if (msh->in_fd > 2)
close(msh->in_fd);
if (msh->out_fd > 2)
close(msh->out_fd);
}
} }
remove_command_from_msh(msh); remove_command_from_msh(msh);
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 10:46:28 by marde-vr #+# #+# */ /* Created: 2024/04/24 10:46:28 by marde-vr #+# #+# */
/* Updated: 2024/04/30 14:41:48 by marde-vr ### ########.fr */ /* Updated: 2024/05/06 10:13:22 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -50,17 +50,21 @@ int get_cmd_count(t_cmd *cmds)
{ {
int nb; int nb;
nb = 0; nb = 1;
while (cmds && !is_operand_type(cmds)) while (cmds && !is_operand_type(cmds))
{ {
while (cmds && (is_output_type(cmds) || is_input_type(cmds))) /*while (cmds && (is_output_type(cmds) || is_input_type(cmds)))
cmds = cmds->next; cmds = cmds->next;
if (is_cmd_type(cmds)) if (cmds && is_cmd_type(cmds))
nb++; nb++;
while (cmds && (is_output_type(cmds) || is_input_type(cmds) while (cmds && (is_output_type(cmds) || is_input_type(cmds)
|| is_cmd_type(cmds))) || is_cmd_type(cmds)))
cmds = cmds->next; cmds = cmds->next;
*/
if (cmds && cmds->cmd_type == PIPE) if (cmds && cmds->cmd_type == PIPE)
{
nb++;
}
cmds = cmds->next; cmds = cmds->next;
} }
return (nb); return (nb);

View File

@ -6,7 +6,7 @@
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */ /* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/19 14:09:44 by tomoron #+# #+# */ /* Created: 2024/04/19 14:09:44 by tomoron #+# #+# */
/* Updated: 2024/05/03 14:07:43 by marde-vr ### ########.fr */ /* Updated: 2024/05/06 09:58:11 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -87,6 +87,8 @@ int get_out_type(t_msh *msh, t_cmd *cur_cmd)
int ret; int ret;
msh->out_type = CMD; msh->out_type = CMD;
if (msh->out_fd > 2)
close(msh->out_fd);
msh->out_fd = 0; msh->out_fd = 0;
ret = 0; ret = 0;
go_to_next_out_type(&cur_cmd); go_to_next_out_type(&cur_cmd);