aboutsummaryrefslogtreecommitdiff
path: root/src/eval
diff options
context:
space:
mode:
Diffstat (limited to 'src/eval')
-rw-r--r--src/eval/eval.c7
-rw-r--r--src/eval/operation.c7
2 files changed, 8 insertions, 6 deletions
diff --git a/src/eval/eval.c b/src/eval/eval.c
index 86d038e..66a535b 100644
--- a/src/eval/eval.c
+++ b/src/eval/eval.c
@@ -6,7 +6,7 @@
/* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/09/13 20:38:06 by charles #+# #+# */
-/* Updated: 2020/10/07 10:25:39 by cacharle ### ########.fr */
+/* Updated: 2020/10/07 15:02:21 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -35,26 +35,23 @@ int st_replace(int oldfd, int newfd)
int fork_wrap(int fds[2], void *passed, t_wrapped_func wrapped)
{
int status;
- /* bool waiting; */
pid_t pid;
if ((pid = fork()) == -1)
return (EVAL_FATAL);
if (pid == 0)
{
+ g_state.is_child = true;
if (st_replace(fds[FD_READ], STDIN_FILENO) != 0)
exit(EXIT_FAILURE);
if (st_replace(fds[FD_WRITE], STDOUT_FILENO) != 0)
exit(EXIT_FAILURE);
- /* if (fd_to_close != FD_NONE) */
- /* close(fd_to_close); */
if ((status = wrapped(passed)) == EVAL_FATAL)
exit(EXIT_FAILURE);
exit(status);
}
g_child_pid = pid;
waitpid(pid, &pid, 0);
- /* close(fds[FD_WRITE]); */
return (WEXITSTATUS(pid));
}
diff --git a/src/eval/operation.c b/src/eval/operation.c
index 156f6f5..1620be2 100644
--- a/src/eval/operation.c
+++ b/src/eval/operation.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/17 15:27:22 by charles #+# #+# */
-/* Updated: 2020/10/07 11:31:47 by cacharle ### ########.fr */
+/* Updated: 2020/10/07 15:08:11 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -25,6 +25,8 @@ int eval_operation(int fds[2], t_env env, t_ast *ast)
if ((status = eval(left_fds, env, ast->op.left)) == EVAL_FATAL)
return (EVAL_FATAL);
g_state.last_status = status;
+ if (g_state.killed)
+ return (status);
if ((ast->op.sep == TAG_AND && status != 0) ||
(ast->op.sep == TAG_OR && status == 0))
return (status);
@@ -50,6 +52,7 @@ int eval_pipeline(int fds[2], t_env env, t_ast *ast)
int pid = fork();
if (pid == 0)
{
+ g_state.is_child = true;
dup2(p[FD_WRITE], STDOUT_FILENO);
if (prev_output != STDIN_FILENO)
{
@@ -71,6 +74,7 @@ int eval_pipeline(int fds[2], t_env env, t_ast *ast)
int pid = fork();
if (pid == 0)
{
+ g_state.is_child = true;
if (prev_output != STDIN_FILENO)
{
dup2(prev_output, STDIN_FILENO);
@@ -81,6 +85,7 @@ int eval_pipeline(int fds[2], t_env env, t_ast *ast)
fds[1] = FD_NONE;
exit(eval(fds, env, curr->data));
}
+ g_child_pid = pid;
close(p[FD_READ]);
int status = 0;