From dd6817ff61d8e4901fdc130b9fe25fdf66a4563c Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Fri, 10 Mar 2017 12:58:34 +0100 Subject: [PATCH] issues #71 , #72 --- 42sh/includes/exec.h | 2 +- 42sh/src/exec/exec_leaf.c | 2 +- 42sh/src/exec/exec_reset.c | 17 ++++++--- 42sh/src/exec/launch_file.c | 2 +- 42sh/src/exec/launch_process.c | 2 +- 42sh/src/exec/launch_subshell.c | 2 +- 42sh/src/exec/mark_process_status.c | 40 ++++++++++------------ 42sh/src/exec/process_resetfds.c | 3 +- 42sh/src/job-control/do_job_notification.c | 2 +- 42sh/src/job-control/job_update_status.c | 4 +-- 42sh/src/main/data_init.c | 2 +- 42sh/src/main/main.c | 6 ++-- 42sh/src/main/shell_init.c | 3 +- 13 files changed, 47 insertions(+), 40 deletions(-) diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index b1853896..1505a765 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/09 15:14:34 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 12:11:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index dc4cc9ab..6aa92a4d 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/09 15:21:14 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 11:58:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_reset.c b/42sh/src/exec/exec_reset.c index 35c26757..51ef6d5d 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/09 15:22:51 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 12:55:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,9 +17,18 @@ int exec_reset(void) t_exec *exec; exec = &data_singleton()->exec; - 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->fd_save[0] = 1;//fcntl(STDIN, F_DUPFD_CLOEXEC); */ + /* exec->fd_save[1] = 1;//fcntl(STDOUT, F_DUPFD_CLOEXEC); */ + /* exec->fd_save[2] = 1;//fcntl(STDERR, F_DUPFD_CLOEXEC); */ + DG("check 0"); + if ((exec->fd_save[0] = fcntl(STDIN, F_DUPFD_CLOEXEC, 10)) == -1) + ft_dprintf(2, "{red}%s: internal fcntl error errno=%i %s{eoc}\n", SHELL_NAME, errno); + DG("check 1"); + if ((exec->fd_save[1] = fcntl(STDOUT, F_DUPFD_CLOEXEC, 10)) == -1) + ft_dprintf(2, "{red}%s: internal fcntl error errno=%i %s{eoc}\n", SHELL_NAME, errno); + if ((exec->fd_save[2] = fcntl(STDERR, F_DUPFD_CLOEXEC, 10)) == -1) + ft_dprintf(2, "{red}%s: internal fcntl error errno=%i %s{eoc}\n", SHELL_NAME, errno); + DG("saved [%i:%i:%i]", exec->fd_save[0], exec->fd_save[1], exec->fd_save[2]); exec->op_stack = NULL; exec->fdin = STDIN; exec->attrs = 0; diff --git a/42sh/src/exec/launch_file.c b/42sh/src/exec/launch_file.c index ba26d9cc..c9d29b79 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/09 15:10:15 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 12:12:59 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index db17f981..0fbbd7db 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/09 15:15:33 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 11:58:53 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/launch_subshell.c b/42sh/src/exec/launch_subshell.c index 1c2703b1..401aa434 100644 --- a/42sh/src/exec/launch_subshell.c +++ b/42sh/src/exec/launch_subshell.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:11:44 by wescande #+# #+# */ -/* Updated: 2017/03/08 15:08:04 by wescande ### ########.fr */ +/* Updated: 2017/03/10 11:51:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/mark_process_status.c b/42sh/src/exec/mark_process_status.c index c2e7dd97..57b21b34 100644 --- a/42sh/src/exec/mark_process_status.c +++ b/42sh/src/exec/mark_process_status.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ -/* Updated: 2017/03/08 18:49:49 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 12:51:05 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,30 +18,26 @@ int mark_process_status(pid_t pid, int status) t_process *p; DG("MPS pid=%i,s=%i", pid, status); - if (pid > 1) + if ((plist = job_getprocess(pid))) { - if ((plist = job_getprocess(pid))) + p = plist->content; + p->status = status; + DG("marking pid=[%i], name=[%s]", p->pid, p->data.cmd.av[0]); + if (WIFSTOPPED(status)) { - p = plist->content; - p->status = status; - DG("marking pid=[%i], name=[%s]", p->pid, p->data.cmd.av[0]); - if (WIFSTOPPED(status)) - { - p->attrs &= ~PROCESS_STATE_MASK; - p->attrs |= PROCESS_SUSPENDED; - } - else - { - p->attrs &= ~PROCESS_STATE_MASK; - p->attrs |= PROCESS_COMPLETED; - if (WIFSIGNALED(status)) - ft_printf("{mag}%d: Terminated by signal %d.\n{eoc}", - (int)pid, WTERMSIG(status)); - } - return (0); + p->attrs &= ~PROCESS_STATE_MASK; + p->attrs |= PROCESS_SUSPENDED; + } + else + { + p->attrs &= ~PROCESS_STATE_MASK; + p->attrs |= PROCESS_COMPLETED; + if (WIFSIGNALED(status)) + ft_printf("{mag}%d: Terminated by signal %d.\n{eoc}", + (int)pid, WTERMSIG(status)); } - ft_dprintf(2, "{red}No child process %d.\n", pid); return (0); } - return (-1); + ft_dprintf(2, "{red}No child process %d.\n", pid); + return (0); } diff --git a/42sh/src/exec/process_resetfds.c b/42sh/src/exec/process_resetfds.c index 61cd1289..127ccc10 100644 --- a/42sh/src/exec/process_resetfds.c +++ b/42sh/src/exec/process_resetfds.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/09 14:51:23 by jhalford #+# #+# */ -/* Updated: 2017/03/09 15:20:41 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 12:51:38 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,7 @@ void process_resetfds(t_process *p) (void)p; exec = &data_singleton()->exec; dup2(exec->fd_save[0], STDIN); + close(STDOUT); dup2(exec->fd_save[1], STDOUT); dup2(exec->fd_save[2], STDERR); } diff --git a/42sh/src/job-control/do_job_notification.c b/42sh/src/job-control/do_job_notification.c index 7d73c78a..2ea310d1 100644 --- a/42sh/src/job-control/do_job_notification.c +++ b/42sh/src/job-control/do_job_notification.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */ -/* Updated: 2017/03/08 20:35:18 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 12:40:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_update_status.c b/42sh/src/job-control/job_update_status.c index 1cae0944..575becb1 100644 --- a/42sh/src/job-control/job_update_status.c +++ b/42sh/src/job-control/job_update_status.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */ -/* Updated: 2017/03/08 20:35:12 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 12:41:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,5 +22,5 @@ void job_update_status(void) pid = waitpid(WAIT_ANY, &status, WUNTRACED | WNOHANG); DG("pid=[%d]", pid); } - while (!mark_process_status(pid, status)); + while (pid > 1 && !mark_process_status(pid, status)); } diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 908c9983..43442aa4 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/09 15:23:31 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 12:12:26 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 152691b1..e847841a 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/03/09 19:46:24 by ariard ### ########.fr */ +/* Updated: 2017/03/10 12:12:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -109,14 +109,14 @@ int main(int ac, char **av) int fd; setlocale(LC_ALL, ""); + DG("{inv}{bol}{gre}start of shell{eoc}"); shell_init(ac, av); if ((fd = get_input_fd()) < 0) { ft_printf("{red}%s: %s: No such file or directory\n{eoc}", SHELL_NAME, shell_get_avdata()); return (1); } - DG("{inv}{bol}{gre}start of shell{eoc} JOBC is %s, fd=[%i]", - SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF", fd); + DG("JOBC is %s, fd=[%i]", SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF", fd); while (handle_instruction(fd) == 0) { DG(); diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index 3a8ad244..177a7520 100644 --- a/42sh/src/main/shell_init.c +++ b/42sh/src/main/shell_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ -/* Updated: 2017/03/08 23:42:47 by ariard ### ########.fr */ +/* Updated: 2017/03/10 12:12:30 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,7 @@ void shell_init(int ac, char **av) int *shell_pgid; t_data *data; + DG("check"); data_init(); data = data_singleton(); data->argc = ac;