diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index ca7bb4aa..a85ff52b 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/10 15:45:50 by ariard ### ########.fr */ +/* Updated: 2017/03/10 16:19:30 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index 0598611e..5013d09c 100644 --- a/42sh/includes/job_control.h +++ b/42sh/includes/job_control.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */ -/* Updated: 2017/03/08 20:06:47 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 15:38:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,7 @@ # define JOB_NOTIFIED (1 << 0) # define JOB_BG (1 << 1) + # define JOB_IS_BG(j) (j & JOB_BG) # define JOB_IS_FG(j) (!JOB_IS_BG(j)) diff --git a/42sh/src/exec/exec_ampersand.c b/42sh/src/exec/exec_ampersand.c index d9b65bbf..04f60729 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/08 16:46:12 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 15:36:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,7 @@ 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 6aa92a4d..424cf51f 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/10 11:58:54 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 15:36:02 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,16 +24,15 @@ int exec_leaf(t_btree **ast) { DG("forked pid=[%i], name=[%s]", p.pid, p.data.cmd.av[0]); job_addprocess(&p); + DG("[BG:%i]", JOB_IS_BG(job->attrs)); if (IS_PIPEEND(p)) { if (JOB_IS_FG(job->attrs)) put_job_in_foreground(job, 0); - else - put_job_in_background(job, 0); + /* else */ + /* put_job_in_background(job, 0); */ job->pgid = 0; } } - if (p.fdout != STDOUT) - close(p.fdout); return (0); } diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index 0fbbd7db..ce257525 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/10 11:58:53 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 15:21:02 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,9 +40,12 @@ int launch_process(t_process *p) { DG("gonna reset fds"); process_resetfds(p); - return (-1); + return (1); } p->pid = pid; process_setgroup(p, pid); + /* process_resetfds(p); */ + if (p->fdout != STDOUT) + close(p->fdout); return (0); } diff --git a/42sh/src/exec/process_redirect.c b/42sh/src/exec/process_redirect.c index 66b43221..814b48b7 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/09 15:14:43 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 15:31:30 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -51,6 +51,7 @@ int process_redirect(t_process *p) } redirs = redirs->next; } + DG("redirecting [%i:%i] [%i]", p->fdin, p->fdout, p->to_close); if (p->to_close != STDIN) close(p->to_close); if (p->fdin != STDIN) diff --git a/42sh/src/exec/process_resetfds.c b/42sh/src/exec/process_resetfds.c index 7cfd2220..0d310a70 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 13:09:25 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 14:35:00 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/redirect_greatand.c b/42sh/src/exec/redirect_greatand.c index ad449c2b..26c8302c 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:01:06 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 14:31:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/set_process.c b/42sh/src/exec/set_process.c index 8faa6f7b..4e360605 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/10 14:54:15 by ariard ### ########.fr */ +/* Updated: 2017/03/10 16:22:00 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,10 +28,11 @@ int set_process(t_process *p, t_btree *ast) return (1); fds[PIPE_WRITE] = STDOUT; fds[PIPE_READ] = STDIN; - if (op == TK_AMP) - exec->job.attrs |= JOB_BG; - else if (op == TK_PIPE) + if (op == TK_PIPE) + { pipe(fds); + DG("[%i] -> PIPE -> [%i]", fds[PIPE_WRITE], fds[PIPE_READ]); + } p->fdin = exec->fdin; p->to_close = fds[PIPE_READ]; p->fdout = fds[PIPE_WRITE]; diff --git a/42sh/src/job-control/job_addprocess.c b/42sh/src/job-control/job_addprocess.c index af8e039d..fb153c30 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/08 20:16:09 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 15:36:33 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,9 +27,15 @@ int job_addprocess(t_process *p) job->pgid = p->pid; ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job))); } + DG("check 0"); 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)) + { + DG("check 2"); job_notify_new(job); + } + DG("check 3"); return (0); } diff --git a/42sh/src/job-control/job_notify_new.c b/42sh/src/job-control/job_notify_new.c index 79e35da1..ac26426c 100644 --- a/42sh/src/job-control/job_notify_new.c +++ b/42sh/src/job-control/job_notify_new.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:27:01 by jhalford #+# #+# */ -/* Updated: 2017/03/08 18:28:01 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 15:36:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_remove.c b/42sh/src/job-control/job_remove.c index b1e88928..45f24e9f 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/08 18:18:34 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 14:40:16 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_update_status.c b/42sh/src/job-control/job_update_status.c index 575becb1..a3088f15 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/10 12:41:11 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 15:38:56 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_wait.c b/42sh/src/job-control/job_wait.c index 8b991d00..d655567f 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/08 20:46:24 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 15:40:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,7 @@ int job_wait(int id) j = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content; do pid = waitpid(-j->pgid, &status, WUNTRACED); - while (!mark_process_status(pid, status) + 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/put_job_in_background.c b/42sh/src/job-control/put_job_in_background.c index b72e7e98..b0302223 100644 --- a/42sh/src/job-control/put_job_in_background.c +++ b/42sh/src/job-control/put_job_in_background.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 15:03:29 by jhalford #+# #+# */ -/* Updated: 2017/03/08 20:33:24 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 15:08:14 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/put_job_in_foreground.c b/42sh/src/job-control/put_job_in_foreground.c index 9e5ae442..97b9ba4a 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/08 20:33:21 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 15:16:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,10 @@ int put_job_in_foreground(t_job *j, int cont) t_jobc *jobc; jobc = &data_singleton()->jobc; + DG("givving terminal to job [%i]", j->pgid); tcsetpgrp(STDIN, j->pgid); + /* tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes); */ + if (cont) { tcsetattr(STDIN, TCSADRAIN, &j->tmodes); @@ -26,11 +29,12 @@ int put_job_in_foreground(t_job *j, int cont) } job_wait(j->id); job_remove(j->id); + tcsetpgrp(STDIN, jobc->shell_pgid); - if (SH_HAS_JOBC(data_singleton()->opts)) - { + /* if (SH_HAS_JOBC(data_singleton()->opts)) */ + /* { */ tcgetattr(STDIN, &j->tmodes); tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes); - } + /* } */ return (0); } diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c index 49079633..5c75131c 100644 --- a/42sh/src/line-editing/readline.c +++ b/42sh/src/line-editing/readline.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ -/* Updated: 2017/03/09 00:09:19 by ariard ### ########.fr */ +/* Updated: 2017/03/10 15:48:30 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,6 +22,8 @@ int readline(int fd, int prompt, char **input) } readline_init(prompt); *input = ft_read_stdin(); + if (STR) + ft_current_str(STR, POS); ft_putchar('\n'); if (!prompt) *input = ft_history_parsing(); diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 690c17b1..a10e2b17 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/10 15:44:35 by ariard ### ########.fr */ +/* Updated: 2017/03/10 16:20:35 by ariard ### ########.fr */ /* */ /* ************************************************************************** */