This commit is contained in:
Antoine Riard 2017-03-24 19:44:39 +01:00
commit 916194163b
10 changed files with 22 additions and 26 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/21 16:32:26 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) int fd_replace(int fd1, int fd2)
{ {
DG("%i ----> %i", fd2, fd1);
if (fd1 != fd2) if (fd1 != fd2)
return (dup2_close(fd1, fd2)); return (dup2_close(fd1, fd2));
return (0); return (0);

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:47:30 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); job_addprocess(&p);
if (IS_PIPEEND(p)) if (IS_PIPEEND(p))
{ {
DG("end of pipe");
if (JOB_IS_FG(job->attrs)) if (JOB_IS_FG(job->attrs))
put_job_in_foreground(job, 0); put_job_in_foreground(job, 0);
else else

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 14:31:42 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; jobc = &data_singleton()->jobc;
i = -1; i = -1;
while (++i < 10) 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->op_stack = NULL;
exec->fdin = STDIN; exec->fdin = STDIN;
exec->attrs = 0; exec->attrs = 0;

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 11:12:05 by ariard #+# #+# */ /* Created: 2017/03/07 11:12:05 by ariard #+# #+# */
/* Updated: 2017/03/24 19:43:40 by ariard ### ########.fr */ /* Updated: 2017/03/24 19:44:30 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,6 +21,7 @@ int exec_var(t_btree **ast)
char *equal; char *equal;
node = (*ast)->item; node = (*ast)->item;
pop(&data_singleton()->exec.op_stack);
if (!(av = token_to_argv(node->data.cmd.token, 1))) if (!(av = token_to_argv(node->data.cmd.token, 1)))
return (0); return (0);
var = av[0]; var = av[0];

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/13 22:21:19 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)) if (process_redirect(p))
set_exitstatus(1, 1); set_exitstatus(1, 1);
else else
{
exec_reset();
p->map.launch(p); p->map.launch(p);
}
shell_resetfds(); shell_resetfds();
shell_resetsig(); shell_resetsig();
process_free(p, 0); process_free(p, 0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 14:54:45 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; p->pid = 0;
exec->fdin = fds[PIPE_READ]; exec->fdin = fds[PIPE_READ];
if (ast) if (ast)
p->redirs = ft_lstmap(((t_astnode *)ast->item)->data.cmd.redir, p->redirs = ft_lstmap(
&redir_copy); ((t_astnode *)ast->item)->data.cmd.redir, &redir_copy);
return ((!ast) ? 0 : process_set_spec(p, ast)); return ((!ast) ? 0 : process_set_spec(p, ast));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 17:43:01 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)path;
(void)envp; (void)envp;
if (!SH_HAS_JOBC(data_singleton()->opts)) if (!SH_HAS_JOBC(data_singleton()->opts))
{
DG("no job control :(");
return (SH_ERR("jobs: %s", SH_MSG_NOJOBC)); return (SH_ERR("jobs: %s", SH_MSG_NOJOBC));
}
do_job_notification(); do_job_notification();
ft_bzero(&data, sizeof(t_data_template)); ft_bzero(&data, sizeof(t_data_template));
if (cliopts_get((char**)av, g_jobs_opts, &data)) if (cliopts_get((char**)av, g_jobs_opts, &data))

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:39:01 by jhalford #+# #+# */ /* Created: 2016/11/28 14:39:01 by jhalford #+# #+# */
/* Updated: 2017/03/24 18:59:40 by ariard ### ########.fr */ /* Updated: 2017/03/24 19:23:12 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,9 +18,8 @@ void token_print(t_list *lst)
while (lst) while (lst)
{ {
if (lst->content) if ((token = lst->content))
token = lst->content; DG("token : %s data [%s]", read_state(token->type), token->data);
DG("%s", read_state(token->type));
lst = lst->next; lst = lst->next;
} }
} }

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */ /* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */
/* Updated: 2017/03/24 19:18:27 by ariard ### ########.fr */ /* Updated: 2017/03/24 19:23:34 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -46,15 +46,12 @@ static int handle_instruction(t_list **token, t_btree **ast)
return (ret); return (ret);
if (do_lexer_routine(token, stream) > 0) if (do_lexer_routine(token, stream) > 0)
continue ; continue ;
token_print(*token);
if ((ret = do_parser_routine(token, ast)) == 1 if ((ret = do_parser_routine(token, ast)) == 1
&& SH_NO_INTERACTIVE(data->opts)) && SH_NO_INTERACTIVE(data->opts))
return (ret); return (ret);
else if (ret > 0) else if (ret > 0)
break ; break ;
} }
/* btree_print(3, *ast, ft_putast); */
/* exit(1); */
if (data->parser.state == SUCCESS && ft_exec(ast) < 0) if (data->parser.state == SUCCESS && ft_exec(ast) < 0)
exit(1); exit(1);
else if (data->parser.state != SUCCESS) else if (data->parser.state != SUCCESS)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 17:23:59 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) if (data_init(ac, av, env) < 0)
return (-1); return (-1);
if (cliopts_get(av, g_opts, data)) if (cliopts_get(av, g_opts, data))
{ return (ft_perror(NULL) && SH_ERR("usage: %s", SHELL_USAGE));
ft_perror(NULL);
return (SH_ERR("usage: %s", SHELL_USAGE));
}
if (!isatty(STDIN) || *data->av_data) if (!isatty(STDIN) || *data->av_data)
data->opts &= ~(SH_INTERACTIVE | SH_OPTS_JOBC); data->opts &= ~(SH_INTERACTIVE | SH_OPTS_JOBC);
if ((data->fd = get_input_fd(data, NULL)) < 0) if ((data->fd = get_input_fd(data, NULL)) < 0)