aboutsummaryrefslogtreecommitdiff
path: root/src/eval/eval.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/eval/eval.c')
-rw-r--r--src/eval/eval.c37
1 files changed, 14 insertions, 23 deletions
diff --git a/src/eval/eval.c b/src/eval/eval.c
index d2eb822..2aed026 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/06 12:57:33 by cacharle ### ########.fr */
+/* Updated: 2020/10/06 17:21:54 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -32,39 +32,30 @@ int st_replace(int oldfd, int newfd)
** \return The child status code or EVAL_FATAL on error
*/
-int fork_wrap(
- int fds[2], void *passed, t_wrapped_func wrapped, pid_t *child_pid, int fd_to_close
-)
+int fork_wrap(int fds[2], void *passed, t_wrapped_func wrapped)
{
int status;
- bool waiting;
+ /* bool waiting; */
pid_t pid;
- waiting = child_pid == NULL;
- if (waiting)
- child_pid = &pid;
- if ((*child_pid = fork()) == -1)
+ if ((pid = fork()) == -1)
return (EVAL_FATAL);
- if (*child_pid == 0)
+ if (pid == 0)
{
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 (fd_to_close != FD_NONE) */
+ /* close(fd_to_close); */
if ((status = wrapped(passed)) == EVAL_FATAL)
exit(EXIT_FAILURE);
exit(status);
}
- g_child_pid = *child_pid;
- if (waiting)
- {
- waitpid(*child_pid, child_pid, 0);
- close(fds[FD_WRITE]);
- return (WEXITSTATUS(*child_pid));
- }
- return (0);
+ g_child_pid = pid;
+ waitpid(pid, &pid, 0);
+ /* close(fds[FD_WRITE]); */
+ return (WEXITSTATUS(pid));
}
/*
@@ -72,15 +63,15 @@ int fork_wrap(
** \return The last command status or EVAL_FATAL on error
*/
-int eval(int fds[2], t_env env, t_ast *ast, pid_t *child_pid, int fd_to_close)
+int eval(int fds[2], t_env env, t_ast *ast)
{
if (ast->tag == AST_OP)
return (eval_operation(fds, env, ast));
if (ast->tag == AST_CMD)
- return (eval_cmd(fds, env, ast, child_pid, fd_to_close));
+ return (eval_cmd(fds, env, ast));
if (ast->tag == AST_PIPELINE)
return (eval_pipeline(fds, env, ast));
if (ast->tag == AST_PARENT)
- return (eval_parenthesis(fds, env, ast, child_pid, fd_to_close));
+ return (eval_parenthesis(fds, env, ast));
return (EVAL_FATAL);
}