WIP exec_cmd_line()

+ fix error handle in redirections()
+ rename ft_free_cmd_arr() to free_pipeline()
+ "char **path" added to "struct t_all"
+ misc
This commit is contained in:
LuckyLaszlo
2021-11-16 08:49:57 +01:00
parent bb77de0588
commit 140549db00
11 changed files with 239 additions and 51 deletions

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/10 23:53:17 by lperrey #+# #+# */
/* Updated: 2021/11/14 08:26:32 by lperrey ### ########.fr */
/* Updated: 2021/11/16 08:03:30 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,7 +18,7 @@ int free_exit(t_all *c, int exit_status)
free(c->prompt);
ft_lstclear((t_list **)&c->token_list, free); // a voir avec Hugo, il y a un truc qui me semble superflu dans la fonction
ft_free_2d_arr(c->envp);
ft_free_cmd_arr(c->cmd_arr);
free_pipeline(&c->cmd_arr);
if (c->termios_changed)
tcsetattr(STDIN_FILENO, TCSANOW, &c->ori_termios);
gnl(STDIN_FILENO, NULL, 1);
@@ -26,23 +26,41 @@ int free_exit(t_all *c, int exit_status)
exit(exit_status);
}
void ft_free_cmd_arr(t_cmd **cmd_arr)
void free_pipeline(t_cmd **pipeline_ptr[])
{
int i;
int i;
t_cmd **pipeline;
if (!cmd_arr)
pipeline = *pipeline_ptr;
if (!pipeline)
return ;
close_pipeline_fd(pipeline);
i = 0;
while (pipeline[i])
{
ft_free_2d_arr(pipeline[i]->argv);
free(pipeline[i]->path);
i++;
}
ft_free_2d_arr(pipeline);
*pipeline_ptr = NULL;
}
void close_pipeline_fd(t_cmd *pipeline[])
{
int i;
if (!pipeline)
return ;
i = 0;
while (cmd_arr[i])
while (pipeline[i])
{
ft_free_2d_arr(cmd_arr[i]->argv);
if (cmd_arr[i]->fd_in != STDIN_FILENO && cmd_arr[i]->fd_in > 0)
if (close(cmd_arr[i]->fd_in) == -1)
if (pipeline[i]->fd_in != STDIN_FILENO && pipeline[i]->fd_in > 0)
if (close(pipeline[i]->fd_in) == -1)
perror("close()");
if (cmd_arr[i]->fd_out != STDOUT_FILENO && cmd_arr[i]->fd_out > 0)
if (close(cmd_arr[i]->fd_out) == -1)
if (pipeline[i]->fd_out != STDOUT_FILENO && pipeline[i]->fd_out > 0)
if (close(pipeline[i]->fd_out) == -1)
perror("close()");
i++;
}
ft_free_2d_arr(cmd_arr);
}