diff --git a/42sh/src/exec/exec_ampersand.c b/42sh/src/exec/exec_ampersand.c index d32ad177..4480fc2e 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/03 16:05:30 by jhalford ### ########.fr */ +/* Updated: 2017/03/03 19:35:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,12 +16,13 @@ int exec_ampersand(t_btree **ast) { t_exec *exec; + if (!SH_HAS_JOBC(data_singleton()->opts)) + return (exec_semi(ast)); exec = &data_singleton()->exec; push(&exec->op_stack, TK_AMP); ft_exec(&(*ast)->left); exec->attrs &= ~EXEC_BG; ft_exec(&(*ast)->right); - /* if (SH_HAS_JOBC(data_singleton()->opts)) */ /* data_singleton()->exec.job.attributes |= JOB_BG; */ /* ft_exec(&(*ast)->left); */ diff --git a/42sh/src/exec/exec_command.c b/42sh/src/exec/exec_command.c index b63752a6..b4acaccf 100644 --- a/42sh/src/exec/exec_command.c +++ b/42sh/src/exec/exec_command.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */ -/* Updated: 2017/03/03 19:02:44 by jhalford ### ########.fr */ +/* Updated: 2017/03/03 19:46:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,10 +54,7 @@ int exec_cmd(t_btree **ast) if (op == TK_AMP) exec->attrs |= JOB_BG; else 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/add_new_job.c b/42sh/src/job-control/add_new_job.c index 3e345d1d..3e866fac 100644 --- a/42sh/src/job-control/add_new_job.c +++ b/42sh/src/job-control/add_new_job.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/02 20:44:21 by jhalford #+# #+# */ -/* Updated: 2017/03/03 18:54:10 by jhalford ### ########.fr */ +/* Updated: 2017/03/03 19:33:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_getprocess.c b/42sh/src/job-control/job_getprocess.c index 52bb8229..3ad82217 100644 --- a/42sh/src/job-control/job_getprocess.c +++ b/42sh/src/job-control/job_getprocess.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/31 15:07:30 by jhalford #+# #+# */ -/* Updated: 2017/03/03 19:03:01 by jhalford ### ########.fr */ +/* Updated: 2017/03/03 19:42:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_wait.c b/42sh/src/job-control/job_wait.c index 6a1c380a..38f18f8f 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/03 18:54:18 by jhalford ### ########.fr */ +/* Updated: 2017/03/03 19:42:12 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 71411673..c5b75d0b 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/03 18:57:58 by jhalford ### ########.fr */ +/* Updated: 2017/03/03 19:46:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,12 +16,10 @@ int put_job_in_foreground(t_job *j, int cont) { t_jobc *jobc; + jobc = &data_singleton()->jobc; if (SH_HAS_JOBC(data_singleton()->opts)) { - jobc = &data_singleton()->jobc; - tcsetpgrp(STDIN, j->pgid); - tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes); if (cont) { tcsetattr(STDIN, TCSADRAIN, &j->tmodes); @@ -35,9 +33,11 @@ int put_job_in_foreground(t_job *j, int cont) tcgetattr(STDIN, &j->tmodes); tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes); - tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes); } else + { job_wait(j->id); + job_remove(j->id); + } return (0); } diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 591cc8c0..78d413f7 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/03 18:55:05 by jhalford ### ########.fr */ +/* Updated: 2017/03/03 19:45:05 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ int data_init(void) data = data_singleton(); data->env = ft_sstrdup(environ); data->comp = NULL; - data->opts = SH_OPTS_JOBC; + data->opts = 0; /* data->exec.process.path = NULL; */ /* data->exec.process.av = NULL; */ /* data->exec.process.to_close = 0; */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index f79cb83a..9bbf2a54 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/03 19:05:22 by jhalford ### ########.fr */ +/* Updated: 2017/03/03 19:37:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -98,7 +98,8 @@ int get_input_fd() } else if ((file = shell_get_avdata())) { - if (fd = open(file, O_RDONLY)) + if ((fd = open(file, O_RDONLY | O_CLOEXEC)) < 0) + return (-1); return (fd); } else @@ -113,7 +114,7 @@ int main(int ac, char **av) shell_init(ac, av); if ((fd = get_input_fd()) < 0) { - ft_printf("{red}%s: No such file or directory\n{eoc}", SHELL_NAME); + 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]", diff --git a/42sh/src/main/shell_get_opts.c b/42sh/src/main/shell_get_opts.c index 215f2145..b0789b58 100644 --- a/42sh/src/main/shell_get_opts.c +++ b/42sh/src/main/shell_get_opts.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/11 14:04:48 by jhalford #+# #+# */ -/* Updated: 2017/02/21 15:37:22 by ariard ### ########.fr */ +/* Updated: 2017/03/03 19:45:39 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,7 +41,10 @@ void shell_get_opts(int ac, char **av) i = 1; if (isatty(STDIN) && !av[1]) + { data_singleton()->opts |= SH_INTERACTIVE; + data_singleton()->opts |= SH_OPTS_JOBC; + } while (i < ac && av[i][0] == '-') { if (ft_strcmp(av[i], "--") == 0) diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index 7ad9da23..272440d7 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/02 20:38:23 by jhalford ### ########.fr */ +/* Updated: 2017/03/03 19:45:52 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */