From 230ff16f791d82d15cd5321cd7fa49b1dba82984 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Sat, 11 Mar 2017 18:33:09 +0100 Subject: [PATCH] yes | head fixed --- 42sh/includes/types.h | 2 +- 42sh/libft | 2 +- 42sh/src/exec/exec_leaf.c | 2 +- 42sh/src/exec/launch_builtin.c | 2 +- 42sh/src/exec/launch_file.c | 12 ++++++------ 42sh/src/exec/launch_process.c | 5 +++-- 42sh/src/exec/launch_subshell.c | 8 ++++++-- 42sh/src/exec/launch_while.c | 2 +- 42sh/src/exec/mark_process_status.c | 14 ++++++++++++-- 42sh/src/exec/process_redirect.c | 7 ++++--- 42sh/src/exec/process_resetfds.c | 2 +- 42sh/src/exec/process_setgroup.c | 6 +----- 42sh/src/exec/redirect_greatand.c | 2 +- 42sh/src/exec/set_exitstatus.c | 2 +- 42sh/src/exec/set_process.c | 2 +- 42sh/src/job-control/job_addprocess.c | 4 +--- 42sh/src/job-control/put_job_in_foreground.c | 2 +- 42sh/src/line-editing/ft_prompt.c | 2 +- 18 files changed, 44 insertions(+), 34 deletions(-) diff --git a/42sh/includes/types.h b/42sh/includes/types.h index 72955d1d..1254a88f 100644 --- a/42sh/includes/types.h +++ b/42sh/includes/types.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */ -/* Updated: 2017/03/10 20:14:52 by ariard ### ########.fr */ +/* Updated: 2017/03/11 16:40:08 by jhalford ### ########.fr */ /* Updated: 2017/03/07 18:35:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft b/42sh/libft index b209bb1f..934ff3af 160000 --- a/42sh/libft +++ b/42sh/libft @@ -1 +1 @@ -Subproject commit b209bb1fb718a68256253d5ab5ff69a46a90d5d6 +Subproject commit 934ff3af934eaecf04575a0a7e7e1b76628ae53b diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 6244fe0d..10d7b78f 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/11 16:00:12 by jhalford ### ########.fr */ +/* Updated: 2017/03/11 18:32:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/launch_builtin.c b/42sh/src/exec/launch_builtin.c index 2cb48478..b16f0f64 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/09 15:12:48 by jhalford ### ########.fr */ +/* Updated: 2017/03/11 18:16:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/launch_file.c b/42sh/src/exec/launch_file.c index bc480476..977b944e 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/11 16:00:38 by jhalford ### ########.fr */ +/* Updated: 2017/03/11 18:16:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,6 +22,11 @@ int launch_file(t_process *p) /* data_singleton()->opts &= ~SH_INTERACTIVE; */ /* data_singleton()->opts &= ~SH_OPTS_JOBC; */ DG("fork! [%s]", p->data.cmd.av[0]); + process_setgroup(p, 0); + process_setsig(); + if (process_redirect(p)) + exit (1); + exec_reset(); if (!p->data.cmd.path) { ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]); @@ -42,11 +47,6 @@ int launch_file(t_process *p) ft_dprintf(2, "{red}%s: permission denied: %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]); exit(126); } - process_setgroup(p, 0); - process_setsig(); - if (process_redirect(p)) - exit (1); - exec_reset(); (*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env); ft_dprintf(2, "{red}%s: internal execve error on %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]); exit(42); diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index 2e2982e3..666620c4 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/11 15:49:36 by jhalford ### ########.fr */ +/* Updated: 2017/03/11 17:59:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,7 +44,8 @@ int launch_process(t_process *p) } p->pid = pid; process_setgroup(p, pid); - /* process_resetfds(p); */ + if (p->fdin != STDIN) + close(p->fdin); if (p->fdout != STDOUT) close(p->fdout); return (0); diff --git a/42sh/src/exec/launch_subshell.c b/42sh/src/exec/launch_subshell.c index 8f4cf431..1861e144 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/11 15:38:56 by jhalford ### ########.fr */ +/* Updated: 2017/03/11 18:09:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,12 @@ static int do_subshell(t_process *p) { + int ret; + ft_exec(&p->data.subshell.content); - return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); + ret = ft_atoi(ft_getenv(data_singleton()->env, "?")); + DG("CHECK, ret=[%i]", ret); + return (ret); } int launch_subshell(t_process *p) diff --git a/42sh/src/exec/launch_while.c b/42sh/src/exec/launch_while.c index d545b894..81f49a83 100644 --- a/42sh/src/exec/launch_while.c +++ b/42sh/src/exec/launch_while.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:20:53 by wescande #+# #+# */ -/* Updated: 2017/03/10 17:09:14 by jhalford ### ########.fr */ +/* Updated: 2017/03/11 17:45:18 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/mark_process_status.c b/42sh/src/exec/mark_process_status.c index 509b8ef4..02d74dc6 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/10 17:09:04 by jhalford ### ########.fr */ +/* Updated: 2017/03/11 18:16:23 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,17 @@ int mark_process_status(pid_t pid, int status) t_list *plist; t_process *p; - DG("MPS pid=%i,s=%i", pid, status); + if (WIFEXITED(status)) + DG("MPS pid=[%i] s=[%i] ec=[%i] (exited)", pid, status, + WEXITSTATUS(status)); + else if (WIFSIGNALED(status)) + DG("MPS pid=[%i] s=[%i] sig=[%i] (signaled)", pid, status, + WTERMSIG(status)); + else if (WIFSTOPPED(status)) + DG("MPS pid=[%i] s=[%i] (stopped)", pid, status); + else + DG("MPS pid=[%i] s=[%i] (unknown)", pid, status); + if ((plist = job_getprocess(pid))) { p = plist->content; diff --git a/42sh/src/exec/process_redirect.c b/42sh/src/exec/process_redirect.c index f92b46e6..d846c7cc 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/11 15:42:46 by jhalford ### ########.fr */ +/* Updated: 2017/03/11 16:40:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,8 +33,9 @@ int process_redirect(t_process *p) while (redirs) { redir = redirs->content; - /* DG("redir type :%s", read_state(redir->type)); */ - /* DG("redir word : %s", redir->word); */ + DG("redir.type [%i]", redir->type); + DG("redir.word [%s]", redir->word); + DG("redir.n [%i]", redir->n); if (redir->n > 9) return (bad_fd(redir->n)); i = 0; diff --git a/42sh/src/exec/process_resetfds.c b/42sh/src/exec/process_resetfds.c index 0d310a70..029c2d22 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/10 14:35:00 by jhalford ### ########.fr */ +/* Updated: 2017/03/11 17:58:14 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_setgroup.c b/42sh/src/exec/process_setgroup.c index 9463c38d..f23c2100 100644 --- a/42sh/src/exec/process_setgroup.c +++ b/42sh/src/exec/process_setgroup.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */ -/* Updated: 2017/03/11 16:05:08 by jhalford ### ########.fr */ +/* Updated: 2017/03/11 16:07:43 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,11 +20,7 @@ int process_setgroup(t_process *p, pid_t pid) (void)p; data = data_singleton(); - /* if (!SH_HAS_JOBC(data->opts)) */ - /* return (0); */ j = &data->exec.job; - /* if (!j->pgid) */ - /* j->pgid = getpid(); */ DG("setpgid(%i, %i)", pid, j->pgid); if (setpgid(pid, j->pgid) == -1) ft_dprintf(2, "{red}%s: internal setpgid() error{eoc}\n", SHELL_NAME); diff --git a/42sh/src/exec/redirect_greatand.c b/42sh/src/exec/redirect_greatand.c index 26c8302c..8be9aecd 100644 --- a/42sh/src/exec/redirect_greatand.c +++ b/42sh/src/exec/redirect_greatand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:12:31 by jhalford #+# #+# */ -/* Updated: 2017/03/10 14:31:24 by jhalford ### ########.fr */ +/* Updated: 2017/03/11 17:32:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/set_exitstatus.c b/42sh/src/exec/set_exitstatus.c index efbbba45..add7281f 100644 --- a/42sh/src/exec/set_exitstatus.c +++ b/42sh/src/exec/set_exitstatus.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */ -/* Updated: 2017/02/27 23:20:22 by ariard ### ########.fr */ +/* Updated: 2017/03/11 18:14:33 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/set_process.c b/42sh/src/exec/set_process.c index 541572fa..2be25490 100644 --- a/42sh/src/exec/set_process.c +++ b/42sh/src/exec/set_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/11 13:26:33 by jhalford ### ########.fr */ +/* Updated: 2017/03/11 17:49:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_addprocess.c b/42sh/src/job-control/job_addprocess.c index 1af05dad..255cfdb4 100644 --- a/42sh/src/job-control/job_addprocess.c +++ b/42sh/src/job-control/job_addprocess.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */ -/* Updated: 2017/03/11 16:05:22 by jhalford ### ########.fr */ +/* Updated: 2017/03/11 18:22:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,8 +32,6 @@ int job_addprocess(t_process *p) ft_lsteadd(&job->first_process, ft_lstnew(p, sizeof(*p))); /* DG("[BG:%i]", JOB_IS_BG(job->attrs)); */ if (JOB_IS_BG(job->attrs) && IS_PIPEEND(*p)) - { job_notify_new(job); - } return (0); } diff --git a/42sh/src/job-control/put_job_in_foreground.c b/42sh/src/job-control/put_job_in_foreground.c index 4bcbcdc3..b90d2c7a 100644 --- a/42sh/src/job-control/put_job_in_foreground.c +++ b/42sh/src/job-control/put_job_in_foreground.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */ -/* Updated: 2017/03/11 15:39:43 by jhalford ### ########.fr */ +/* Updated: 2017/03/11 18:22:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/ft_prompt.c b/42sh/src/line-editing/ft_prompt.c index 434c9f1e..06967004 100644 --- a/42sh/src/line-editing/ft_prompt.c +++ b/42sh/src/line-editing/ft_prompt.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */ -/* Updated: 2017/03/08 23:47:11 by ariard ### ########.fr */ +/* Updated: 2017/03/11 16:14:18 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */