This commit is contained in:
Antoine Riard 2017-03-08 23:20:28 +01:00
commit a8881bfed3
43 changed files with 286 additions and 137 deletions

View file

@ -188,6 +188,15 @@ job-control/process_free_cmd.c\
job-control/process_free_cond.c\ job-control/process_free_cond.c\
job-control/process_free_list.c\ job-control/process_free_list.c\
job-control/process_free_subshell.c\ job-control/process_free_subshell.c\
job-control/process_print.c\
job-control/process_print_case.c\
job-control/process_print_cmd.c\
job-control/process_print_for.c\
job-control/process_print_function.c\
job-control/process_print_if.c\
job-control/process_print_subshell.c\
job-control/process_print_until.c\
job-control/process_print_while.c\
job-control/put_job_in_background.c\ job-control/put_job_in_background.c\
job-control/put_job_in_foreground.c\ job-control/put_job_in_foreground.c\
job-control/sigchld_handler.c\ job-control/sigchld_handler.c\

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
/* Updated: 2017/03/08 14:58:19 by wescande ### ########.fr */ /* Updated: 2017/03/08 19:15:13 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -30,7 +30,7 @@
# define IS_PIPEEND(p) ((p).fdout == STDOUT) # define IS_PIPEEND(p) ((p).fdout == STDOUT)
# define IS_PIPESINGLE(p) (IS_PIPESTART(p) && IS_PIPEEND(p)) # define IS_PIPESINGLE(p) (IS_PIPESTART(p) && IS_PIPEEND(p))
# define EXEC_BG (1 << 1) /* # define EXEC_BG (1 << 1) */
# define EXEC_AND_IF (1 << 2) # define EXEC_AND_IF (1 << 2)
# define EXEC_OR_IF (1 << 3) # define EXEC_OR_IF (1 << 3)
# define EXEC_IF_BRANCH (1 << 4) # define EXEC_IF_BRANCH (1 << 4)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */ /* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
/* Updated: 2017/03/05 16:28:37 by jhalford ### ########.fr */ /* Updated: 2017/03/08 20:06:47 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -84,5 +84,17 @@ void sigttou_handler(int signo);
int process_cmp_pid(t_process *p, pid_t *pid); int process_cmp_pid(t_process *p, pid_t *pid);
void process_format(t_list **p, int firstp, int opts); void process_format(t_list **p, int firstp, int opts);
/*
** Mapping pour afficher les process
*/
void process_print(t_process *p);
int process_print_subshell(t_process *p);
int process_print_while(t_process *p);
int process_print_if(t_process *p);
int process_print_case(t_process *p);
int process_print_until(t_process *p);
int process_print_function(t_process *p);
int process_print_for(t_process *p);
int process_print_cmd(t_process *p);
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ /* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
/* Updated: 2017/03/08 16:11:21 by ariard ### ########.fr */ /* Updated: 2017/03/08 23:20:20 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 16:01:30 by jhalford #+# #+# */ /* Created: 2016/12/10 16:01:30 by jhalford #+# #+# */
/* Updated: 2017/03/07 18:24:12 by jhalford ### ########.fr */ /* Updated: 2017/03/08 16:46:12 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,15 +21,8 @@ int exec_ampersand(t_btree **ast)
exec = &data_singleton()->exec; exec = &data_singleton()->exec;
push(&exec->op_stack, TK_AMP); push(&exec->op_stack, TK_AMP);
ft_exec(&(*ast)->left); ft_exec(&(*ast)->left);
exec->attrs &= ~EXEC_BG; exec->attrs &= ~EXEC_AOL_MASK;
exec->job.attrs &= ~JOB_BG;
ft_exec(&(*ast)->right); ft_exec(&(*ast)->right);
/* if (SH_HAS_JOBC(data_singleton()->opts)) */
/* data_singleton()->exec.job.attributes |= JOB_BG; */
/* ft_exec(&(*ast)->left); */
/* if (SH_HAS_JOBC(data_singleton()->opts)) */
/* data_singleton()->exec.job.attributes &= ~JOB_BG; */
/* ft_exec(&(*ast)->right); */
// btree_delone(ast, &ast_free);
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */
/* Updated: 2017/03/08 14:47:30 by jhalford ### ########.fr */ /* Updated: 2017/03/08 20:31:12 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,6 +22,7 @@ int exec_leaf(t_btree **ast)
return (1); return (1);
if (!(launch_process(&p))) if (!(launch_process(&p)))
{ {
DG("forked pid=[%i], name=[%s]", p.pid, p.data.cmd.av[0]);
job_addprocess(&p); job_addprocess(&p);
if (IS_PIPEEND(p)) if (IS_PIPEEND(p))
{ {
@ -29,9 +30,9 @@ int exec_leaf(t_btree **ast)
put_job_in_foreground(job, 0); put_job_in_foreground(job, 0);
else else
put_job_in_background(job, 0); put_job_in_background(job, 0);
}
job->pgid = 0; job->pgid = 0;
} }
}
if (p.fdout != STDOUT) if (p.fdout != STDOUT)
close(p.fdout); close(p.fdout);
return (0); return (0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/30 20:52:05 by jhalford #+# #+# */ /* Created: 2016/11/30 20:52:05 by jhalford #+# #+# */
/* Updated: 2017/03/06 18:09:54 by ariard ### ########.fr */ /* Updated: 2017/03/08 16:41:45 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,6 +21,5 @@ int exec_semi(t_btree **ast)
ft_exec(&(*ast)->left); ft_exec(&(*ast)->left);
exec->attrs &= ~EXEC_AOL_MASK; exec->attrs &= ~EXEC_AOL_MASK;
ft_exec(&(*ast)->right); ft_exec(&(*ast)->right);
// btree_delone(ast, &ast_free);
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */ /* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */
/* Updated: 2017/03/08 14:46:08 by jhalford ### ########.fr */ /* Updated: 2017/03/08 17:35:42 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,7 +16,7 @@ int launch_file(t_process *p)
{ {
int pid; int pid;
DG("in file"); /* DG("in file"); */
pid = fork(); pid = fork();
if (pid == 0) if (pid == 0)
{ {
@ -40,13 +40,11 @@ int launch_file(t_process *p)
ft_dprintf(2, "{red}%s: permission denied: %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]); ft_dprintf(2, "{red}%s: permission denied: %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);
exit(126); exit(126);
} }
// for all leaves
process_setgroup(p, 0); process_setgroup(p, 0);
process_setsig(); process_setsig();
if (process_redirect(p)) if (process_redirect(p))
exit (1); exit (1);
exec_reset(); exec_reset();
//
(*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env); (*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]); ft_dprintf(2, "{red}%s: internal execve error on %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);
exit(42); exit(42);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */ /* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
/* Updated: 2017/03/08 14:45:54 by jhalford ### ########.fr */ /* Updated: 2017/03/08 20:46:03 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,13 +23,13 @@ t_itof g_launchmap[] =
{PROCESS_IF, launch_if}, {PROCESS_IF, launch_if},
{PROCESS_FOR, launch_for}, {PROCESS_FOR, launch_for},
{PROCESS_CASE, launch_case}, {PROCESS_CASE, launch_case},
{0, NULL}
}; };
int launch_process(t_process *p) int launch_process(t_process *p)
{ {
int pid; int pid;
DG("launchprocess");
if (p->type >= PROCESS_MAX) if (p->type >= PROCESS_MAX)
return (-1); return (-1);
if (!g_launchmap[p->type].f) if (!g_launchmap[p->type].f)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
/* Updated: 2017/03/06 12:28:55 by wescande ### ########.fr */ /* Updated: 2017/03/08 18:49:49 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,13 +17,14 @@ int mark_process_status(pid_t pid, int status)
t_list *plist; t_list *plist;
t_process *p; t_process *p;
DG("MPS pid=%i,s=%i", pid, status);
if (pid > 1) if (pid > 1)
{ {
DG("MPS pid=%i,s=%i", pid, status);
if ((plist = job_getprocess(pid))) if ((plist = job_getprocess(pid)))
{ {
p = plist->content; p = plist->content;
p->status = status; p->status = status;
DG("marking pid=[%i], name=[%s]", p->pid, p->data.cmd.av[0]);
if (WIFSTOPPED(status)) if (WIFSTOPPED(status))
{ {
p->attrs &= ~PROCESS_STATE_MASK; p->attrs &= ~PROCESS_STATE_MASK;
@ -39,7 +40,8 @@ int mark_process_status(pid_t pid, int status)
} }
return (0); return (0);
} }
ft_dprintf(2, "No child process %d.\n", pid); ft_dprintf(2, "{red}No child process %d.\n", pid);
return (0);
} }
return (-1); return (-1);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */ /* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */
/* Updated: 2017/03/03 16:34:02 by jhalford ### ########.fr */ /* Updated: 2017/03/08 20:53:48 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
/* Updated: 2017/03/08 15:55:27 by jhalford ### ########.fr */ /* Updated: 2017/03/08 16:46:51 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,8 +19,6 @@ int set_process(t_process *p, t_btree *ast)
int op; int op;
int fds[2]; int fds[2];
// cmd = &((t_astnode *)ast->item)->data.cmd;
/* process_reset(p); */
exec = &data_singleton()->exec; exec = &data_singleton()->exec;
op = pop(&exec->op_stack); op = pop(&exec->op_stack);
if ((EXEC_IS_AND_IF(exec->attrs) if ((EXEC_IS_AND_IF(exec->attrs)
@ -31,7 +29,7 @@ int set_process(t_process *p, t_btree *ast)
fds[PIPE_WRITE] = STDOUT; fds[PIPE_WRITE] = STDOUT;
fds[PIPE_READ] = STDIN; fds[PIPE_READ] = STDIN;
if (op == TK_AMP) if (op == TK_AMP)
exec->attrs |= JOB_BG; exec->job.attrs |= JOB_BG;
else if (op == TK_PIPE) else if (op == TK_PIPE)
pipe(fds); pipe(fds);
p->fdin = exec->fdin; p->fdin = exec->fdin;

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:06:05 by wescande #+# #+# */ /* Created: 2017/03/07 15:06:05 by wescande #+# #+# */
/* Updated: 2017/03/08 15:55:25 by jhalford ### ########.fr */ /* Updated: 2017/03/08 18:49:55 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,7 +21,6 @@ int set_process_cmd(t_process *p, t_btree *ast)
p->data.cmd.path = NULL; p->data.cmd.path = NULL;
p->data.cmd.execf = NULL; p->data.cmd.execf = NULL;
p->data.cmd.stat = ft_memalloc(sizeof(struct stat)); p->data.cmd.stat = ft_memalloc(sizeof(struct stat));
DG("gonna setexec av[0]=[%s]", p->data.cmd.av[0]);
p->type = PROCESS_FILE; p->type = PROCESS_FILE;
if ((func = is_function(p))) if ((func = is_function(p)))
{ {
@ -40,7 +39,6 @@ int set_process_cmd(t_process *p, t_btree *ast)
else if (ft_hash(p)) else if (ft_hash(p))
{ {
p->data.cmd.execf = &execve; p->data.cmd.execf = &execve;
DG("found hash at [%s]", p->data.cmd.path);
if (stat(p->data.cmd.path, p->data.cmd.stat) == -1) if (stat(p->data.cmd.path, p->data.cmd.stat) == -1)
{ {
ft_memdel((void**)&p->data.cmd.stat); ft_memdel((void**)&p->data.cmd.stat);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */ /* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */
/* Updated: 2017/01/31 15:05:34 by jhalford ### ########.fr */ /* Updated: 2017/03/08 18:52:24 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */ /* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */
/* Updated: 2017/03/03 16:46:51 by jhalford ### ########.fr */ /* Updated: 2017/03/08 20:35:18 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */ /* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */
/* Updated: 2017/03/05 15:12:31 by jhalford ### ########.fr */ /* Updated: 2017/03/08 20:16:09 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,6 +19,7 @@ int job_addprocess(t_process *p)
jobc = &data_singleton()->jobc; jobc = &data_singleton()->jobc;
job = &data_singleton()->exec.job; job = &data_singleton()->exec.job;
DG("adding pid=[%i] to job", p->pid);
if (IS_PIPESTART(*p)) if (IS_PIPESTART(*p))
{ {
job_update_id(); job_update_id();
@ -27,10 +28,7 @@ int job_addprocess(t_process *p)
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job))); ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
} }
job = jobc->first_job->content; job = jobc->first_job->content;
if (p->pid > 0)
{
ft_lsteadd(&job->first_process, ft_lstnew(p, sizeof(*p))); ft_lsteadd(&job->first_process, ft_lstnew(p, sizeof(*p)));
}
if (JOB_IS_BG(job->attrs) && IS_PIPEEND(*p)) if (JOB_IS_BG(job->attrs) && IS_PIPEEND(*p))
job_notify_new(job); job_notify_new(job);
return (0); return (0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 15:06:45 by jhalford #+# #+# */ /* Created: 2016/12/13 15:06:45 by jhalford #+# #+# */
/* Updated: 2017/03/06 12:31:00 by wescande ### ########.fr */ /* Updated: 2017/03/08 20:53:25 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 15:04:03 by jhalford #+# #+# */ /* Created: 2016/12/12 15:04:03 by jhalford #+# #+# */
/* Updated: 2017/01/31 14:46:48 by jhalford ### ########.fr */ /* Updated: 2017/03/08 17:18:20 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:27:01 by jhalford #+# #+# */ /* Created: 2016/12/13 14:27:01 by jhalford #+# #+# */
/* Updated: 2016/12/15 17:15:54 by jhalford ### ########.fr */ /* Updated: 2017/03/08 18:28:01 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */ /* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */
/* Updated: 2017/03/08 15:06:12 by wescande ### ########.fr */ /* Updated: 2017/03/08 18:18:34 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */ /* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */
/* Updated: 2017/03/03 18:56:57 by jhalford ### ########.fr */ /* Updated: 2017/03/08 20:35:12 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,6 +18,9 @@ void job_update_status(void)
pid_t pid; pid_t pid;
do do
{
pid = waitpid(WAIT_ANY, &status, WUNTRACED | WNOHANG); pid = waitpid(WAIT_ANY, &status, WUNTRACED | WNOHANG);
DG("pid=[%d]", pid);
}
while (!mark_process_status(pid, status)); while (!mark_process_status(pid, status));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */ /* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */
/* Updated: 2017/03/03 19:42:12 by jhalford ### ########.fr */ /* Updated: 2017/03/08 20:46:24 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,11 +15,15 @@
int job_wait(int id) int job_wait(int id)
{ {
pid_t pid; pid_t pid;
t_job *j;
t_jobc *jobc;
int status; int status;
DG("job wait [%i]", id); DG("job wait [%i]", id);
jobc = &data_singleton()->jobc;
j = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content;
do do
pid = waitpid(WAIT_ANY, &status, WUNTRACED); pid = waitpid(-j->pgid, &status, WUNTRACED);
while (!mark_process_status(pid, status) while (!mark_process_status(pid, status)
&& !job_is_stopped(id) && !job_is_stopped(id)
&& !job_is_completed(id)); && !job_is_completed(id));

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 13:05:55 by jhalford #+# #+# */ /* Created: 2017/01/09 13:05:55 by jhalford #+# #+# */
/* Updated: 2017/03/07 21:24:17 by wescande ### ########.fr */ /* Updated: 2017/03/08 20:08:26 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -42,16 +42,7 @@ static void process_format_com_long(t_list **plist)
t_process *p; t_process *p;
p = (*plist)->content; p = (*plist)->content;
/* if (p->attrs & PROCESS_CONTROL) process_print(p);
ft_putstr("script");
else if (p->attrs & PROCESS_SUBSHELL)
{
ft_putstr("( ");
// ft_putstr(p->data.cmd.av[2]);
ft_putstr(" )");
}
else*/
ft_sstrprint(p->data.cmd.av, ' ');
if ((*plist)->next) if ((*plist)->next)
ft_putstr(" |"); ft_putstr(" |");
(*plist) = (*plist)->next; (*plist) = (*plist)->next;
@ -72,16 +63,7 @@ static void process_format_com_short(t_list **plist, t_flag state)
p->attrs &= ~PROCESS_STATE_MASK; p->attrs &= ~PROCESS_STATE_MASK;
p->attrs &= ~PROCESS_RUNNING; p->attrs &= ~PROCESS_RUNNING;
} }
/* if (p->attrs & PROCESS_CONTROL) process_print(p);
ft_putstr("script");
else if (p->attrs & PROCESS_SUBSHELL)
{
ft_putstr("( ");
ft_putstr(p->data.cmd.av[2]);
ft_putstr(" )");
}
else*/
ft_sstrprint(p->data.cmd.av, ' ');
if ((*plist)->next) if ((*plist)->next)
ft_putstr(" | "); ft_putstr(" | ");
(*plist) = (*plist)->next; (*plist) = (*plist)->next;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
/* Updated: 2017/03/08 12:40:22 by jhalford ### ########.fr */ /* Updated: 2017/03/08 20:13:57 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,7 +23,6 @@ t_itof g_freemap[] =
{PROCESS_IF, process_free_cond}, {PROCESS_IF, process_free_cond},
{PROCESS_FOR, process_free_list}, {PROCESS_FOR, process_free_list},
{PROCESS_CASE, process_free_list}, {PROCESS_CASE, process_free_list},
{0, NULL}
}; };
void process_free(void *content, size_t content_size) void process_free(void *content, size_t content_size)

View file

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:03:32 by wescande #+# #+# */
/* Updated: 2017/03/08 20:44:26 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_itof g_printmap[] =
{
{PROCESS_FUNCTION, process_print_function},
{PROCESS_BUILTIN, process_print_cmd},
{PROCESS_FILE, process_print_cmd},
{PROCESS_SUBSHELL, process_print_subshell},
{PROCESS_WHILE, process_print_while},
{PROCESS_UNTIL, process_print_until},
{PROCESS_IF, process_print_if},
{PROCESS_FOR, process_print_for},
{PROCESS_CASE, process_print_case},
};
void process_print(t_process *p)
{
if (p->type >= PROCESS_MAX)
return ;
if (g_printmap[p->type].f)
(*g_printmap[p->type].f)(p);
}

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_print_case.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:15:22 by wescande #+# #+# */
/* Updated: 2017/03/08 19:13:50 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int process_print_case(t_process *p)
{
(void)p;
ft_putstr("CASE GROUP");
return (0);
}

View file

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_print_cmd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:17:16 by wescande #+# #+# */
/* Updated: 2017/03/08 20:28:10 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int process_print_cmd(t_process *p)
{
ft_sstrprint(p->data.cmd.av, ' ');
return (0);
}

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_print_for.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:14:21 by wescande #+# #+# */
/* Updated: 2017/03/08 19:13:16 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int process_print_for(t_process *p)
{
(void)p;
ft_putstr("FOR GROUP");
return (0);
}

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_print_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:12:18 by wescande #+# #+# */
/* Updated: 2017/03/08 19:13:54 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int process_print_function(t_process *p)
{
(void)p;
ft_putstr("FUNCTION GROUP");
return (0);
}

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_print_if.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:14:48 by wescande #+# #+# */
/* Updated: 2017/03/08 19:14:01 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int process_print_if(t_process *p)
{
(void)p;
ft_putstr("IF GROUP");
return (0);
}

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_print_subshell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:06:06 by wescande #+# #+# */
/* Updated: 2017/03/08 19:14:54 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int process_print_subshell(t_process *p)
{
(void)p;
ft_putstr("SUBSHELL GROUP");
return (0);
}

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_print_until.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:16:00 by wescande #+# #+# */
/* Updated: 2017/03/08 19:13:36 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int process_print_until(t_process *p)
{
(void)p;
ft_putstr("UNTIL GROUP");
return (0);
}

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_print_while.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:15:01 by wescande #+# #+# */
/* Updated: 2017/03/08 19:14:13 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int process_print_while(t_process *p)
{
(void)p;
ft_putstr("WHILE GROUP");
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 15:03:29 by jhalford #+# #+# */ /* Created: 2016/12/13 15:03:29 by jhalford #+# #+# */
/* Updated: 2017/03/02 20:57:36 by jhalford ### ########.fr */ /* Updated: 2017/03/08 20:33:24 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */ /* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */
/* Updated: 2017/03/08 15:05:31 by wescande ### ########.fr */ /* Updated: 2017/03/08 20:33:21 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,8 +17,6 @@ int put_job_in_foreground(t_job *j, int cont)
t_jobc *jobc; t_jobc *jobc;
jobc = &data_singleton()->jobc; jobc = &data_singleton()->jobc;
if (SH_HAS_JOBC(data_singleton()->opts))
{
tcsetpgrp(STDIN, j->pgid); tcsetpgrp(STDIN, j->pgid);
if (cont) if (cont)
{ {
@ -29,13 +27,10 @@ int put_job_in_foreground(t_job *j, int cont)
job_wait(j->id); job_wait(j->id);
job_remove(j->id); job_remove(j->id);
tcsetpgrp(STDIN, jobc->shell_pgid); tcsetpgrp(STDIN, jobc->shell_pgid);
if (SH_HAS_JOBC(data_singleton()->opts))
{
tcgetattr(STDIN, &j->tmodes); 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); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 17:37:56 by jhalford #+# #+# */ /* Created: 2016/12/10 17:37:56 by jhalford #+# #+# */
/* Updated: 2017/03/05 15:30:35 by wescande ### ########.fr */ /* Updated: 2017/03/08 17:21:34 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,8 +14,5 @@
void sigchld_handler(int signo) void sigchld_handler(int signo)
{ {
// t_data *data;
(void)signo; (void)signo;
// data = data_singleton();
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 15:51:17 by jhalford #+# #+# */ /* Created: 2017/03/08 15:51:17 by jhalford #+# #+# */
/* Updated: 2017/03/08 20:04:52 by ariard ### ########.fr */ /* Updated: 2017/03/08 23:19:57 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,41 +18,8 @@ int lexer_heredoc(t_list **alst, t_lexer *lexer)
token = (*alst)->content; token = (*alst)->content;
token->type = HEREDOCDATA; token->type = HEREDOCDATA;
//token_append_char(token, '\n', 0, 0);
while (lexer->str[lexer->pos]) while (lexer->str[lexer->pos])
if (token_append_char(token, lexer->str[lexer->pos++], 0, 0)) if (token_append_char(token, lexer->str[lexer->pos++], 0, 0))
return (1); return (1);
return (0); return (0);
//ft_strappend(&lexer->str, (char[]){'\n', 0});
//lexer->pos++;
/* heredoc_lst = *(t_list**)lexer->heredoc_stack->content; */
/* heredoc_tok = heredoc_lst->content; */
/* if (!(heredoc_lst->next)) */
/* { */
/* ft_dprintf(2, "{red}%s: parse error near `\\n'{eoc}\n", SHELL_NAME); */
/* return (1); */
/* } */
/* eof_tok = heredoc_lst->next->content; */
/* if (!(eof_tok->type == TK_WORD)) */
/* { */
/* ft_dprintf(2, "{red}%s: expected word token after <<{eoc}\n", SHELL_NAME); */
/* return (1); */
/* } */
/* DG("heredoc contains [%s]", heredoc_tok->data); */
/* DG("heredoc ends at [%s]", eof_tok->data); */
/* DG("input is [%s]", lexer->str + lexer->pos); */
/* if (ft_strcmp(eof_tok->data, lexer->str + lexer->pos) == 0) */
/* { */
/* /1* pop(&lexer->stack); *1/ */
/* pop(&lexer->heredoc_stack); */
/* while (lexer->str[++lexer->pos]) */
/* ; */
/* ft_strappend(&lexer->str, (char[]){'\n', 0}); */
/* lexer->pos++; */
/* return (0); */
/* } */
/* else */
/* while (lexer->str[lexer->pos]) */
/* token_append_char(heredoc_tok, lexer->str[lexer->pos++], 0, 0); */
/* return (lexer_end(alst, lexer)); */
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/30 16:29:57 by jhalford #+# #+# */ /* Created: 2016/11/30 16:29:57 by jhalford #+# #+# */
/* Updated: 2017/03/08 12:20:30 by jhalford ### ########.fr */ /* Updated: 2017/03/08 17:11:35 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/11 17:18:42 by jhalford #+# #+# */ /* Created: 2016/11/11 17:18:42 by jhalford #+# #+# */
/* Updated: 2017/03/03 15:12:41 by wescande ### ########.fr */ /* Updated: 2017/03/08 17:45:08 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/02 15:17:28 by gwojda #+# #+# */ /* Created: 2017/02/02 15:17:28 by gwojda #+# #+# */
/* Updated: 2017/03/08 12:56:46 by jhalford ### ########.fr */ /* Updated: 2017/03/08 17:37:21 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */ /* Created: 2016/12/13 13:51:33 by gwojda #+# #+# */
/* Updated: 2017/02/16 14:27:57 by gwojda ### ########.fr */ /* Updated: 2017/03/08 21:23:54 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,12 +20,13 @@ static int ft_git_status(void)
char *line; char *line;
pid_t soon; pid_t soon;
char *exec[] = {"git", "status", "--porcelain", "--branch", NULL}; char *exec[] = {"git", "status", "--porcelain", "--branch", NULL};
int ret;
pipe(pip); pipe(pip);
if ((soon = fork())) if ((soon = fork()))
{ {
wait(&soon); waitpid(soon, &ret, WUNTRACED);
if (WEXITSTATUS(soon)) if (WEXITSTATUS(ret))
return (-1); return (-1);
close(pip[1]); close(pip[1]);
get_next_line(pip[0], &line); get_next_line(pip[0], &line);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
/* Updated: 2017/03/08 21:02:29 by ariard ### ########.fr */ /* Updated: 2017/03/08 23:19:16 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */
/* Updated: 2017/03/08 13:04:03 by jhalford ### ########.fr */ /* Updated: 2017/03/08 20:56:52 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */