From a9799debdab0888d9a2fc2191fbcfc2a44677d91 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Thu, 9 Mar 2017 15:24:00 +0100 Subject: [PATCH] issue #72, tried to reset file descriptors but still not working --- 42sh/Makefile | 1 + 42sh/includes/exec.h | 4 ++-- 42sh/src/builtin/builtin_cd.c | 2 +- 42sh/src/builtin/builtin_exit.c | 2 +- 42sh/src/exec/exec_leaf.c | 2 +- 42sh/src/exec/exec_reset.c | 8 ++++---- 42sh/src/exec/launch_builtin.c | 2 +- 42sh/src/exec/launch_file.c | 2 +- 42sh/src/exec/launch_process.c | 6 +++++- 42sh/src/exec/process_redirect.c | 2 +- 42sh/src/exec/process_reset.c | 2 +- 42sh/src/exec/process_resetfds.c | 24 ++++++++++++++++++++++++ 42sh/src/lexer/lexer_end.c | 2 +- 42sh/src/main/data_init.c | 6 ++---- 42sh/src/main/data_singleton.c | 2 +- 15 files changed, 47 insertions(+), 20 deletions(-) create mode 100644 42sh/src/exec/process_resetfds.c diff --git a/42sh/Makefile b/42sh/Makefile index 51d458d4..7fbe5d9f 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -91,6 +91,7 @@ exec/mark_process_status.c\ exec/node_copy.c\ exec/process_redirect.c\ exec/process_reset.c\ +exec/process_resetfds.c\ exec/process_setgroup.c\ exec/process_setsig.c\ exec/redir_copy.c\ diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 850f95d6..b1853896 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/08 19:15:13 by jhalford ### ########.fr */ +/* Updated: 2017/03/09 15:14:34 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -136,7 +136,7 @@ int exec_reset(void); int process_setgroup(t_process *p, pid_t pid); void process_setsig(void); void process_reset(t_process *p); -void process_resetfds(void); +void process_resetfds(t_process *p); int fd_is_valid(int fd, int flag); int bad_fd(int fd); diff --git a/42sh/src/builtin/builtin_cd.c b/42sh/src/builtin/builtin_cd.c index e3ace609..424c2c15 100644 --- a/42sh/src/builtin/builtin_cd.c +++ b/42sh/src/builtin/builtin_cd.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 11:57:53 by jhalford #+# #+# */ -/* Updated: 2017/03/03 20:12:45 by wescande ### ########.fr */ +/* Updated: 2017/03/09 14:58:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/builtin/builtin_exit.c b/42sh/src/builtin/builtin_exit.c index c5c32983..ea146188 100644 --- a/42sh/src/builtin/builtin_exit.c +++ b/42sh/src/builtin/builtin_exit.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:28:41 by jhalford #+# #+# */ -/* Updated: 2017/03/09 14:35:20 by jhalford ### ########.fr */ +/* Updated: 2017/03/09 15:14:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 3a242088..dc4cc9ab 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ -/* Updated: 2017/03/08 20:31:12 by jhalford ### ########.fr */ +/* Updated: 2017/03/09 15:21:14 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_reset.c b/42sh/src/exec/exec_reset.c index 2b925196..35c26757 100644 --- a/42sh/src/exec/exec_reset.c +++ b/42sh/src/exec/exec_reset.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */ -/* Updated: 2017/03/08 14:45:10 by jhalford ### ########.fr */ +/* Updated: 2017/03/09 15:22:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,9 +17,9 @@ int exec_reset(void) t_exec *exec; exec = &data_singleton()->exec; - exec->fd_save[0] = fcntl(0, F_DUPFD_CLOEXEC); - exec->fd_save[1] = fcntl(1, F_DUPFD_CLOEXEC); - exec->fd_save[2] = fcntl(2, F_DUPFD_CLOEXEC); + exec->fd_save[0] = fcntl(STDIN, F_DUPFD_CLOEXEC); + exec->fd_save[1] = fcntl(STDOUT, F_DUPFD_CLOEXEC); + exec->fd_save[2] = fcntl(STDERR, F_DUPFD_CLOEXEC); exec->op_stack = NULL; exec->fdin = STDIN; exec->attrs = 0; diff --git a/42sh/src/exec/launch_builtin.c b/42sh/src/exec/launch_builtin.c index 0c80ecbe..2cb48478 100644 --- a/42sh/src/exec/launch_builtin.c +++ b/42sh/src/exec/launch_builtin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */ -/* Updated: 2017/03/08 15:10:49 by wescande ### ########.fr */ +/* Updated: 2017/03/09 15:12:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/launch_file.c b/42sh/src/exec/launch_file.c index 249c49d1..ba26d9cc 100644 --- a/42sh/src/exec/launch_file.c +++ b/42sh/src/exec/launch_file.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */ -/* Updated: 2017/03/08 17:35:42 by jhalford ### ########.fr */ +/* Updated: 2017/03/09 15:10:15 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index 68a56e29..db17f981 100644 --- a/42sh/src/exec/launch_process.c +++ b/42sh/src/exec/launch_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */ -/* Updated: 2017/03/08 23:43:18 by ariard ### ########.fr */ +/* Updated: 2017/03/09 15:15:33 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,7 +37,11 @@ int launch_process(t_process *p) p->attrs &= ~PROCESS_STATE_MASK; p->attrs |= PROCESS_RUNNING; if (!(pid = (*g_launchmap[p->type].f)(p))) + { + DG("gonna reset fds"); + process_resetfds(p); return (-1); + } p->pid = pid; process_setgroup(p, pid); return (0); diff --git a/42sh/src/exec/process_redirect.c b/42sh/src/exec/process_redirect.c index c62cc0c8..66b43221 100644 --- a/42sh/src/exec/process_redirect.c +++ b/42sh/src/exec/process_redirect.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */ -/* Updated: 2017/03/07 21:04:38 by wescande ### ########.fr */ +/* Updated: 2017/03/09 15:14:43 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_reset.c b/42sh/src/exec/process_reset.c index 7e12b8b3..f10d78a3 100644 --- a/42sh/src/exec/process_reset.c +++ b/42sh/src/exec/process_reset.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/07 17:44:22 by jhalford #+# #+# */ -/* Updated: 2017/03/08 14:51:19 by jhalford ### ########.fr */ +/* Updated: 2017/03/09 15:09:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_resetfds.c b/42sh/src/exec/process_resetfds.c new file mode 100644 index 00000000..61cd1289 --- /dev/null +++ b/42sh/src/exec/process_resetfds.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* process_resetfds.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/09 14:51:23 by jhalford #+# #+# */ +/* Updated: 2017/03/09 15:20:41 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +void process_resetfds(t_process *p) +{ + t_exec *exec; + + (void)p; + exec = &data_singleton()->exec; + dup2(exec->fd_save[0], STDIN); + dup2(exec->fd_save[1], STDOUT); + dup2(exec->fd_save[2], STDERR); +} diff --git a/42sh/src/lexer/lexer_end.c b/42sh/src/lexer/lexer_end.c index ec6dd699..c06e06d4 100644 --- a/42sh/src/lexer/lexer_end.c +++ b/42sh/src/lexer/lexer_end.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 16:58:24 by jhalford #+# #+# */ -/* Updated: 2017/03/09 14:32:07 by jhalford ### ########.fr */ +/* Updated: 2017/03/09 14:53:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index a3026aca..908c9983 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/03/08 23:40:20 by ariard ### ########.fr */ +/* Updated: 2017/03/09 15:23:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,15 +21,13 @@ int data_init(void) data = data_singleton(); data->env = ft_sstrdup(environ); + data->local_var = NULL; set_exitstatus(0, 1); data->comp = NULL; data->opts = 0; exec_reset(); - data->jobc.first_job = NULL; data->jobc.current_id = 1; - - data->local_var = NULL; data->lst_func = NULL; data->heredoc_queue = NULL; if ((term_name = ft_getenv(data->env, "TERM")) == NULL) diff --git a/42sh/src/main/data_singleton.c b/42sh/src/main/data_singleton.c index 51fe1e00..b43daac3 100644 --- a/42sh/src/main/data_singleton.c +++ b/42sh/src/main/data_singleton.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/10 11:36:39 by jhalford #+# #+# */ -/* Updated: 2017/03/08 20:50:57 by ariard ### ########.fr */ +/* Updated: 2017/03/09 15:22:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */