From 4f7b69b2832d3bed9ff2a229b31ed2d12c03e482 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Sun, 12 Mar 2017 15:29:35 +0100 Subject: [PATCH 1/5] ca segfault avec cette ligne --- 42sh/libft | 2 +- 42sh/src/main/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/42sh/libft b/42sh/libft index b209bb1f..69084091 160000 --- a/42sh/libft +++ b/42sh/libft @@ -1 +1 @@ -Subproject commit b209bb1fb718a68256253d5ab5ff69a46a90d5d6 +Subproject commit 690840914077a838e13238356db33e35127baa7d diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index a5fb2b2e..c3c3b81b 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -70,7 +70,7 @@ int handle_instruction(int fd) return (error_syntax(&token, &parser, &ast)); } } - ft_show_heredoc_data(&ast); + /* ft_show_heredoc_data(&ast); */ btree_print(STDBUG, ast, &ft_putast); if (ft_exec(&ast)) return (1); From 9061e43bea624b5e5343c3424a226c4f725d8b79 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Sun, 12 Mar 2017 22:01:25 +0100 Subject: [PATCH 2/5] new process group handling is goooooood --- 42sh/includes/lexer.h | 2 +- 42sh/src/exec/exec_leaf.c | 4 ++-- 42sh/src/exec/launch_file.c | 2 +- 42sh/src/exec/launch_process.c | 2 -- 42sh/src/exec/launch_subshell.c | 5 ++++- 42sh/src/exec/mark_process_status.c | 2 +- 42sh/src/exec/process_setgroup.c | 5 ++++- 42sh/src/exec/process_setsig.c | 2 ++ 42sh/src/job-control/job_addprocess.c | 4 ++-- 42sh/src/job-control/job_remove.c | 1 + 42sh/src/job-control/put_job_in_foreground.c | 9 ++++----- 42sh/src/main/main.c | 1 - 12 files changed, 22 insertions(+), 17 deletions(-) diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 7c5e0999..618939db 100644 --- a/42sh/includes/lexer.h +++ b/42sh/includes/lexer.h @@ -23,7 +23,7 @@ | TK_DO | TK_IF | TK_FI | TK_THEN | TK_ELIF | TK_ELSE) enum e_lexstate { - DEFAULT, + DEFAULT, //#define DEFAULT 0 PAREN, HEREDOC, NEWLINE, diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 10d7b78f..c367c141 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -22,9 +22,9 @@ int exec_leaf(t_btree **ast) return (1); if (!(launch_process(&p))) { - DG("forked pid=[%i], name=[%s]", p.pid, p.data.cmd.av[0]); + /* DG("forked pid=[%i], name=[%s]", p.pid, p.data.cmd.av[0]); */ job_addprocess(&p); - DG("[IS_BG->%i]", JOB_IS_BG(job->attrs)); + /* DG("[IS_BG->%i]", JOB_IS_BG(job->attrs)); */ if (IS_PIPEEND(p)) { if (JOB_IS_FG(job->attrs)) diff --git a/42sh/src/exec/launch_file.c b/42sh/src/exec/launch_file.c index 977b944e..3a005fa9 100644 --- a/42sh/src/exec/launch_file.c +++ b/42sh/src/exec/launch_file.c @@ -21,7 +21,7 @@ int launch_file(t_process *p) { /* data_singleton()->opts &= ~SH_INTERACTIVE; */ /* data_singleton()->opts &= ~SH_OPTS_JOBC; */ - DG("fork! [%s]", p->data.cmd.av[0]); + /* DG("fork! [%s]", p->data.cmd.av[0]); */ process_setgroup(p, 0); process_setsig(); if (process_redirect(p)) diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index 666620c4..57bb96dd 100644 --- a/42sh/src/exec/launch_process.c +++ b/42sh/src/exec/launch_process.c @@ -29,7 +29,6 @@ int launch_process(t_process *p) { int pid; - DG("launchprocess"); if (p->type >= PROCESS_MAX) return (-1); if (!g_launchmap[p->type].f) @@ -38,7 +37,6 @@ int launch_process(t_process *p) p->attrs |= PROCESS_RUNNING; if (!(pid = (*g_launchmap[p->type].f)(p))) { - DG("gonna reset fds"); process_resetfds(p); return (1); } diff --git a/42sh/src/exec/launch_subshell.c b/42sh/src/exec/launch_subshell.c index 1861e144..cc7cd24d 100644 --- a/42sh/src/exec/launch_subshell.c +++ b/42sh/src/exec/launch_subshell.c @@ -14,11 +14,14 @@ static int do_subshell(t_process *p) { - int ret; + int ret; ft_exec(&p->data.subshell.content); ret = ft_atoi(ft_getenv(data_singleton()->env, "?")); DG("CHECK, ret=[%i]", ret); + /* p = ft_lstlast(j->first_process)->content; */ + /* ret = p->status */ + /* DG("CHECK, ret=[%i]", ret); */ return (ret); } diff --git a/42sh/src/exec/mark_process_status.c b/42sh/src/exec/mark_process_status.c index 02d74dc6..6a7eca78 100644 --- a/42sh/src/exec/mark_process_status.c +++ b/42sh/src/exec/mark_process_status.c @@ -32,7 +32,7 @@ int mark_process_status(pid_t pid, int status) { p = plist->content; p->status = status; - DG("marking pid=[%i], name=[%s]", p->pid, p->data.cmd.av[0]); + /* DG("found pid=[%i], name=[%s]", p->pid, p->data.cmd.av[0]); */ if (WIFSTOPPED(status)) { p->attrs &= ~PROCESS_STATE_MASK; diff --git a/42sh/src/exec/process_setgroup.c b/42sh/src/exec/process_setgroup.c index f23c2100..35b83760 100644 --- a/42sh/src/exec/process_setgroup.c +++ b/42sh/src/exec/process_setgroup.c @@ -21,13 +21,16 @@ int process_setgroup(t_process *p, pid_t pid) (void)p; data = data_singleton(); j = &data->exec.job; + if (!SH_IS_INTERACTIVE(data_singleton()->opts)) + return (0); DG("setpgid(%i, %i)", pid, j->pgid); if (setpgid(pid, j->pgid) == -1) ft_dprintf(2, "{red}%s: internal setpgid() error{eoc}\n", SHELL_NAME); if (pid == 0 && JOB_IS_FG(j->attrs)) { - DG("I'm taking the terminal !"); + DG("tcsetpgrp[%i]", j->pgid); tcsetpgrp(STDIN, j->pgid); + DG("after tcsetpgrp"); } return (0); } diff --git a/42sh/src/exec/process_setsig.c b/42sh/src/exec/process_setsig.c index 03c2ed46..96b44ad1 100644 --- a/42sh/src/exec/process_setsig.c +++ b/42sh/src/exec/process_setsig.c @@ -19,5 +19,7 @@ void process_setsig(void) signal(SIGTSTP, SIG_DFL); signal(SIGTTIN, SIG_DFL); signal(SIGTTOU, SIG_DFL); + /* signal(SIGTTIN, sigttin_handler); */ + /* signal(SIGTTOU, sigttou_handler); */ signal(SIGCHLD, SIG_DFL); } diff --git a/42sh/src/job-control/job_addprocess.c b/42sh/src/job-control/job_addprocess.c index 255cfdb4..f56a02e5 100644 --- a/42sh/src/job-control/job_addprocess.c +++ b/42sh/src/job-control/job_addprocess.c @@ -23,8 +23,8 @@ int job_addprocess(t_process *p) { job_update_id(); job->id = jobc->current_id; - /* job->pgid = SH_HAS_JOBC(data_singleton()->opts) ? p->pid : getpid(); */ - job->pgid = p->pid; + job->pgid = SH_IS_INTERACTIVE(data_singleton()->opts) ? p->pid : getpgid(0); + /* job->pgid = p->pid; */ ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job))); } DG("adding pid=[%i] to pgid=[%i]", p->pid, job->pgid); diff --git a/42sh/src/job-control/job_remove.c b/42sh/src/job-control/job_remove.c index 45f24e9f..fed549a5 100644 --- a/42sh/src/job-control/job_remove.c +++ b/42sh/src/job-control/job_remove.c @@ -23,6 +23,7 @@ void job_remove(int id) if (job_is_completed(id)) { p = ft_lstlast(j->first_process)->content; + /* DG("remove, status=%i", p->status); */ set_exitstatus(p->status, 0); if (id < data_singleton()->jobc.current_id) data_singleton()->jobc.current_id = id; diff --git a/42sh/src/job-control/put_job_in_foreground.c b/42sh/src/job-control/put_job_in_foreground.c index b90d2c7a..d2e9479b 100644 --- a/42sh/src/job-control/put_job_in_foreground.c +++ b/42sh/src/job-control/put_job_in_foreground.c @@ -17,9 +17,9 @@ int put_job_in_foreground(t_job *j, int cont) t_jobc *jobc; jobc = &data_singleton()->jobc; - DG("giving terminal to pgid->[%i]", j->pgid); - tcsetpgrp(STDIN, j->pgid); - + DG("tcsetpgrp[%i]", j->pgid); + if (SH_IS_INTERACTIVE(data_singleton()->opts)) + tcsetpgrp(STDIN, j->pgid); if (cont) { tcsetattr(STDIN, TCSADRAIN, &j->tmodes); @@ -28,8 +28,7 @@ int put_job_in_foreground(t_job *j, int cont) } job_wait(j->id); job_remove(j->id); - - if (SH_HAS_JOBC(data_singleton()->opts)) + if (SH_IS_INTERACTIVE(data_singleton()->opts)) { tcsetpgrp(STDIN, jobc->shell_pgid); tcgetattr(STDIN, &j->tmodes); diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index c3c3b81b..6635870a 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -124,7 +124,6 @@ int main(int ac, char **av) DG("JOBC is %s, fd=[%i]", SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF", fd); while (handle_instruction(fd) == 0) { - DG(); // lexer_clean; // parser_clean; ; From 51642beccd0505c1c2c0abd7645fddcfaff3da4d Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Sun, 12 Mar 2017 23:07:22 +0100 Subject: [PATCH 3/5] curly brace token only when followed by a ' ' space for #94 --- 42sh/src/lexer/lexer_curly_braces.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/42sh/src/lexer/lexer_curly_braces.c b/42sh/src/lexer/lexer_curly_braces.c index d6eee381..7ef584e5 100644 --- a/42sh/src/lexer/lexer_curly_braces.c +++ b/42sh/src/lexer/lexer_curly_braces.c @@ -19,7 +19,8 @@ int lexer_curly_braces(t_list **alst, t_lexer *lexer) token = (*alst)->content; if (token->type) lexer_lex(&(*alst)->next, lexer); - if (lexer->str[lexer->pos] == '{') + if (lexer->str[lexer->pos] == '{' + && lexer->str[lexer->pos + 1] == ' ') { token->type = TK_LBRACE; push(&lexer->stack, PAREN); From f74b323e8f1a5ce791a79c162fd704a5650b5815 Mon Sep 17 00:00:00 2001 From: william Date: Sun, 12 Mar 2017 23:32:16 +0100 Subject: [PATCH 4/5] rectif variable set but not used + #96 sur cd / --- 42sh/src/completion/c_printer.c | 4 ++-- 42sh/src/exec/process_redirect.c | 2 +- 42sh/src/glob/dir_glob.c | 2 +- 42sh/src/parser/add_condition.c | 4 ++-- 42sh/src/parser/add_redir_condition.c | 20 ++++++++++---------- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/42sh/src/completion/c_printer.c b/42sh/src/completion/c_printer.c index 57908b3a..050212e8 100644 --- a/42sh/src/completion/c_printer.c +++ b/42sh/src/completion/c_printer.c @@ -123,7 +123,7 @@ void c_printer(t_comp *c) t_clst *ptr; int loop; int max_line; - int offset; + //int offset; loop = c->c_line; @@ -133,7 +133,7 @@ void c_printer(t_comp *c) max_line = (c->c_line % (c->m_size - 1)); else max_line = c->m_size - 1; - offset = (c->m_size - 1) - max_line; +// offset = (c->m_size - 1) - max_line; while (loop && max_line) { c_printer_line(c, ptr, c->c_pline, 1); diff --git a/42sh/src/exec/process_redirect.c b/42sh/src/exec/process_redirect.c index 35214223..ddceb6af 100644 --- a/42sh/src/exec/process_redirect.c +++ b/42sh/src/exec/process_redirect.c @@ -34,7 +34,7 @@ int process_redirect(t_process *p) { redir = redirs->content; DG("redirs content : %p", redirs->content); - DG("redir.type [%i]", redir->type); +// DG("redir.type [%li]", redir->type); DG("redir.word [%s]", redir->word); DG("redir.n [%i]", redir->n); if (redir->n > 9) diff --git a/42sh/src/glob/dir_glob.c b/42sh/src/glob/dir_glob.c index 18401efe..895d6d08 100644 --- a/42sh/src/glob/dir_glob.c +++ b/42sh/src/glob/dir_glob.c @@ -58,7 +58,7 @@ int dir_research(t_glob *gl, char *p, ft_ld_pushfront(&gl->match_tmp, ft_strjoin(p + gl->cur_dir * 2 * (p[0] == '.' && p[1] == '/'), "/")); else - ft_ld_pushfront(&gl->match_tmp, ft_strdup("")); + ft_ld_pushfront(&gl->match_tmp, ft_strdup(CH(gl->m_pat)[0])); return (0); } if ((ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.') && is_directory(p)) diff --git a/42sh/src/parser/add_condition.c b/42sh/src/parser/add_condition.c index 2825ace2..426d3572 100644 --- a/42sh/src/parser/add_condition.c +++ b/42sh/src/parser/add_condition.c @@ -15,10 +15,10 @@ int iscondition(t_btree **ast, t_list **lst) { t_astnode *node; - t_token *token; +// t_token *token; node = NULL; - token = (*lst)->content; +// token = (*lst)->content; if (*ast) { node = (*ast)->item; diff --git a/42sh/src/parser/add_redir_condition.c b/42sh/src/parser/add_redir_condition.c index bf1a1ed4..1269cda0 100644 --- a/42sh/src/parser/add_redir_condition.c +++ b/42sh/src/parser/add_redir_condition.c @@ -12,12 +12,12 @@ #include "minishell.h" -static int isdir_sep_condition(t_btree **ast, t_list **lst) +static int isdir_sep_condition(t_btree **ast)//, t_list **lst) { - t_token *token; +// t_token *token; t_astnode *node; - token = (*lst)->content; +// token = (*lst)->content; if (*ast) { node = (*ast)->item; @@ -27,12 +27,12 @@ static int isdir_sep_condition(t_btree **ast, t_list **lst) return (0); } -static int isdir_word_condition(t_btree **ast, t_list **lst) +static int isdir_word_condition(t_btree **ast)//, t_list **lst) { - t_token *token; +// t_token *token; t_astnode *node; - token = (*lst)->content; +// token = (*lst)->content; if (*ast) { node = (*ast)->item; @@ -45,19 +45,19 @@ static int isdir_word_condition(t_btree **ast, t_list **lst) int isdir_condition(t_btree **ast, t_list **lst) { t_token *token; - t_astnode *node; +// t_astnode *node; token = (*lst)->content; if (*ast) { - node = (*ast)->item; +// node = (*ast)->item; if ((token->type == TK_LESS || token->type == TK_GREAT || token->type == TK_GREATAND || token->type == TK_LESSAND || token->type == TK_DLESS || token->type == TK_DGREAT) - && isdir_sep_condition(&(*ast)->left, lst) == 1) + && isdir_sep_condition(&(*ast)->left) == 1) return (1); if (token->type == TK_WORD - && isdir_word_condition(&(*ast)->left, lst) == 1) + && isdir_word_condition(&(*ast)->left) == 1) return (1); } return (0); From 8aa91c93b57653fca685c2b920263ec3f9034157 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 13 Mar 2017 00:03:48 +0100 Subject: [PATCH 5/5] rollback on last commit for #94 --- 42sh/src/lexer/lexer_curly_braces.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/42sh/src/lexer/lexer_curly_braces.c b/42sh/src/lexer/lexer_curly_braces.c index 7ef584e5..d6eee381 100644 --- a/42sh/src/lexer/lexer_curly_braces.c +++ b/42sh/src/lexer/lexer_curly_braces.c @@ -19,8 +19,7 @@ int lexer_curly_braces(t_list **alst, t_lexer *lexer) token = (*alst)->content; if (token->type) lexer_lex(&(*alst)->next, lexer); - if (lexer->str[lexer->pos] == '{' - && lexer->str[lexer->pos + 1] == ' ') + if (lexer->str[lexer->pos] == '{') { token->type = TK_LBRACE; push(&lexer->stack, PAREN);