brace groups and subshell launching re-design
This commit is contained in:
parent
1c6c22bbbd
commit
271748861e
15 changed files with 70 additions and 65 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 22:36:52 by jhalford ### ########.fr */
|
/* Updated: 2017/03/13 23:02:23 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -66,7 +66,7 @@ struct s_data_list
|
||||||
t_btree *content;
|
t_btree *content;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct s_data_subshell
|
struct s_data_tree
|
||||||
{
|
{
|
||||||
t_btree *content;
|
t_btree *content;
|
||||||
};
|
};
|
||||||
|
|
@ -74,9 +74,9 @@ struct s_data_subshell
|
||||||
union u_process_data
|
union u_process_data
|
||||||
{
|
{
|
||||||
struct s_data_cmd cmd;
|
struct s_data_cmd cmd;
|
||||||
struct s_data_subshell subshell;
|
struct s_data_tree subshell;
|
||||||
struct s_data_subshell brace;
|
struct s_data_tree brace;
|
||||||
struct s_data_subshell function;
|
struct s_data_tree function;
|
||||||
struct s_data_cond d_while;
|
struct s_data_cond d_while;
|
||||||
struct s_data_cond d_until;
|
struct s_data_cond d_until;
|
||||||
struct s_data_cond d_if;
|
struct s_data_cond d_if;
|
||||||
|
|
@ -133,9 +133,6 @@ struct s_exec
|
||||||
int control_count;
|
int control_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* extern t_itof g_redirmap[]; */
|
|
||||||
/* extern t_itof g_execmap[]; */
|
|
||||||
|
|
||||||
int exec_reset(void);
|
int exec_reset(void);
|
||||||
int process_setgroup(t_process *p, pid_t pid);
|
int process_setgroup(t_process *p, pid_t pid);
|
||||||
void process_setsig(void);
|
void process_setsig(void);
|
||||||
|
|
@ -164,7 +161,7 @@ void redir_free(void *data, size_t content_size);
|
||||||
|
|
||||||
char **token_to_argv(t_ld *ld, int do_match);
|
char **token_to_argv(t_ld *ld, int do_match);
|
||||||
|
|
||||||
int add_new_job(t_job *job);
|
/* int add_new_job(t_job *job); */
|
||||||
|
|
||||||
int error_badidentifier(char *name);
|
int error_badidentifier(char *name);
|
||||||
t_btree *is_function(t_process *p);
|
t_btree *is_function(t_process *p);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
|
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/07 19:42:54 by ariard ### ########.fr */
|
/* Updated: 2017/03/13 22:52:32 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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/13 22:37:51 by jhalford ### ########.fr */
|
/* Updated: 2017/03/13 23:56:53 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -35,11 +35,9 @@ int exec_leaf(t_btree **ast)
|
||||||
job = &data_singleton()->exec.job;
|
job = &data_singleton()->exec.job;
|
||||||
if (process_set(&p, *ast))
|
if (process_set(&p, *ast))
|
||||||
return (1);
|
return (1);
|
||||||
DG("p.type=%i", p.type);
|
|
||||||
p.map = g_process_map[p.type];
|
p.map = g_process_map[p.type];
|
||||||
if (!(process_launch(&p)))
|
if (!(process_launch(&p)))
|
||||||
{
|
{
|
||||||
DG("check");
|
|
||||||
DG("forked pid=[%i]", p.pid);
|
DG("forked pid=[%i]", p.pid);
|
||||||
job_addprocess(&p);
|
job_addprocess(&p);
|
||||||
/* DG("[IS_BG->%i]", JOB_IS_BG(job->attrs)); */
|
/* DG("[IS_BG->%i]", JOB_IS_BG(job->attrs)); */
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 10:58:49 by ariard #+# #+# */
|
/* Created: 2017/03/07 10:58:49 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/07 16:00:24 by wescande ### ########.fr */
|
/* Updated: 2017/03/13 23:22:45 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,19 +6,45 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/13 19:09:30 by jhalford #+# #+# */
|
/* Created: 2017/03/13 19:09:30 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */
|
/* Updated: 2017/03/13 23:57:38 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
int plaunch_brace(t_process *p)
|
int plaunch_brace(t_process *p)
|
||||||
|
{
|
||||||
|
pid_t pid;
|
||||||
|
|
||||||
|
DG("plaunch_brace");
|
||||||
|
if (IS_PIPESINGLE(*p))
|
||||||
{
|
{
|
||||||
if (process_redirect(p))
|
if (process_redirect(p))
|
||||||
{
|
{
|
||||||
|
DG("BRACE_GROUP redirection failed");
|
||||||
set_exitstatus(1, 1);
|
set_exitstatus(1, 1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
ft_exec(&p->data.subshell.content);
|
ft_exec(&p->data.brace.content);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
pid = fork();
|
||||||
|
if (pid == 0)
|
||||||
|
{
|
||||||
|
DG("fork!");
|
||||||
|
data_singleton()->opts &= ~SH_INTERACTIVE;
|
||||||
|
/* data_singleton()->opts &= ~SH_OPTS_JOBC; */
|
||||||
|
if (process_redirect(p))
|
||||||
|
exit (1);
|
||||||
|
process_setgroup(p, 0);
|
||||||
|
process_setsig();
|
||||||
|
exec_reset();
|
||||||
|
ft_exec(&p->data.brace.content);
|
||||||
|
exit(ft_atoi(ft_getenv(data_singleton()->env, "?")));
|
||||||
|
}
|
||||||
|
else if (pid > 0)
|
||||||
|
return (pid);
|
||||||
|
else if (pid == -1)
|
||||||
|
ft_dprintf(2, "{red}%s: internal fork error{eoc}\n", SHELL_NAME);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */
|
/* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */
|
/* Updated: 2017/03/13 23:35:37 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -29,11 +29,12 @@ int plaunch_builtin(t_process *p)
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
{
|
{
|
||||||
process_setgroup(p, 0);
|
|
||||||
process_setsig();
|
|
||||||
if (process_redirect(p))
|
if (process_redirect(p))
|
||||||
exit (1);
|
exit (1);
|
||||||
|
process_setgroup(p, 0);
|
||||||
|
process_setsig();
|
||||||
exec_reset();///A FAIRE POUR LES BUILTIN OU PAS ? -> Q de William
|
exec_reset();///A FAIRE POUR LES BUILTIN OU PAS ? -> Q de William
|
||||||
|
// je pense ca ne change rien si on l'enleve car on excve apres
|
||||||
exit((*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env));
|
exit((*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env));
|
||||||
}
|
}
|
||||||
else if (pid > 0)
|
else if (pid > 0)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */
|
/* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 22:39:43 by jhalford ### ########.fr */
|
/* Updated: 2017/03/13 23:15:06 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -22,7 +22,7 @@ int plaunch_file(t_process *p)
|
||||||
{
|
{
|
||||||
/* data_singleton()->opts &= ~SH_INTERACTIVE; */
|
/* data_singleton()->opts &= ~SH_INTERACTIVE; */
|
||||||
/* data_singleton()->opts &= ~SH_OPTS_JOBC; */
|
/* data_singleton()->opts &= ~SH_OPTS_JOBC; */
|
||||||
/* DG("fork! [%s]", p->data.cmd.av[0]); */
|
DG("fork! [%s]", p->data.cmd.av[0]);
|
||||||
if (process_redirect(p))
|
if (process_redirect(p))
|
||||||
exit (1);
|
exit (1);
|
||||||
process_setgroup(p, 0);
|
process_setgroup(p, 0);
|
||||||
|
|
|
||||||
|
|
@ -6,31 +6,16 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/08 00:11:44 by wescande #+# #+# */
|
/* Created: 2017/03/08 00:11:44 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */
|
/* Updated: 2017/03/13 23:57:41 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
static int do_subshell(t_process *p)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ft_exec(&p->data.subshell.content);
|
|
||||||
ret = ft_atoi(ft_getenv(data_singleton()->env, "?"));
|
|
||||||
DG("CHECK, ret=[%i]", ret);
|
|
||||||
/* p = ft_lstlast(j->first_process)->content; */
|
|
||||||
/* ret = p->status */
|
|
||||||
/* DG("CHECK, ret=[%i]", ret); */
|
|
||||||
return (ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
int plaunch_subshell(t_process *p)
|
int plaunch_subshell(t_process *p)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
if (SH_IS_INTERACTIVE(data_singleton()->opts))
|
|
||||||
{
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -41,12 +26,10 @@ int plaunch_subshell(t_process *p)
|
||||||
process_setgroup(p, 0);
|
process_setgroup(p, 0);
|
||||||
process_setsig();
|
process_setsig();
|
||||||
exec_reset();
|
exec_reset();
|
||||||
exit(do_subshell(p));
|
ft_exec(&p->data.subshell.content);
|
||||||
|
exit(ft_atoi(ft_getenv(data_singleton()->env, "?")));
|
||||||
}
|
}
|
||||||
else if (pid > 0)
|
else if (pid > 0)
|
||||||
return (pid);
|
return (pid);
|
||||||
}
|
|
||||||
else
|
|
||||||
do_subshell(p);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */
|
/* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 22:35:24 by jhalford ### ########.fr */
|
/* Updated: 2017/03/13 23:10:42 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -40,10 +40,11 @@ int process_launch(t_process *p)
|
||||||
p->attrs |= PROCESS_RUNNING;
|
p->attrs |= PROCESS_RUNNING;
|
||||||
if (!(pid = (*p->map.launch)(p)))
|
if (!(pid = (*p->map.launch)(p)))
|
||||||
{
|
{
|
||||||
|
DG("launcher did not fork!");
|
||||||
process_resetfds(p);
|
process_resetfds(p);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
DG("launcher did not fork!");
|
DG("launcher forked!");
|
||||||
p->pid = pid;
|
p->pid = pid;
|
||||||
process_setgroup(p, pid);
|
process_setgroup(p, pid);
|
||||||
if (p->fdin != STDIN)
|
if (p->fdin != STDIN)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
|
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 22:39:48 by jhalford ### ########.fr */
|
/* Updated: 2017/03/13 22:40:00 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */
|
/* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 13:37:03 by jhalford ### ########.fr */
|
/* Updated: 2017/03/13 23:33:06 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 15:06:05 by wescande #+# #+# */
|
/* Created: 2017/03/07 15:06:05 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/13 20:31:21 by jhalford ### ########.fr */
|
/* Updated: 2017/03/13 22:52:43 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
|
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/11 18:14:33 by jhalford ### ########.fr */
|
/* Updated: 2017/03/13 23:33:03 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */
|
/* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 22:25:13 by jhalford ### ########.fr */
|
/* Updated: 2017/03/13 23:32:52 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -30,7 +30,6 @@
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
static t_btree *gen_t_btree(const char *command)
|
static t_btree *gen_t_btree(const char *command)
|
||||||
{
|
{
|
||||||
t_btree *ast;
|
t_btree *ast;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 19:55:20 by jhalford ### ########.fr */
|
/* Updated: 2017/03/13 23:08:17 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -62,7 +62,7 @@ int handle_instruction(int fd)
|
||||||
if (parser.state == ERROR)
|
if (parser.state == ERROR)
|
||||||
error_syntax(&token, &parser, &ast);
|
error_syntax(&token, &parser, &ast);
|
||||||
lexer.state = data_singleton()->heredoc_queue ? HEREDOC : 0;
|
lexer.state = data_singleton()->heredoc_queue ? HEREDOC : 0;
|
||||||
DG("lexer.state=%i", lexer.state);
|
/* DG("lexer.state=%i", lexer.state); */
|
||||||
if (lexer.state)
|
if (lexer.state)
|
||||||
continue;
|
continue;
|
||||||
else if (parser.state == SUCCESS)
|
else if (parser.state == SUCCESS)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue