core: rebuild of parsing and the execution
This commit is contained in:
44
cmd/cmd.c
Normal file
44
cmd/cmd.c
Normal file
@ -0,0 +1,44 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* cmd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/15 14:18:21 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/02/21 22:27:28 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cmd_private.h"
|
||||
|
||||
void ft_cmddel(void *ptr)
|
||||
{
|
||||
t_cmd *content;
|
||||
|
||||
content = (t_cmd *) ptr;
|
||||
if (content->args != NULL)
|
||||
ft_freer_tab_ultimate(1, content->args);
|
||||
if (content->own_cmd == false && content->executable != NULL)
|
||||
free(content->executable);
|
||||
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]);
|
||||
free(content);
|
||||
}
|
||||
|
||||
void ft_cmd_waiter(void *ptr)
|
||||
{
|
||||
t_cmd *cmd;
|
||||
|
||||
cmd = ptr;
|
||||
if (cmd->pid != -1)
|
||||
{
|
||||
waitpid(cmd->pid, ft_get_exit_code(), 0);
|
||||
}
|
||||
}
|
19
cmd/cmd.h
Normal file
19
cmd/cmd.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef CMD_H
|
||||
# define CMD_H
|
||||
# include <stdbool.h>
|
||||
# include "../data/data.h"
|
||||
|
||||
typedef struct s_cmd
|
||||
{
|
||||
int fd_in[2];
|
||||
int fd_out[2];
|
||||
int pid;
|
||||
char *executable;
|
||||
char **args;
|
||||
bool own_cmd;
|
||||
} t_cmd;
|
||||
|
||||
void ft_cmddel(void *content);
|
||||
void ft_cmd_waiter(void *content);
|
||||
|
||||
#endif
|
8
cmd/cmd_private.h
Normal file
8
cmd/cmd_private.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef CMD_PRIVATE_H
|
||||
# define CMD_PRIVATE_H
|
||||
# include <sys/types.h>
|
||||
# include <sys/wait.h>
|
||||
# include "./cmd.h"
|
||||
# include "../libftx/libftx.h"
|
||||
# include "../data/data.h"
|
||||
#endif
|
Reference in New Issue
Block a user