From eeae2232a5b1ca48810ae27386ebbc48edfaed58 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Fri, 24 Mar 2017 19:21:51 +0100 Subject: [PATCH] issue #177 --- 42sh/libft/src/sys/fd_replace.c | 3 ++- 42sh/src/exec/exec_leaf.c | 3 ++- 42sh/src/exec/exec_reset.c | 4 ++-- 42sh/src/exec/exec_var.c | 3 ++- 42sh/src/exec/process_launch.c | 5 +---- 42sh/src/exec/process_set.c | 6 +++--- 42sh/src/job_control/builtin_jobs.c | 5 ++++- 42sh/src/lexer/token_print.c | 5 ++++- 42sh/src/main/main.c | 7 +++++-- 42sh/src/main/shell_init.c | 7 ++----- 10 files changed, 27 insertions(+), 21 deletions(-) diff --git a/42sh/libft/src/sys/fd_replace.c b/42sh/libft/src/sys/fd_replace.c index 2e22e75e..aac43597 100644 --- a/42sh/libft/src/sys/fd_replace.c +++ b/42sh/libft/src/sys/fd_replace.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/21 16:32:26 by jhalford #+# #+# */ -/* Updated: 2017/03/22 17:22:55 by gwojda ### ########.fr */ +/* Updated: 2017/03/24 19:09:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ int fd_replace(int fd1, int fd2) { + DG("%i ----> %i", fd2, fd1); if (fd1 != fd2) return (dup2_close(fd1, fd2)); return (0); diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 9fb93b0e..5efe775d 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ -/* Updated: 2017/03/22 21:48:12 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 19:14:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,6 +43,7 @@ int exec_leaf(t_btree **ast) job_addprocess(&p); if (IS_PIPEEND(p)) { + DG("end of pipe"); if (JOB_IS_FG(job->attrs)) put_job_in_foreground(job, 0); else diff --git a/42sh/src/exec/exec_reset.c b/42sh/src/exec/exec_reset.c index f2fd8909..36ea6ae0 100644 --- a/42sh/src/exec/exec_reset.c +++ b/42sh/src/exec/exec_reset.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */ -/* Updated: 2017/03/24 18:23:49 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 18:41:14 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,7 +32,7 @@ int exec_reset(void) jobc = &data_singleton()->jobc; i = -1; while (++i < 10) - exec->fd_save[i] = fcntl(i, F_DUPFD, 10); + exec->fd_save[i] = fcntl(i, F_DUPFD_CLOEXEC, 10); exec->op_stack = NULL; exec->fdin = STDIN; exec->attrs = 0; diff --git a/42sh/src/exec/exec_var.c b/42sh/src/exec/exec_var.c index 4a227eb0..bab39c69 100644 --- a/42sh/src/exec/exec_var.c +++ b/42sh/src/exec/exec_var.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 11:12:05 by ariard #+# #+# */ -/* Updated: 2017/03/24 15:40:00 by ariard ### ########.fr */ +/* Updated: 2017/03/24 19:20:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,7 @@ int exec_var(t_btree **ast) char *equal; node = (*ast)->item; + pop(&data_singleton()->exec.op_stack); if (!(av = token_to_argv(node->data.cmd.token, 1))) return (0); var = av[0]; diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index eb01f277..ef7724fc 100644 --- a/42sh/src/exec/process_launch.c +++ b/42sh/src/exec/process_launch.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */ -/* Updated: 2017/03/24 18:22:16 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 19:21:07 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,10 +41,7 @@ int process_launch(t_process *p) if (process_redirect(p)) set_exitstatus(1, 1); else - { - exec_reset(); p->map.launch(p); - } shell_resetfds(); shell_resetsig(); process_free(p, 0); diff --git a/42sh/src/exec/process_set.c b/42sh/src/exec/process_set.c index de3b37f1..be240f3f 100644 --- a/42sh/src/exec/process_set.c +++ b/42sh/src/exec/process_set.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/22 18:26:37 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 19:19:34 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -68,7 +68,7 @@ int process_set(t_process *p, t_btree *ast) p->pid = 0; exec->fdin = fds[PIPE_READ]; if (ast) - p->redirs = ft_lstmap(((t_astnode *)ast->item)->data.cmd.redir, - &redir_copy); + p->redirs = ft_lstmap( + ((t_astnode *)ast->item)->data.cmd.redir, &redir_copy); return ((!ast) ? 0 : process_set_spec(p, ast)); } diff --git a/42sh/src/job_control/builtin_jobs.c b/42sh/src/job_control/builtin_jobs.c index 68ae3c86..a23b8184 100644 --- a/42sh/src/job_control/builtin_jobs.c +++ b/42sh/src/job_control/builtin_jobs.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */ -/* Updated: 2017/03/24 18:17:02 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 18:48:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,7 +67,10 @@ int builtin_jobs(const char *path, char *const av[], char *const envp[]) (void)path; (void)envp; if (!SH_HAS_JOBC(data_singleton()->opts)) + { + DG("no job control :("); return (SH_ERR("jobs: %s", SH_MSG_NOJOBC)); + } do_job_notification(); ft_bzero(&data, sizeof(t_data_template)); if (cliopts_get((char**)av, g_jobs_opts, &data)) diff --git a/42sh/src/lexer/token_print.c b/42sh/src/lexer/token_print.c index 6579d827..68c61e64 100644 --- a/42sh/src/lexer/token_print.c +++ b/42sh/src/lexer/token_print.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:39:01 by jhalford #+# #+# */ -/* Updated: 2017/03/24 17:24:09 by gwojda ### ########.fr */ +/* Updated: 2017/03/24 18:39:53 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,10 @@ void token_print(t_list *lst) while (lst) { if (lst->content) + { token = lst->content; + DG("token : %s data [%s]", read_state(token->type), token->data); + } lst = lst->next; } } diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index fd66ee2b..80e87820 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */ -/* Updated: 2017/03/24 18:25:10 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 18:55:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -46,13 +46,15 @@ static int handle_instruction(t_list **token, t_btree **ast) return (ret); if (do_lexer_routine(token, stream) > 0) continue ; + /* token_print(*token); */ + /* exit(1); */ if ((ret = do_parser_routine(token, ast)) == 1 && SH_NO_INTERACTIVE(data->opts)) return (ret); else if (ret > 0) break ; } - /* btree_print(3, *ast, ft_putast); */ + btree_print(3, *ast, ft_putast); /* exit(1); */ if (data->parser.state == SUCCESS && ft_exec(ast) < 0) exit(1); @@ -71,6 +73,7 @@ int main(int ac, char **av, char **env) t_btree *ast; g_argv = av; + DG("----------------------"); if (shell_init(ac, av, env) != 0) return (1); token = NULL; diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index d3a5dc78..45d9092c 100644 --- a/42sh/src/main/shell_init.c +++ b/42sh/src/main/shell_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ -/* Updated: 2017/03/24 17:11:20 by wescande ### ########.fr */ +/* Updated: 2017/03/24 18:57:17 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -87,10 +87,7 @@ int shell_init(int ac, char **av, char **env) if (data_init(ac, av, env) < 0) return (-1); if (cliopts_get(av, g_opts, data)) - { - ft_perror(NULL); - return (SH_ERR("usage: %s", SHELL_USAGE)); - } + return (ft_perror(NULL) && SH_ERR("usage: %s", SHELL_USAGE)); if (!isatty(STDIN) || *data->av_data) data->opts &= ~(SH_INTERACTIVE | SH_OPTS_JOBC); if ((data->fd = get_input_fd(data, NULL)) < 0)