diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-23 12:48:58 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-23 12:48:58 +0200 |
commit | a6bf9c5397fe58a1a344c791cd4aeebb8eb46f03 (patch) | |
tree | e81c270dbe4c7b56aa385a426081b4218f9b26fb | |
parent | It's not working at all (diff) | |
download | 42-minishell-a6bf9c5397fe58a1a344c791cd4aeebb8eb46f03.tar.gz 42-minishell-a6bf9c5397fe58a1a344c791cd4aeebb8eb46f03.tar.bz2 42-minishell-a6bf9c5397fe58a1a344c791cd4aeebb8eb46f03.tar.xz 42-minishell-a6bf9c5397fe58a1a344c791cd4aeebb8eb46f03.tar.zst 42-minishell-a6bf9c5397fe58a1a344c791cd4aeebb8eb46f03.zip |
Ok but not ok
Diffstat (limited to '')
-rw-r--r-- | src/ft_e_lcom.c | 31 | ||||
-rw-r--r-- | src/ft_p_lcom.c | 1 |
2 files changed, 25 insertions, 7 deletions
diff --git a/src/ft_e_lcom.c b/src/ft_e_lcom.c index 36fb430..8cb4879 100644 --- a/src/ft_e_lcom.c +++ b/src/ft_e_lcom.c @@ -15,6 +15,8 @@ #include <stdlib.h> #include <fcntl.h> #include <unistd.h> +#include <signal.h> +#include <sys/wait.h> #include "ft_s_struct.h" static uint8_t @@ -35,9 +37,12 @@ static uint8_t uint8_t ft_e_lcom(t_msh *msh) { + /* TODO: norme */ t_lcom *ptr; int32_t write_fd; + int32_t status; uint8_t bu_id; + pid_t pid; ptr = msh->curr; while (ptr != NULL) @@ -45,18 +50,30 @@ uint8_t if ((bu_id = ft_get_builtin_id(ptr->com, msh)) < FT_BUILTINS_COUNT) { - if (ptr->redir == 1) + if ((pid = fork()) == 0) { - if ((write_fd = open(ptr->rdrpath, O_CREAT | O_RDWR, 0644))) + if (ptr->redir == 1) { - /* TODO: handle err */ + if ((write_fd = open(ptr->rdrpath, O_CREAT | O_RDWR, 0644))) + { + /* TODO: handle err */ + } + dup2(write_fd, STDOUT_FILENO); + close(write_fd); } - dup2(write_fd, STDOUT_FILENO); + msh->ret = msh->bu_ptr[bu_id](ptr->args, msh); + kill(pid, SIGTERM); } - msh->ret = msh->bu_ptr[bu_id](ptr->args, msh); - if (ptr->redir == 1) + else if (pid < 0) { - close(write_fd); + /* TODO: handle fork failed */ + } + else + { + while (!(wait(&status) == pid)) + { + /* TODO: fix this syntax */ + } } } else diff --git a/src/ft_p_lcom.c b/src/ft_p_lcom.c index aec344f..45fcf17 100644 --- a/src/ft_p_lcom.c +++ b/src/ft_p_lcom.c @@ -118,6 +118,7 @@ int8_t ft_rdr_err_check(ptr, link); if (ft_get_rdrpath(ptr, link) != 0) return (-1); + /* TODO: don't check files here, check at run-time */ ft_check_redir_file(link); } return (0); |