From 57546c00229e1633c42c0e6cb7336f86dbeb5951 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Tue, 28 Mar 2017 20:31:02 +0200 Subject: [PATCH] protected control loops from background 'raping' --- 42sh/includes/exec.h | 3 +-- 42sh/src/exec/plaunch_for.c | 3 ++- 42sh/src/exec/plaunch_until.c | 3 ++- 42sh/src/exec/plaunch_while.c | 3 ++- 42sh/src/exec/process_launch.c | 5 ++--- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index ce602f64..05bb2fa7 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/27 15:46:34 by jhalford ### ########.fr */ +/* Updated: 2017/03/28 20:22:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -135,7 +135,6 @@ struct s_exec int fdin; t_list *op_stack; char **case_pattern; - int control_count; }; int exec_init(t_exec *exec); diff --git a/42sh/src/exec/plaunch_for.c b/42sh/src/exec/plaunch_for.c index c5f97f8a..f1f0ad27 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/24 14:52:00 by ariard ### ########.fr */ +/* Updated: 2017/03/28 20:29:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,6 +27,7 @@ int plaunch_for(t_process *p) return (SH_ERR(FORERR_0, var)); i = 0; av = token_to_argv(temp, 1); + data_singleton()->exec.job.attrs &= ~JOB_BG; while (av[++i]) { builtin_setenv("setenv", (char*[]){"local", var, av[i], 0}, diff --git a/42sh/src/exec/plaunch_until.c b/42sh/src/exec/plaunch_until.c index dbe8e2fb..17529fc1 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/22 19:22:56 by jhalford ### ########.fr */ +/* Updated: 2017/03/28 20:30:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,7 @@ int plaunch_until(t_process *p) int ret; ret = 0; + data_singleton()->exec.job.attrs &= ~JOB_BG; ft_exec(&p->data.d_until.condition); while (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0")) { diff --git a/42sh/src/exec/plaunch_while.c b/42sh/src/exec/plaunch_while.c index d4631982..9caaa1bd 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/24 22:43:37 by jhalford ### ########.fr */ +/* Updated: 2017/03/28 20:29:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,7 @@ int plaunch_while(t_process *p) int ret; ret = 0; + data_singleton()->exec.job.attrs &= ~JOB_BG; ft_exec(&p->data.d_while.condition); while (!(ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0"))) { diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 9ea29b09..e0ea77da 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/28 15:36:13 by wescande ### ########.fr */ +/* Updated: 2017/03/28 20:29:23 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,8 +39,7 @@ int process_fork(t_process *p) int process_launch(t_process *p) { p->state = PROCESS_RUNNING; - if (!IS_PIPESINGLE(*p) - || p->type == PROCESS_FILE + if (!IS_PIPESINGLE(*p) || p->type == PROCESS_FILE || p->type == PROCESS_SUBSHELL) { p->pid = process_fork(p);