aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-10-07 12:27:26 +0200
committerCharles Cabergs <me@cacharle.xyz>2020-10-07 12:27:26 +0200
commit38630279546fbd3876fe2396f2afe4ca1bca9acc (patch)
tree3b08fa1524722334afbafc5155c96e4ee488862e
parent22ff0337dc23239c32cc738bb6f576b8a0b66f8b (diff)
downloadminishell-38630279546fbd3876fe2396f2afe4ca1bca9acc.tar.gz
minishell-38630279546fbd3876fe2396f2afe4ca1bca9acc.tar.bz2
minishell-38630279546fbd3876fe2396f2afe4ca1bca9acc.zip
Fixing parenthesis pipeline parsing, False negative unmatched quote on str
-rw-r--r--include/minishell.h11
m---------minishell_test0
-rw-r--r--src/builtin/cd.c2
-rw-r--r--src/builtin/export.c2
-rw-r--r--src/builtin/pwd.c2
-rw-r--r--src/eval/eval.c4
-rw-r--r--src/eval/operation.c25
-rw-r--r--src/lexer/trim.c4
-rw-r--r--src/parser/parser.c4
-rw-r--r--src/path.c2
-rw-r--r--src/preprocess.c8
-rw-r--r--src/setup.c4
12 files changed, 32 insertions, 36 deletions
diff --git a/include/minishell.h b/include/minishell.h
index 7d3f45c..e111119 100644
--- a/include/minishell.h
+++ b/include/minishell.h
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/26 15:33:51 by cacharle #+# #+# */
-/* Updated: 2020/09/16 17:20:42 by charles ### ########.fr */
+/* Updated: 2020/10/07 11:20:46 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -50,10 +50,19 @@
typedef t_ftvec* t_env;
+/*
+** \note Having a fixed size buffer for pids should be fine
+** as long as it's greater than the process hard limit
+*/
+
+# define STATE_PIDS_MAX_SIZE 4096
+
typedef struct
{
int last_status;
char *progname;
+ pid_t pids[STATE_PIDS_MAX_SIZE];
+ size_t pids_len;
} t_state;
extern t_state g_state;
diff --git a/minishell_test b/minishell_test
-Subproject 058491e35baa8bc73e14b48ceb765a3fe3c07e1
+Subproject 2a93ed69f7ee88c26b1edfb1f58a8f4d6d842bd
diff --git a/src/builtin/cd.c b/src/builtin/cd.c
index d95f6b7..b421e70 100644
--- a/src/builtin/cd.c
+++ b/src/builtin/cd.c
@@ -6,7 +6,7 @@
/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:10:20 by charles #+# #+# */
-/* Updated: 2020/09/28 10:54:15 by cacharle ### ########.fr */
+/* Updated: 2020/10/07 11:51:47 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
diff --git a/src/builtin/export.c b/src/builtin/export.c
index 96ec18c..c026755 100644
--- a/src/builtin/export.c
+++ b/src/builtin/export.c
@@ -6,7 +6,7 @@
/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:11:34 by charles #+# #+# */
-/* Updated: 2020/10/06 17:40:22 by cacharle ### ########.fr */
+/* Updated: 2020/10/07 11:12:33 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
diff --git a/src/builtin/pwd.c b/src/builtin/pwd.c
index 9e04fe9..1120c4e 100644
--- a/src/builtin/pwd.c
+++ b/src/builtin/pwd.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:10:40 by charles #+# #+# */
-/* Updated: 2020/09/15 12:09:32 by charles ### ########.fr */
+/* Updated: 2020/10/07 11:51:41 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
diff --git a/src/eval/eval.c b/src/eval/eval.c
index 2aed026..86d038e 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 17:21:54 by cacharle ### ########.fr */
+/* Updated: 2020/10/07 10:25:39 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,7 +17,7 @@ int st_replace(int oldfd, int newfd)
if (oldfd != FD_NONE)
{
dup2(oldfd, newfd);
- close(oldfd);
+ /* close(oldfd); */
}
return 0;
}
diff --git a/src/eval/operation.c b/src/eval/operation.c
index 8442533..156f6f5 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 17:31:43 by cacharle ### ########.fr */
+/* Updated: 2020/10/07 11:31:47 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -31,23 +31,6 @@ int eval_operation(int fds[2], t_env env, t_ast *ast)
return (eval(right_fds, env, ast->op.right));
}
-/* pid_t run_piped_child(t_env env, t_ast *ast, int copied, int closed) */
-/* { */
-/* pid_t pid; */
-/* int fds[2]; */
-/* */
-/* pid = fork(); */
-/* if (pid == 0) */
-/* { */
-/* dup2(copied, STDOUT_FILENO); */
-/* close(closed); */
-/* fds[0] = FD_NONE; */
-/* fds[1] = FD_NONE; */
-/* exit(eval(fds, env, ast, NULL, FD_NONE)); */
-/* } */
-/* return (pid); */
-/* } */
-
int eval_pipeline(int fds[2], t_env env, t_ast *ast)
{
t_ftlst *curr;
@@ -88,7 +71,6 @@ int eval_pipeline(int fds[2], t_env env, t_ast *ast)
int pid = fork();
if (pid == 0)
{
- /* dup2(p[FD_WRITE], STDOUT_FILENO); */
if (prev_output != STDIN_FILENO)
{
dup2(prev_output, STDIN_FILENO);
@@ -101,7 +83,10 @@ int eval_pipeline(int fds[2], t_env env, t_ast *ast)
}
close(p[FD_READ]);
+ int status = 0;
+
+ waitpid(pid, &pid, 0);
while (wait(NULL) != -1)
;
- return (0);
+ return (WEXITSTATUS(pid));
}
diff --git a/src/lexer/trim.c b/src/lexer/trim.c
index c8ed49e..0f3279b 100644
--- a/src/lexer/trim.c
+++ b/src/lexer/trim.c
@@ -6,7 +6,7 @@
/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/16 08:18:36 by nahaddac #+# #+# */
-/* Updated: 2020/10/06 16:14:54 by cacharle ### ########.fr */
+/* Updated: 2020/10/07 10:36:41 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -63,6 +63,8 @@ int del_quote(char *str)
}
}
}
+ else
+ return (0);
if (quote_counter % 2 == 1)
{
errorf("unexpected EOF while looking for matching `%c'\n", str[0]);
diff --git a/src/parser/parser.c b/src/parser/parser.c
index 99c9c8b..29fdece 100644
--- a/src/parser/parser.c
+++ b/src/parser/parser.c
@@ -6,7 +6,7 @@
/* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/17 18:09:04 by nahaddac #+# #+# */
-/* Updated: 2020/10/06 17:28:31 by cacharle ### ########.fr */
+/* Updated: 2020/10/07 10:31:26 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -96,7 +96,7 @@ t_parsed *parse_pipeline(t_tok_lst *input)
expr_ast = expr->ast;
free(expr);
t_ast *pipeline_ast;
- if (tail->ast->tag == AST_CMD)
+ if (tail->ast->tag == AST_CMD || tail->ast->tag == AST_PARENT)
{
pipeline_ast = ast_new(AST_PIPELINE);
if ((pipeline_ast->pipeline = ft_lstnew(tail->ast)) == NULL)
diff --git a/src/path.c b/src/path.c
index c8cf2d2..61c6cf7 100644
--- a/src/path.c
+++ b/src/path.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/27 15:51:01 by cacharle #+# #+# */
-/* Updated: 2020/10/06 17:26:05 by cacharle ### ########.fr */
+/* Updated: 2020/10/07 12:24:27 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
diff --git a/src/preprocess.c b/src/preprocess.c
index 22bf266..95f2b56 100644
--- a/src/preprocess.c
+++ b/src/preprocess.c
@@ -6,7 +6,7 @@
/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/03 08:58:49 by charles #+# #+# */
-/* Updated: 2020/10/06 16:30:30 by cacharle ### ########.fr */
+/* Updated: 2020/10/07 11:12:31 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -82,12 +82,10 @@ char **st_tokens_to_argv(t_tok_lst **tokens)
return (ret);
}
-
bool escape(char *str, enum e_tok tag)
{
- if (str[0] == '\\' // && str[1] != '\0' not on mac
- && (tag & TAG_STR
- || ((tag & TAG_STR_DOUBLE) && ft_strchr("\\\"$", str[1]))))
+ if (str[0] == '\\' && (tag & TAG_STR
+ || ((tag & TAG_STR_DOUBLE) && ft_strchr("\\\"$", str[1]))))
{
ft_memmove(str, str + 1, ft_strlen(str + 1) + 1);
return (true);
diff --git a/src/setup.c b/src/setup.c
index 34b9d2c..e069dba 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -6,7 +6,7 @@
/* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/09/16 15:46:09 by charles #+# #+# */
-/* Updated: 2020/10/06 17:36:40 by cacharle ### ########.fr */
+/* Updated: 2020/10/07 11:21:14 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -79,5 +79,7 @@ bool setup(char *first_arg, t_env env)
signal(SIGQUIT, signal_sigquit);
signal(SIGTERM, signal_sigterm);
setup_progname(first_arg);
+ ft_bzero(g_state.pids, STATE_PIDS_MAX_SIZE);
+ g_state.pids_len = 0;
return (setup_env(env) || setup_shlvl(env));
}