fix: exit

This commit is contained in:
Camille Chauvet 2023-03-06 14:22:30 +01:00
parent 686ea5d0db
commit 5bfc613126
2 changed files with 21 additions and 35 deletions

View File

@ -89,6 +89,10 @@ static int ft_executor(t_data *data, t_cmd *cmd)
return (1);
dup2(cmd->fd_out, 1);
dup2(cmd->fd_in, 0);
if (cmd->fd_out > 2)
close(cmd->fd_out);
if (cmd->fd_in > 2)
close(cmd->fd_in);
execve(cmd->executable, cmd->args, tab);
}
else

52
main.c
View File

@ -43,6 +43,7 @@ static int ft_minishell(t_data *data, char *line)
char *line_clean;
int infile;
int outfile;
int return_value;
if (ft_syntatic_verif(data, line))
return (1);
@ -50,47 +51,27 @@ static int ft_minishell(t_data *data, char *line)
if (line_clean == NULL)
return (1);
outfile = ft_outfile(data, line_clean);
return_value = 0;
if (outfile == -2)
{
free(line_clean);
return (1);
}
return_value = 1;
infile = ft_infile(data, line_clean);
if (infile == -2)
{
if (outfile > 2)
close(outfile);
free(line_clean);
return (1);
}
if (ft_gen_exit_code_var(data))
{
if (outfile > 2)
close(outfile);
if (infile > 2)
close(infile);
ft_lstclear(cmds, ft_cmddel);
free(cmds);
free(line_clean);
return (1);
}
if (return_value == 0 && infile == -2)
return_value = 1;
if (return_value == 0&& ft_gen_exit_code_var(data))
return_value = 1;
cmds = ft_parse_cmds(data, line_clean, infile, outfile);
if (cmds == NULL)
{
if (outfile > 2)
close(outfile);
if (infile > 2)
close(infile);
ft_lstclear(cmds, ft_cmddel);
free(cmds);
free(line_clean);
return (1);
}
ft_cmds_executor(data, cmds);
if (return_value == 0 && cmds == NULL)
return_value = 1;
if (return_value == 0 && ft_cmds_executor(data, cmds))
return_value = 1;
if (outfile > 2)
close(outfile);
if (infile > 2)
close(infile);
ft_lstclear(cmds, ft_cmddel);
free(cmds);
free(line_clean);
return (0);
return (-1 * return_value);
}
void ft_ctrlc(int num)
@ -144,6 +125,7 @@ int main(int ac, char **av, char **env)
break ;
}
ft_lstclear(data.env, env_del);
free(data.exit_code_str);
free(data.env);
return (data.exit_code);
}