From f65f23b10f0951a1f84c9b79ce61e086c1113561 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Thu, 16 Mar 2017 18:46:27 +0100 Subject: [PATCH] job control NORM --- 42sh/src/exec/exec_ampersand.c | 3 +- 42sh/src/exec/exec_leaf.c | 6 ++-- 42sh/src/exec/exec_reset.c | 4 +-- 42sh/src/exec/ft_exec.c | 2 +- 42sh/src/exec/mark_process_status.c | 14 +-------- 42sh/src/exec/plaunch_brace.c | 2 +- 42sh/src/exec/plaunch_while.c | 2 +- 42sh/src/exec/process_launch.c | 30 ++++---------------- 42sh/src/exec/process_set.c | 5 ++-- 42sh/src/job-control/builtin_bg.c | 2 +- 42sh/src/job-control/do_job_notification.c | 13 +++------ 42sh/src/job-control/job_addprocess.c | 8 ++---- 42sh/src/job-control/job_is_completed.c | 2 +- 42sh/src/job-control/job_is_stopped.c | 2 +- 42sh/src/job-control/job_remove.c | 10 ++++--- 42sh/src/job-control/job_update_status.c | 11 +++---- 42sh/src/job-control/job_wait.c | 16 +++++------ 42sh/src/job-control/pprint_case.c | 8 +++--- 42sh/src/job-control/pprint_cmd.c | 8 +++--- 42sh/src/job-control/pprint_for.c | 8 +++--- 42sh/src/job-control/pprint_function.c | 8 +++--- 42sh/src/job-control/pprint_if.c | 8 +++--- 42sh/src/job-control/pprint_subshell.c | 8 +++--- 42sh/src/job-control/pprint_until.c | 8 +++--- 42sh/src/job-control/pprint_while.c | 8 +++--- 42sh/src/job-control/process_format.c | 2 +- 42sh/src/job-control/process_free.c | 20 +------------ 42sh/src/job-control/put_job_in_foreground.c | 9 ++---- 42sh/src/job-control/sigtstp_handler.c | 7 +---- 42sh/src/main/data_init.c | 2 +- 42sh/src/main/main.c | 2 +- 42sh/src/main/shell_init.c | 8 +----- 32 files changed, 87 insertions(+), 159 deletions(-) diff --git a/42sh/src/exec/exec_ampersand.c b/42sh/src/exec/exec_ampersand.c index 04f60729..74a260b2 100644 --- a/42sh/src/exec/exec_ampersand.c +++ b/42sh/src/exec/exec_ampersand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 16:01:30 by jhalford #+# #+# */ -/* Updated: 2017/03/10 15:36:48 by jhalford ### ########.fr */ +/* Updated: 2017/03/16 18:37:56 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,6 @@ int exec_ampersand(t_btree **ast) return (exec_semi(ast)); exec = &data_singleton()->exec; push(&exec->op_stack, TK_AMP); - exec->job.attrs |= JOB_BG; ft_exec(&(*ast)->left); exec->attrs &= ~EXEC_AOL_MASK; exec->job.attrs &= ~JOB_BG; diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 698defbe..55852698 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/15 19:58:48 by ariard ### ########.fr */ +/* Updated: 2017/03/16 18:40:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,16 +40,14 @@ int exec_leaf(t_btree **ast) p.map = g_process_map[p.type]; if (!(process_launch(&p))) { - DG("forked pid=[%i]", p.pid); job_addprocess(&p); - /* DG("[IS_BG->%i]", JOB_IS_BG(job->attrs)); */ if (IS_PIPEEND(p)) { if (JOB_IS_FG(job->attrs)) put_job_in_foreground(job, 0); - DG("job->pgid RESET (end of pipe)"); job->pgid = 0; } + DG("check"); } return (0); } diff --git a/42sh/src/exec/exec_reset.c b/42sh/src/exec/exec_reset.c index 83ec518b..8b45d70e 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/11 14:19:41 by jhalford ### ########.fr */ +/* Updated: 2017/03/16 16:55:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,6 @@ int exec_reset(void) ft_dprintf(2, "{red}%s: internal fcntl STDOUT error errno=%i{eoc}\n", SHELL_NAME, errno); if ((exec->fd_save[2] = fcntl(STDERR, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF) ft_dprintf(2, "{red}%s: internal fcntl STDERR error errno=%i{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; @@ -33,6 +32,7 @@ int exec_reset(void) exec->job.pgid = 0; exec->job.attrs = 0; exec->job.first_process = NULL; + tcgetattr(STDIN, &exec->job.tmodes); jobc->first_job = NULL; jobc->current_id = 1; return (0); diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index 1f4a97ae..22ac506d 100644 --- a/42sh/src/exec/ft_exec.c +++ b/42sh/src/exec/ft_exec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */ -/* Updated: 2017/03/15 02:04:38 by ariard ### ########.fr */ +/* Updated: 2017/03/16 18:38:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/mark_process_status.c b/42sh/src/exec/mark_process_status.c index 6a7eca78..7341d593 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/11 18:16:23 by jhalford ### ########.fr */ +/* Updated: 2017/03/16 16:50:43 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,22 +17,10 @@ int mark_process_status(pid_t pid, int status) t_list *plist; t_process *p; - 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; p->status = status; - /* DG("found pid=[%i], name=[%s]", p->pid, p->data.cmd.av[0]); */ if (WIFSTOPPED(status)) { p->attrs &= ~PROCESS_STATE_MASK; diff --git a/42sh/src/exec/plaunch_brace.c b/42sh/src/exec/plaunch_brace.c index 0574cd60..069123e9 100644 --- a/42sh/src/exec/plaunch_brace.c +++ b/42sh/src/exec/plaunch_brace.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 19:09:30 by jhalford #+# #+# */ -/* Updated: 2017/03/15 18:13:05 by ariard ### ########.fr */ +/* Updated: 2017/03/16 18:42:45 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_while.c b/42sh/src/exec/plaunch_while.c index 2920c659..7f4ff6d5 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/15 00:55:31 by ariard ### ########.fr */ +/* Updated: 2017/03/16 18:44:00 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index ec81ba32..10ea8de8 100644 --- a/42sh/src/exec/process_launch.c +++ b/42sh/src/exec/process_launch.c @@ -6,28 +6,12 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */ -/* Updated: 2017/03/15 23:52:30 by wescande ### ########.fr */ +/* Updated: 2017/03/16 18:45:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -/* t_itof g_launchmap[] = */ -/* { */ -/* {PROCESS_FUNCTION, launch_function}, */ -/* {PROCESS_BUILTIN, launch_builtin}, */ -/* {PROCESS_FILE, launch_file}, */ -/* {PROCESS_SUBSHELL, launch_subshell}, */ -/* {PROCESS_BRACE, launch_brace}, */ -/* {PROCESS_WHILE, launch_while}, */ -/* {PROCESS_UNTIL, launch_until}, */ -/* {PROCESS_IF, launch_if}, */ -/* {PROCESS_FOR, launch_for}, */ -/* {PROCESS_CASE, launch_case}, */ -/* {PROCESS_EMPTY, launch_empty}, */ -/* }; */ - - int check_pipe(t_process *p) { pid_t pid; @@ -61,24 +45,20 @@ int check_pipe(t_process *p) int process_launch(t_process *p) { pid_t pid; - pid_t manage_pid; + /* pid_t manage_pid; */ DG("p->type=%i", p->type); - /* if (p->type >= PROCESS_MAX) */ - /* return (-1); */ - /* if (!g_launch_map[p->type].f) */ - /* return (-1); */ p->attrs &= ~PROCESS_STATE_MASK; p->attrs |= PROCESS_RUNNING; - if (!(manage_pid = check_pipe(p))) + /* if (!(manage_pid = check_pipe(p))) */ if (!(pid = (*p->map.launch)(p))) { DG("launcher did not fork!"); process_resetfds(p); return (1); } - if (manage_pid) - pid = manage_pid; + /* if (manage_pid) */ + /* pid = manage_pid; */ DG("launcher forked!"); p->pid = pid; process_setgroup(p, pid); diff --git a/42sh/src/exec/process_set.c b/42sh/src/exec/process_set.c index 74dcf000..7ee3a391 100644 --- a/42sh/src/exec/process_set.c +++ b/42sh/src/exec/process_set.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/15 18:20:38 by ariard ### ########.fr */ +/* Updated: 2017/03/16 18:40:59 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,7 +34,6 @@ static int process_set_spec(t_process *p, t_btree *ast) if (!ast) return (0); item = ast->item; - DG("process set spec"); while (g_setprocessmap[++i].id) if (item->type == g_setprocessmap[i].id) { @@ -62,6 +61,8 @@ int process_set(t_process *p, t_btree *ast) fds[PIPE_READ] = STDIN; if (op == TK_PIPE) pipe(fds); + else if (op == TK_AMP) + exec->job.attrs |= JOB_BG; p->fdin = exec->fdin; p->to_close = fds[PIPE_READ]; p->fdout = fds[PIPE_WRITE]; diff --git a/42sh/src/job-control/builtin_bg.c b/42sh/src/job-control/builtin_bg.c index 99eb37fc..269e9c2d 100644 --- a/42sh/src/job-control/builtin_bg.c +++ b/42sh/src/job-control/builtin_bg.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 16:54:18 by jhalford #+# #+# */ -/* Updated: 2017/01/20 00:09:28 by ariard ### ########.fr */ +/* Updated: 2017/03/16 16:49:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/do_job_notification.c b/42sh/src/job-control/do_job_notification.c index 4f7a079d..09ff6659 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/15 11:24:23 by gwojda ### ########.fr */ +/* Updated: 2017/03/16 18:35:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,21 +26,16 @@ int do_job_notification(void) while (jlist) { j = jlist->content; + jlist = jlist->next; if (job_is_completed(j->id) - || (job_is_stopped(j->id) && !(j->attrs & JOB_NOTIFIED))) + || (job_is_stopped(j->id) && !(j->attrs & JOB_NOTIFIED))) { ret = 1; job_notify_change(j->id); + j->attrs |= JOB_NOTIFIED; if (job_is_completed(j->id)) - { - jlist = jlist->next; job_remove(j->id); - continue ; - } - else - j->attrs |= JOB_NOTIFIED; } - jlist = jlist->next; } return (ret); } diff --git a/42sh/src/job-control/job_addprocess.c b/42sh/src/job-control/job_addprocess.c index f56a02e5..bac28023 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 18:22:29 by jhalford ### ########.fr */ +/* Updated: 2017/03/16 18:24:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,14 +23,12 @@ int job_addprocess(t_process *p) { job_update_id(); job->id = jobc->current_id; - job->pgid = SH_IS_INTERACTIVE(data_singleton()->opts) ? p->pid : getpgid(0); - /* job->pgid = p->pid; */ + job->pgid = SH_IS_INTERACTIVE(data_singleton()->opts) ? + p->pid : getpgid(0); ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job))); } - DG("adding pid=[%i] to pgid=[%i]", p->pid, job->pgid); job = jobc->first_job->content; 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/job_is_completed.c b/42sh/src/job-control/job_is_completed.c index c289614f..8a6712d4 100644 --- a/42sh/src/job-control/job_is_completed.c +++ b/42sh/src/job-control/job_is_completed.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 15:10:20 by jhalford #+# #+# */ -/* Updated: 2017/03/06 12:30:22 by wescande ### ########.fr */ +/* Updated: 2017/03/16 18:26:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_is_stopped.c b/42sh/src/job-control/job_is_stopped.c index 16c2bee8..2f71c258 100644 --- a/42sh/src/job-control/job_is_stopped.c +++ b/42sh/src/job-control/job_is_stopped.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 15:06:45 by jhalford #+# #+# */ -/* Updated: 2017/03/08 20:53:25 by jhalford ### ########.fr */ +/* Updated: 2017/03/16 18:26:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_remove.c b/42sh/src/job-control/job_remove.c index fed549a5..46b33738 100644 --- a/42sh/src/job-control/job_remove.c +++ b/42sh/src/job-control/job_remove.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */ -/* Updated: 2017/03/10 14:40:16 by jhalford ### ########.fr */ +/* Updated: 2017/03/16 18:29:43 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,15 +15,17 @@ void job_remove(int id) { t_jobc *jobc; - t_job *j; + t_job *j; + t_list *jlist; t_process *p; jobc = &data_singleton()->jobc; - j = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content; + if (!(jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id))) + return ; + j = jlist->content; if (job_is_completed(id)) { p = ft_lstlast(j->first_process)->content; - /* DG("remove, status=%i", p->status); */ set_exitstatus(p->status, 0); if (id < data_singleton()->jobc.current_id) data_singleton()->jobc.current_id = id; diff --git a/42sh/src/job-control/job_update_status.c b/42sh/src/job-control/job_update_status.c index 6432d8bc..7fca5ea1 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/14 23:43:00 by jhalford ### ########.fr */ +/* Updated: 2017/03/16 18:32:15 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,12 +17,13 @@ void job_update_status(void) int status; pid_t pid; - do + while (1) { if ((pid = waitpid(WAIT_ANY, &status, WUNTRACED | WNOHANG)) == -1 && errno != ECHILD) - ft_dprintf(2, "{red}%s: waitpid error errno=%i{eoc}\n", SHELL_NAME, errno); - DG("pid=[%d]", pid); + ft_dprintf(2, "{red}%s: waitpid error errno=%i{eoc}\n", + SHELL_NAME, errno); + if (pid <= 1 || mark_process_status(pid, status)) + break ; } - while (pid > 1 && !mark_process_status(pid, status)); } diff --git a/42sh/src/job-control/job_wait.c b/42sh/src/job-control/job_wait.c index 0cb2625a..f6c40b86 100644 --- a/42sh/src/job-control/job_wait.c +++ b/42sh/src/job-control/job_wait.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */ -/* Updated: 2017/03/15 18:12:30 by jhalford ### ########.fr */ +/* Updated: 2017/03/16 18:01:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,16 +21,16 @@ int job_wait(int id) jobc = &data_singleton()->jobc; j = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content; - DG("job wait id=[%i], pgid=[%i]", id, j->pgid); - do + while (1) { if ((pid = waitpid(-j->pgid, &status, WUNTRACED)) == -1 && errno != ECHILD) - ft_dprintf(2, "{red}%s: waitpid error errno=%i{eoc}\n", SHELL_NAME, errno); - DG("waitpid->[%d]", pid); + ft_dprintf(2, "{red}%s: waitpid error errno=%i{eoc}\n", + SHELL_NAME, errno); + if (pid <= 1 || mark_process_status(pid, status) + || job_is_stopped(id) + || job_is_completed(id)) + break ; } - while (pid > 1 && !mark_process_status(pid, status) - && !job_is_stopped(id) - && !job_is_completed(id)); return (0); } diff --git a/42sh/src/job-control/pprint_case.c b/42sh/src/job-control/pprint_case.c index adcd0b77..9ac8e632 100644 --- a/42sh/src/job-control/pprint_case.c +++ b/42sh/src/job-control/pprint_case.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pprint_case.c :+: :+: :+: */ +/* pprint_case.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: wescande +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/08 16:15:22 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:41:59 by jhalford ### ########.fr */ +/* Created: 2017/03/16 16:58:56 by jhalford #+# #+# */ +/* Updated: 2017/03/16 16:58:56 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/pprint_cmd.c b/42sh/src/job-control/pprint_cmd.c index 63e3809e..1e2b36af 100644 --- a/42sh/src/job-control/pprint_cmd.c +++ b/42sh/src/job-control/pprint_cmd.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pprint_cmd.c :+: :+: :+: */ +/* pprint_cmd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: wescande +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/08 16:17:16 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:23:18 by jhalford ### ########.fr */ +/* Created: 2017/03/16 16:55:30 by jhalford #+# #+# */ +/* Updated: 2017/03/16 16:55:34 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/pprint_for.c b/42sh/src/job-control/pprint_for.c index 555332d7..c81b18fd 100644 --- a/42sh/src/job-control/pprint_for.c +++ b/42sh/src/job-control/pprint_for.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pprint_for.c :+: :+: :+: */ +/* pprint_for.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: wescande +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/08 16:14:21 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:23:18 by jhalford ### ########.fr */ +/* Created: 2017/03/16 16:55:26 by jhalford #+# #+# */ +/* Updated: 2017/03/16 16:55:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/pprint_function.c b/42sh/src/job-control/pprint_function.c index 5f36f29b..755c7690 100644 --- a/42sh/src/job-control/pprint_function.c +++ b/42sh/src/job-control/pprint_function.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pprint_function.c :+: :+: :+: */ +/* pprint_function.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: wescande +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/08 16:12:18 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:23:18 by jhalford ### ########.fr */ +/* Created: 2017/03/16 16:53:36 by jhalford #+# #+# */ +/* Updated: 2017/03/16 16:53:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/pprint_if.c b/42sh/src/job-control/pprint_if.c index 300790fd..eb6dc692 100644 --- a/42sh/src/job-control/pprint_if.c +++ b/42sh/src/job-control/pprint_if.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pprint_if.c :+: :+: :+: */ +/* pprint_if.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: wescande +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/08 16:14:48 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:23:18 by jhalford ### ########.fr */ +/* Created: 2017/03/16 16:53:20 by jhalford #+# #+# */ +/* Updated: 2017/03/16 16:53:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/pprint_subshell.c b/42sh/src/job-control/pprint_subshell.c index 1adc2195..bd0737e1 100644 --- a/42sh/src/job-control/pprint_subshell.c +++ b/42sh/src/job-control/pprint_subshell.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pprint_subshell.c :+: :+: :+: */ +/* pprint_subshell.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: wescande +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/08 16:06:06 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:23:18 by jhalford ### ########.fr */ +/* Created: 2017/03/16 16:53:59 by jhalford #+# #+# */ +/* Updated: 2017/03/16 16:54:00 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/pprint_until.c b/42sh/src/job-control/pprint_until.c index f676268a..cf23fa29 100644 --- a/42sh/src/job-control/pprint_until.c +++ b/42sh/src/job-control/pprint_until.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pprint_until.c :+: :+: :+: */ +/* pprint_until.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: wescande +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/08 16:16:00 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:23:18 by jhalford ### ########.fr */ +/* Created: 2017/03/16 16:53:43 by jhalford #+# #+# */ +/* Updated: 2017/03/16 16:53:43 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/pprint_while.c b/42sh/src/job-control/pprint_while.c index 1db3885d..6039b9d2 100644 --- a/42sh/src/job-control/pprint_while.c +++ b/42sh/src/job-control/pprint_while.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pprint_while.c :+: :+: :+: */ +/* pprint_while.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: wescande +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/08 16:15:01 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:23:18 by jhalford ### ########.fr */ +/* Created: 2017/03/16 16:53:29 by jhalford #+# #+# */ +/* Updated: 2017/03/16 16:53:30 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/process_format.c b/42sh/src/job-control/process_format.c index 56db10f5..facaad6f 100644 --- a/42sh/src/job-control/process_format.c +++ b/42sh/src/job-control/process_format.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:05:55 by jhalford #+# #+# */ -/* Updated: 2017/03/16 16:39:58 by jhalford ### ########.fr */ +/* Updated: 2017/03/16 16:41:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/process_free.c b/42sh/src/job-control/process_free.c index f7c364f3..13e6aae7 100644 --- a/42sh/src/job-control/process_free.c +++ b/42sh/src/job-control/process_free.c @@ -6,36 +6,18 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ -/* Updated: 2017/03/14 20:19:22 by wescande ### ########.fr */ +/* Updated: 2017/03/16 16:53:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -/* t_itof g_freemap[] = */ -/* { */ -/* {PROCESS_FUNCTION, process_free_subshell}, */ -/* {PROCESS_BUILTIN, process_free_cmd}, */ -/* {PROCESS_FILE, process_free_cmd}, */ -/* {PROCESS_SUBSHELL, process_free_subshell}, */ -/* {PROCESS_WHILE, process_free_cond}, */ -/* {PROCESS_UNTIL, process_free_cond}, */ -/* {PROCESS_IF, process_free_cond}, */ -/* {PROCESS_FOR, process_free_list}, */ -/* {PROCESS_CASE, process_free_list}, */ -/* {PROCESS_EMPTY, NULL}, */ -/* }; */ - void process_free(void *content, size_t content_size) { t_process *p; p = content; (void)content_size; - /* if (p->type >= PROCESS_MAX) */ - /* return ; */ - /* if (g_freemap[p->type].f) */ - /* (g_freemap[p->type].f)(p); */ if (p->map.free) (p->map.free)(p); ft_lstdel(&p->redirs, redir_free); diff --git a/42sh/src/job-control/put_job_in_foreground.c b/42sh/src/job-control/put_job_in_foreground.c index c90577a4..74bafa70 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/15 15:51:30 by gwojda ### ########.fr */ +/* Updated: 2017/03/16 16:51:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,19 +17,15 @@ int put_job_in_foreground(t_job *j, int cont) t_jobc *jobc; jobc = &data_singleton()->jobc; - DG("tcsetpgrp[%i]", j->pgid); if (SH_IS_INTERACTIVE(data_singleton()->opts)) tcsetpgrp(STDIN, j->pgid); if (cont) { - // j->tmodes = pas initialisé ! - //tcsetattr(STDIN, TCSADRAIN, &j->tmodes); + tcsetattr(STDIN, TCSADRAIN, &j->tmodes); if (kill(-j->pgid, SIGCONT) < 0) DG("kill(SIGCONT) failed"); } - DG("check"); job_wait(j->id); - DG("check"); if (SH_IS_INTERACTIVE(data_singleton()->opts)) { tcsetpgrp(STDIN, jobc->shell_pgid); @@ -37,6 +33,5 @@ int put_job_in_foreground(t_job *j, int cont) tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes); } job_remove(j->id); - DG("check"); return (0); } diff --git a/42sh/src/job-control/sigtstp_handler.c b/42sh/src/job-control/sigtstp_handler.c index 5244b9c0..d771e8a3 100644 --- a/42sh/src/job-control/sigtstp_handler.c +++ b/42sh/src/job-control/sigtstp_handler.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 15:14:53 by jhalford #+# #+# */ -/* Updated: 2017/03/05 15:30:58 by wescande ### ########.fr */ +/* Updated: 2017/03/16 16:52:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,10 +14,5 @@ void sigtstp_handler(int signo) { -// t_jobc *jobc; - (void)signo; -// jobc = &data_singleton()->jobc; - DG("got SIGTSTP pid=%i, pgrp=%i, shell_pgid=%i", getpid(), getpgrp(), data_singleton()->jobc.shell_pgid); - ft_putchar('\x1A'); } diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 11e9f92e..03c24127 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/15 16:23:18 by wescande ### ########.fr */ +/* Updated: 2017/03/16 16:47:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 238ded89..93594fd9 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/16 16:36:34 by jhalford ### ########.fr */ +/* Updated: 2017/03/16 18:01:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index 7d2fce00..23d9f9fc 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/15 13:55:49 by gwojda ### ########.fr */ +/* Updated: 2017/03/16 16:47:50 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,6 @@ static int interactive_settings(void) t_data *data; data = data_singleton(); - DG("interactive shell settings"); shell_pgid = &data->jobc.shell_pgid; while (tcgetpgrp(STDIN) != (*shell_pgid = getpgrp())) kill(-*shell_pgid, SIGTTIN); @@ -54,17 +53,12 @@ int shell_init(int ac, char **av) data_init(ac, av); if (isatty(STDIN) && !*cliopts_getdata(av)) { - DG("interactive"); data->opts |= SH_INTERACTIVE; data->opts |= SH_OPTS_JOBC; } - else - DG("non interactive"); if (cliopts_get(av, g_opts, data)) return (ft_perror()); if (SH_IS_INTERACTIVE(data->opts)) interactive_settings(); - else - DG("not interactive"); return (0); }