catch fix on master

This commit is contained in:
wescande 2017-03-20 11:37:57 +01:00
parent f482f78254
commit 714b0854be
6 changed files with 52 additions and 22 deletions

View file

@ -6,7 +6,7 @@
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# 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)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -6,27 +6,16 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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); */
}