summaryrefslogtreecommitdiffstats
path: root/src/ft_e_lcom.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ft_e_lcom.c31
1 files changed, 24 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