From 84bf7575c27483bc65c7fe16c66d5b847e1282e6 Mon Sep 17 00:00:00 2001 From: wescande Date: Tue, 21 Mar 2017 02:15:59 +0100 Subject: [PATCH] rectif exec of script + rectif job_control+ MOTHER FUCKER YEAH --- 42sh/includes/exec.h | 4 ++-- 42sh/includes/minishell.h | 3 ++- 42sh/libft/src/get_next_line/get_next_line.c | 4 +--- 42sh/src/builtin/builtin_env.c | 10 +++++++++- 42sh/src/exec/exec_leaf.c | 6 ++++-- 42sh/src/exec/plaunch_brace.c | 4 ++-- 42sh/src/exec/plaunch_for.c | 4 ++-- 42sh/src/exec/plaunch_if.c | 5 +++-- 42sh/src/exec/plaunch_subshell.c | 3 ++- 42sh/src/exec/plaunch_until.c | 5 +++-- 42sh/src/exec/plaunch_while.c | 5 +++-- 42sh/src/exec/process_launch.c | 9 ++++++--- 42sh/src/glob/command_getoutput.c | 4 +++- 42sh/src/job_control/job_addprocess.c | 5 +++-- 42sh/src/main/data_init.c | 11 +++++++++-- 15 files changed, 54 insertions(+), 28 deletions(-) diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 6848b770..ca6c8860 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ -/* Updated: 2017/03/20 16:07:29 by wescande ### ########.fr */ +/* Updated: 2017/03/21 00:45:28 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -68,7 +68,7 @@ union u_process_data struct s_data_tree function; struct s_data_cond d_while; struct s_data_cond d_until; - struct s_data_cond d_if; + struct s_data_tree d_if; struct s_data_list d_for; struct s_data_list d_case; }; diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 4d65e4f3..c8766637 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ -/* Updated: 2017/03/20 10:35:37 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 02:11:31 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,6 +31,7 @@ # include "glob.h" # include "completion.h" # include "hash.h" +/* # define malloc(x) NULL */ #ifndef DEBUG # define DEBUG_MODE 0 diff --git a/42sh/libft/src/get_next_line/get_next_line.c b/42sh/libft/src/get_next_line/get_next_line.c index ba080bde..efe575cd 100644 --- a/42sh/libft/src/get_next_line/get_next_line.c +++ b/42sh/libft/src/get_next_line/get_next_line.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/15 13:12:06 by jhalford #+# #+# */ -/* Updated: 2017/03/20 21:18:01 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 01:17:07 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,7 +43,6 @@ static int ft_loop_read(int fd, char **line, char *save) while ((ret = read(fd, buf, BUFF_SIZE)) > 0) { - DG("boucle"); buf[ret] = 0; tmp = *line; if ((pos = ft_strchr(buf, '\n'))) @@ -59,7 +58,6 @@ static int ft_loop_read(int fd, char **line, char *save) } if (ret < 0) return (-1); - DG("GNL ret %i, fd=%i", **line ? 1 : 0, fd); return (**line ? 1 : 0); } diff --git a/42sh/src/builtin/builtin_env.c b/42sh/src/builtin/builtin_env.c index a30da58a..13a606a0 100644 --- a/42sh/src/builtin/builtin_env.c +++ b/42sh/src/builtin/builtin_env.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:14:20 by jhalford #+# #+# */ -/* Updated: 2017/03/20 20:51:55 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 01:14:41 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,10 +60,17 @@ static void env_replace(char ***custom_env, char *arg) static int env_treat_flag(char ***custom_env, char *const *arg[]) { + char *tmp; + while (*(++*arg)) { if (!ft_strcmp(**arg, "-i")) + { + tmp = ft_strjoin("PATH=", ft_getenv(*custom_env, "PATH")); ft_tabdel(custom_env); + *custom_env = ft_sstradd(NULL, tmp); + ft_strdel(&tmp); + } else if (!ft_strcmp(**arg, "-u")) { ++*arg; @@ -112,5 +119,6 @@ int builtin_env(const char *path, else pid = command_setoutput(argv, env); ft_tabdel(&env); + DG("%d", pid); return (builtin_return_status(pid, 0)); } diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 4468ef57..7c099811 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/20 20:41:34 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 01:21:04 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ t_process_map g_process_map[] = {PROCESS_BRACE, plaunch_brace, pprint_brace, pfree_subshell}, {PROCESS_WHILE, plaunch_while, pprint_while, pfree_cond}, {PROCESS_UNTIL, plaunch_until, pprint_until, pfree_cond}, - {PROCESS_IF, plaunch_if, pprint_if, pfree_cond}, + {PROCESS_IF, plaunch_if, pprint_if, pfree_subshell}, {PROCESS_FOR, plaunch_for, pprint_for, pfree_list}, {PROCESS_CASE, plaunch_case, pprint_case, pfree_list}, {PROCESS_EMPTY, plaunch_empty, NULL, NULL}, @@ -51,5 +51,7 @@ int exec_leaf(t_btree **ast) job->pgid = 0; } } + else +DG("WHY HERE?"); return (0); } diff --git a/42sh/src/exec/plaunch_brace.c b/42sh/src/exec/plaunch_brace.c index 0406b81e..69fe397d 100644 --- a/42sh/src/exec/plaunch_brace.c +++ b/42sh/src/exec/plaunch_brace.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 19:09:30 by jhalford #+# #+# */ -/* Updated: 2017/03/20 15:50:10 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 00:52:20 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,5 +15,5 @@ int plaunch_brace(t_process *p) { ft_exec(&p->data.brace.content); - return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); + return (0); } diff --git a/42sh/src/exec/plaunch_for.c b/42sh/src/exec/plaunch_for.c index 21e4f2bc..37772296 100644 --- a/42sh/src/exec/plaunch_for.c +++ b/42sh/src/exec/plaunch_for.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/15 00:49:20 by wescande #+# #+# */ -/* Updated: 2017/03/20 15:51:47 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 00:51:01 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,5 +36,5 @@ int plaunch_for(t_process *p) } temp = temp->next; } - return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); + return (0); } diff --git a/42sh/src/exec/plaunch_if.c b/42sh/src/exec/plaunch_if.c index 7b941d54..64044393 100644 --- a/42sh/src/exec/plaunch_if.c +++ b/42sh/src/exec/plaunch_if.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:26:53 by wescande #+# #+# */ -/* Updated: 2017/03/20 15:50:23 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 00:53:01 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,5 +16,6 @@ int plaunch_if(t_process *p) { data_singleton()->exec.attrs &= ~EXEC_IF_BRANCH; ft_exec(&p->data.d_if.content); - return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); + /* set_exitstatus(ft_atoi(ft_getenv(data_singleton()->env, "?"))); */ + return (0); } diff --git a/42sh/src/exec/plaunch_subshell.c b/42sh/src/exec/plaunch_subshell.c index 980a6232..69a0dc8a 100644 --- a/42sh/src/exec/plaunch_subshell.c +++ b/42sh/src/exec/plaunch_subshell.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:11:44 by wescande #+# #+# */ -/* Updated: 2017/03/20 15:50:25 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 00:52:42 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,4 +16,5 @@ int plaunch_subshell(t_process *p) { ft_exec(&p->data.subshell.content); exit(ft_atoi(ft_getenv(data_singleton()->env, "?"))); + return (0); } diff --git a/42sh/src/exec/plaunch_until.c b/42sh/src/exec/plaunch_until.c index d9e55135..1f420b3e 100644 --- a/42sh/src/exec/plaunch_until.c +++ b/42sh/src/exec/plaunch_until.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 22:04:42 by wescande #+# #+# */ -/* Updated: 2017/03/20 15:50:27 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 00:51:39 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,5 +24,6 @@ int plaunch_until(t_process *p) ret = ft_atoi(ft_getenv(data_singleton()->env, "?")); ft_exec(&p->data.d_until.condition); } - return (ret); + set_exitstatus(ret, 1); + return (0); } diff --git a/42sh/src/exec/plaunch_while.c b/42sh/src/exec/plaunch_while.c index 696059de..7869a9b7 100644 --- a/42sh/src/exec/plaunch_while.c +++ b/42sh/src/exec/plaunch_while.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:20:53 by wescande #+# #+# */ -/* Updated: 2017/03/20 15:50:29 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 00:48:16 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,5 +24,6 @@ int plaunch_while(t_process *p) ret = ft_atoi(ft_getenv(data_singleton()->env, "?")); ft_exec(&p->data.d_while.condition); } - return (ret); + set_exitstatus(ret, 1); + return (0); } diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 5ee8f200..95f7575d 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/20 20:52:03 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 01:26:45 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,8 +45,9 @@ static int do_the_fork_if_i_have_to(t_process *p) set_exitstatus(1, 1); return (0); } - set_exitstatus(p->map.launch(p), 1); - return (0); + return (p->map.launch(p)); + /* set_exitstatus(p->map.launch(p), 1); */ + /* return (0); */ } return (do_the_muther_forker(p)); } @@ -58,10 +59,12 @@ int process_launch(t_process *p) p->state = PROCESS_RUNNING; if (!(pid = do_the_fork_if_i_have_to(p))) { + DG("NO_FORK"); process_resetfds(p); process_free(p, 0); return (1); } + DG("FORK"); p->pid = pid; process_setgroup(p, pid); if (p->fdin != STDIN) diff --git a/42sh/src/glob/command_getoutput.c b/42sh/src/glob/command_getoutput.c index 471d0887..fdab45d0 100644 --- a/42sh/src/glob/command_getoutput.c +++ b/42sh/src/glob/command_getoutput.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 19:44:25 by wescande #+# #+# */ -/* Updated: 2017/03/20 18:16:20 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 01:21:38 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -63,6 +63,7 @@ static void execute_command(char *const av[], char **env) data->opts &= ~SH_INTERACTIVE; data->opts &= ~SH_OPTS_JOBC; command = manage_command(av); + DG("DO THE EXEC"); if (do_lexer_routine(&token, command)) { ft_dprintf(2, "{red}%s: syntax error in command substitution{eoc}\n", @@ -108,6 +109,7 @@ int command_setoutput(char *const av[], char **env) if (!av) return (0); + pid = 0; if (!(pid = do_the_muther_forker(NULL))) execute_command(av, env); return (pid); diff --git a/42sh/src/job_control/job_addprocess.c b/42sh/src/job_control/job_addprocess.c index 7a860da3..4822d25c 100644 --- a/42sh/src/job_control/job_addprocess.c +++ b/42sh/src/job_control/job_addprocess.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */ -/* Updated: 2017/03/20 20:51:59 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 01:30:10 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,8 @@ int job_addprocess(t_process *p) job_update_id(); job->id = jobc->current_id; job->pgid = SH_IS_INTERACTIVE(data_singleton()->opts) ? - p->pid : data_singleton()->jobc.shell_pgid; + /* p->pid : data_singleton()->jobc.shell_pgid; */ + p->pid : getpgid(0); ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job))); } job = jobc->first_job->content; diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 540471e5..272a3e04 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/03/20 09:57:11 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 01:50:24 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -64,8 +64,15 @@ int data_init(int ac, char **av) lexer_init(&data->lexer); parser_init(&data->parser); if ((term_name = ft_getenv(data->env, "TERM")) == NULL) - return (-1); + { + /* ft_dprintf(2, "{red}TERM not set\n{eoc}"); */ + term_name = "dumb"; + /* return (-1); */ + } if (tgetent(NULL, term_name) != 1) + { + ft_dprintf(2, "{red}TERM name is not a tty\n{eoc}"); return (-1); + } return (0); }