2023-02-15 14:52:27 -05:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* cmd.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2023/02/15 14:18:21 by cchauvet #+# #+# */
|
2023-02-21 16:38:00 -05:00
|
|
|
/* Updated: 2023/02/21 22:27:28 by cchauvet ### ########.fr */
|
2023-02-15 14:52:27 -05:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
2023-03-10 06:32:39 -05:00
|
|
|
#include "cmd_private.h"
|
2023-02-15 14:52:27 -05:00
|
|
|
|
|
|
|
void ft_cmddel(void *ptr)
|
|
|
|
{
|
|
|
|
t_cmd *content;
|
|
|
|
|
|
|
|
content = (t_cmd *) ptr;
|
|
|
|
if (content->args != NULL)
|
|
|
|
ft_freer_tab_ultimate(1, content->args);
|
2023-03-10 06:32:39 -05:00
|
|
|
if (content->own_cmd == false && content->executable != NULL)
|
2023-02-15 14:52:27 -05:00
|
|
|
free(content->executable);
|
2023-03-10 06:32:39 -05:00
|
|
|
if (content->fd_in[0] > 2)
|
|
|
|
close(content->fd_in[0]);
|
|
|
|
if (content->fd_out[0] > 2)
|
|
|
|
close(content->fd_out[0]);
|
|
|
|
if (content->fd_in[1] > 2)
|
|
|
|
close(content->fd_in[1]);
|
|
|
|
if (content->fd_out[1] > 2)
|
|
|
|
close(content->fd_out[1]);
|
2023-02-15 14:52:27 -05:00
|
|
|
free(content);
|
|
|
|
}
|
|
|
|
|
2023-03-10 06:32:39 -05:00
|
|
|
void ft_cmd_waiter(void *ptr)
|
2023-02-15 14:52:27 -05:00
|
|
|
{
|
2023-03-10 06:32:39 -05:00
|
|
|
t_cmd *cmd;
|
2023-02-15 14:52:27 -05:00
|
|
|
|
2023-03-10 06:32:39 -05:00
|
|
|
cmd = ptr;
|
|
|
|
if (cmd->pid != -1)
|
2023-02-15 14:52:27 -05:00
|
|
|
{
|
2023-03-10 06:32:39 -05:00
|
|
|
waitpid(cmd->pid, ft_get_exit_code(), 0);
|
2023-02-15 14:52:27 -05:00
|
|
|
}
|
|
|
|
}
|