aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-10-06 17:23:23 +0200
committerCharles Cabergs <me@cacharle.xyz>2020-10-06 17:23:23 +0200
commit89bd998bcf0839a83daf16ab9b1e8ae568a8a9f2 (patch)
tree84627975d6a6379f5a56b31eeaee90f55a231d1d
parentfc862343cc5d0c305811fe23311084ae3702ed42 (diff)
downloadminishell-89bd998bcf0839a83daf16ab9b1e8ae568a8a9f2.tar.gz
minishell-89bd998bcf0839a83daf16ab9b1e8ae568a8a9f2.tar.bz2
minishell-89bd998bcf0839a83daf16ab9b1e8ae568a8a9f2.zip
Removing previous pipe bloat
-rw-r--r--include/eval.h11
-rw-r--r--src/eval/cmd.c8
-rw-r--r--src/eval/eval.c37
-rw-r--r--src/eval/operation.c10
-rw-r--r--src/eval/parenthesis.c8
-rw-r--r--src/main.c4
6 files changed, 35 insertions, 43 deletions
diff --git a/include/eval.h b/include/eval.h
index 819b3cc..2aa4f1d 100644
--- a/include/eval.h
+++ b/include/eval.h
@@ -6,7 +6,7 @@
/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:05:30 by charles #+# #+# */
-/* Updated: 2020/09/15 20:09:27 by charles ### ########.fr */
+/* Updated: 2020/10/06 17:22:12 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -49,26 +49,27 @@ extern pid_t g_child_pid;
** eval.c
*/
-int fork_wrap(int fds[2], void *passed, t_wrapped_func wrapped, pid_t *child_pid, int fd_to_close);
-int eval(int fds[2], t_env env, t_ast *ast, pid_t *child_pid, int fd_to_close);
+int fork_wrap(int fds[2], void *passed, t_wrapped_func wrapped);
+int eval(int fds[2], t_env env, t_ast *ast);
/*
** cmd.c
*/
-int eval_cmd(int fds[2], t_env env, t_ast *ast, pid_t *child_pid, int fd_to_close);
+int eval_cmd(int fds[2], t_env env, t_ast *ast);
/*
** operation.c
*/
int eval_operation(int fds[2], t_env env, t_ast *ast);
+int eval_pipeline(int fds[2], t_env env, t_ast *ast);
/*
** parenthesis.c
*/
-int eval_parenthesis(int fds[2], t_env env, t_ast *ast, pid_t *child_pid, int fd_to_close);
+int eval_parenthesis(int fds[2], t_env env, t_ast *ast);
/*
** redir.c
diff --git a/src/eval/cmd.c b/src/eval/cmd.c
index 5cabbba..8c08b78 100644
--- a/src/eval/cmd.c
+++ b/src/eval/cmd.c
@@ -6,7 +6,7 @@
/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/14 10:41:31 by charles #+# #+# */
-/* Updated: 2020/09/16 19:39:42 by charles ### ########.fr */
+/* Updated: 2020/10/06 17:18:20 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -30,7 +30,7 @@ int wrapped_cmd(t_fork_param_cmd *param)
return (status);
}
-int eval_cmd(int fds[2], t_env env, t_ast *ast, pid_t *child_pid, int fd_to_close)
+int eval_cmd(int fds[2], t_env env, t_ast *ast)
{
t_fork_param_cmd param;
char **argv;
@@ -44,7 +44,7 @@ int eval_cmd(int fds[2], t_env env, t_ast *ast, pid_t *child_pid, int fd_to_cl
if (argv[0] == NULL)
return (0);
param.builtin = builtin_search_func(argv[0]);
- if (param.builtin != NULL && !param.builtin->forked && child_pid == NULL)
+ if (param.builtin != NULL && !param.builtin->forked)
return (param.builtin->func(argv, env));
if (param.builtin == NULL
@@ -56,7 +56,7 @@ int eval_cmd(int fds[2], t_env env, t_ast *ast, pid_t *child_pid, int fd_to_cl
param.argv = argv;
param.env = env;
- status = fork_wrap(fds, &param, (t_wrapped_func)wrapped_cmd, child_pid, fd_to_close);
+ status = fork_wrap(fds, &param, (t_wrapped_func)wrapped_cmd);
ft_split_destroy(argv);
g_state.last_status = status;
return (status);
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);
}
diff --git a/src/eval/operation.c b/src/eval/operation.c
index d8206b6..df54346 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/06 16:11:54 by cacharle ### ########.fr */
+/* Updated: 2020/10/06 17:21:38 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,13 +22,13 @@ int eval_operation(int fds[2], t_env env, t_ast *ast)
left_fds[FD_WRITE] = FD_NONE;
right_fds[FD_READ] = FD_NONE;
right_fds[FD_WRITE] = fds[FD_WRITE];
- if ((status = eval(left_fds, env, ast->op.left, NULL, FD_NONE)) == EVAL_FATAL)
+ if ((status = eval(left_fds, env, ast->op.left)) == EVAL_FATAL)
return (EVAL_FATAL);
g_state.last_status = status;
if ((ast->op.sep == TAG_AND && status != 0) ||
(ast->op.sep == TAG_OR && status == 0))
return (status);
- return (eval(right_fds, env, ast->op.right, NULL, FD_NONE));
+ return (eval(right_fds, env, ast->op.right));
}
/* pid_t run_piped_child(t_env env, t_ast *ast, int copied, int closed) */
@@ -76,7 +76,7 @@ int eval_pipeline(int fds[2], t_env env, t_ast *ast)
close(p[FD_READ]);
fds[0] = FD_NONE;
fds[1] = FD_NONE;
- exit(eval(fds, env, curr->data, NULL, FD_NONE));
+ exit(eval(fds, env, curr->data));
}
close(p[FD_WRITE]);
if (prev_output != STDIN_FILENO)
@@ -97,7 +97,7 @@ int eval_pipeline(int fds[2], t_env env, t_ast *ast)
close(p[FD_WRITE]);
fds[0] = FD_NONE;
fds[1] = FD_NONE;
- exit(eval(fds, env, curr->data, NULL, FD_NONE));
+ exit(eval(fds, env, curr->data));
}
close(p[FD_READ]);
diff --git a/src/eval/parenthesis.c b/src/eval/parenthesis.c
index 83edf40..5a1fafa 100644
--- a/src/eval/parenthesis.c
+++ b/src/eval/parenthesis.c
@@ -6,7 +6,7 @@
/* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/09/13 20:38:29 by charles #+# #+# */
-/* Updated: 2020/09/15 20:09:13 by charles ### ########.fr */
+/* Updated: 2020/10/06 17:22:29 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,10 +14,10 @@
int wrapped_eval(t_fork_param_args *param)
{
- return (eval(param->fds, param->env, param->ast, NULL, FD_NONE));
+ return (eval(param->fds, param->env, param->ast));
}
-int eval_parenthesis(int fds[2], t_env env, t_ast *ast, pid_t *child_pid, int fd_to_close)
+int eval_parenthesis(int fds[2], t_env env, t_ast *ast)
{
int status;
t_fork_param_args param;
@@ -29,5 +29,5 @@ int eval_parenthesis(int fds[2], t_env env, t_ast *ast, pid_t *child_pid, int
param.fds[1] = fds[1];
param.env = env;
param.ast = ast->parent_ast;
- return (fork_wrap(fds, &param, (t_wrapped_func)wrapped_eval, child_pid, fd_to_close));
+ return (fork_wrap(fds, &param, (t_wrapped_func)wrapped_eval));
}
diff --git a/src/main.c b/src/main.c
index 7898547..29b81a6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,7 +6,7 @@
/* By: cacharle <cacharle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/28 11:45:44 by cacharle #+# #+# */
-/* Updated: 2020/10/06 16:14:07 by cacharle ### ########.fr */
+/* Updated: 2020/10/06 17:22:40 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -46,7 +46,7 @@ int execute(t_env env, char *input)
return (2);
fds[0] = FD_NONE;
fds[1] = FD_NONE;
- status = eval(fds, env, parser_out->ast, NULL, FD_NONE);
+ status = eval(fds, env, parser_out->ast);
/* ast_destroy(parser_out->ast); */
free(parser_out);
if (status == EVAL_FATAL)