From 714b0854be5a3c202e7fa3e8f577c6fc4523dcd9 Mon Sep 17 00:00:00 2001 From: wescande Date: Mon, 20 Mar 2017 11:37:57 +0100 Subject: [PATCH] catch fix on master --- 42sh/Makefile | 3 ++- 42sh/includes/exec.h | 3 ++- 42sh/includes/lexer.h | 3 ++- 42sh/src/builtin/builtin_env.c | 14 ++++++++----- 42sh/src/exec/process_launch.c | 33 +++++++++++++++++++------------ 42sh/src/glob/command_getoutput.c | 18 ++++++++++++++++- 6 files changed, 52 insertions(+), 22 deletions(-) diff --git a/42sh/Makefile b/42sh/Makefile index 7d58c40b..beb66d8e 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,7 +6,7 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/19 15:14:11 by gwojda ### ########.fr # +# Updated: 2017/03/20 11:37:21 by wescande ### ########.fr # # # # **************************************************************************** # @@ -302,6 +302,7 @@ NB = $(words $(SRC_BASE)) INDEX = 0 all : + @make -j -C $(LIBFT_DIR) @make $(NAME) $(NAME): $(LIBFT_LIB) $(OBJ_DIR) $(OBJS) diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 302c2a52..e055e34f 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 09:46:31 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 11:34:35 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -139,6 +139,7 @@ struct s_exec }; int exec_reset(void); +int do_the_muther_forker(t_process *p); int process_setgroup(t_process *p, pid_t pid); void process_setsig(void); void process_reset(t_process *p); diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index a0bc1ed1..2920d059 100644 --- a/42sh/includes/lexer.h +++ b/42sh/includes/lexer.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ -/* Updated: 2017/03/19 17:13:05 by wescande ### ########.fr */ +/* Updated: 2017/03/20 11:22:08 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -83,6 +83,7 @@ void token_print(t_list *lst); int reduce_parens(t_list **alst, char *str); int bquotes_expand(t_list **alst); char *command_getoutput(char *command, char *const av[], char **env, int pipe_mode); +int command_setoutput(char *command, char *const av[], char **env, int pipe_mode); int ft_is_delim(char c); int ft_is_delim_list(char c); diff --git a/42sh/src/builtin/builtin_env.c b/42sh/src/builtin/builtin_env.c index b6fc4c3b..61594a26 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/19 17:43:24 by wescande ### ########.fr */ +/* Updated: 2017/03/20 11:29:17 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,8 @@ static int env_usage(int arg_miss, char c) else if (c) ft_dprintf(2, "{red}env: illegal option -- %c{eoc}\n", c); ft_dprintf(2, "usage: env [-i] [-u name] ... [name=value] ... cmd\n"); - return (1); + set_exitstatus(1, 1); + return (0); } static void env_freeone(char **env, char *arg) @@ -89,15 +90,17 @@ static int env_treat_flag(char ***custom_env, char *const *arg[]) int builtin_env(const char *path, char *const argv[], char *const envp[]) { char **env; + pid_t pid; (void)path; + pid = 0; if (!argv || ft_strcmp(*argv, "env")) return (env_usage(0, 0)); env = ft_sstrdup((char **)envp); if (env_treat_flag(&env, &argv)) { ft_sstrfree(env); - return (1); + return (0); } if (!*argv) { @@ -106,7 +109,8 @@ int builtin_env(const char *path, char *const argv[], char *const envp[]) ft_putchar('\n'); } else - command_getoutput(NULL, argv, env, 0); + pid = command_setoutput(NULL, argv, env, 0); ft_tabdel(&env); - return (0); + set_exitstatus(0, 1); + return (pid); } diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 234fdd4d..a7ac2e26 100644 --- a/42sh/src/exec/process_launch.c +++ b/42sh/src/exec/process_launch.c @@ -6,27 +6,16 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */ -/* Updated: 2017/03/17 23:49:43 by wescande ### ########.fr */ +/* Updated: 2017/03/20 11:34:39 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" - int do_the_muther_forker(t_process *p) { pid_t pid; - if (IS_PIPESINGLE(*p) && p->type != PROCESS_FILE && p->type != PROCESS_SUBSHELL) - { - if (process_redirect(p)) - { - set_exitstatus(1, 1); - return (0); - } - set_exitstatus(p->map.launch(p), 1); - return (0); - } if ((pid = fork()) == -1) { ft_dprintf(3, "{red}%s: internal fork error{eoc}\n", SHELL_NAME); @@ -34,6 +23,8 @@ int do_the_muther_forker(t_process *p) } else if (pid) return (pid); + if (!p) + return (pid); DG("START OF FORK"); if (process_redirect(p)) exit (1); @@ -45,6 +36,22 @@ int do_the_muther_forker(t_process *p) exit(p->map.launch(p)); } +static int should_i_fork(t_process *p) +{ + if (IS_PIPESINGLE(*p) && p->type != PROCESS_FILE && p->type != PROCESS_SUBSHELL) + { + if (process_redirect(p)) + { + set_exitstatus(1, 1); + return (0); + } + return (p->map.launch(p)); + /* set_exitstatus(p->map.launch(p), 1); */ + /* return (0); */ + } + return (do_the_muther_forker(p)); +} + int process_launch(t_process *p) { pid_t pid; @@ -52,7 +59,7 @@ int process_launch(t_process *p) DG("p->type=%i", p->type); p->attrs &= ~PROCESS_STATE_MASK; p->attrs |= PROCESS_RUNNING; - if (!(pid = do_the_muther_forker(p))) + if (!(pid = should_i_fork(p))) { DG("launcher did not fork!"); process_resetfds(p); diff --git a/42sh/src/glob/command_getoutput.c b/42sh/src/glob/command_getoutput.c index 7a3f387f..53297129 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/19 17:42:45 by wescande ### ########.fr */ +/* Updated: 2017/03/20 11:36:03 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -102,3 +102,19 @@ char *command_getoutput(char *command, char *const av[], char **env, int pipe_ return (manage_output(fds)); return (NULL); } + +int command_setoutput(char *command, char *const av[], char **env, int pipe_mode) +{ + /* int ret; */ + int pid; +(void)pipe_mode; + if (!command && !av) + return (0); + if (!(pid = do_the_muther_forker(NULL))) + execute_command(command, av, env); + return (pid); + /* waitpid(pid, &ret, WUNTRACED); */ + /* if (pipe_mode) */ + /* return (manage_output(fds)); */ + /* return (NULL); */ +}