bang exec ok

This commit is contained in:
Antoine Riard 2017-03-10 16:23:51 +01:00
commit 0852e7c807
18 changed files with 48 additions and 30 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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))

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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];

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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();

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */