diff --git a/42sh/Makefile b/42sh/Makefile index 46f6de4d..441332c6 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -188,6 +188,15 @@ job-control/process_free_cmd.c\ job-control/process_free_cond.c\ job-control/process_free_list.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_foreground.c\ job-control/sigchld_handler.c\ diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index baf2e7d6..850f95d6 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/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_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_OR_IF (1 << 3) # define EXEC_IF_BRANCH (1 << 4) diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index 62c32983..0598611e 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/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); 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 diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 56057738..7c5e0999 100644 --- a/42sh/includes/lexer.h +++ b/42sh/includes/lexer.h @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_ampersand.c b/42sh/src/exec/exec_ampersand.c index a95c357c..d9b65bbf 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/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; push(&exec->op_stack, TK_AMP); ft_exec(&(*ast)->left); - exec->attrs &= ~EXEC_BG; + exec->attrs &= ~EXEC_AOL_MASK; + exec->job.attrs &= ~JOB_BG; 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); } diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 95f1d38b..3a242088 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/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); if (!(launch_process(&p))) { + DG("forked pid=[%i], name=[%s]", p.pid, p.data.cmd.av[0]); job_addprocess(&p); if (IS_PIPEEND(p)) { @@ -29,8 +30,8 @@ int exec_leaf(t_btree **ast) put_job_in_foreground(job, 0); else put_job_in_background(job, 0); + job->pgid = 0; } - job->pgid = 0; } if (p.fdout != STDOUT) close(p.fdout); diff --git a/42sh/src/exec/exec_semi.c b/42sh/src/exec/exec_semi.c index 4a0d2699..7f8b91ce 100644 --- a/42sh/src/exec/exec_semi.c +++ b/42sh/src/exec/exec_semi.c @@ -6,7 +6,7 @@ /* 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); exec->attrs &= ~EXEC_AOL_MASK; ft_exec(&(*ast)->right); -// btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/exec/launch_file.c b/42sh/src/exec/launch_file.c index 180d0f58..249c49d1 100644 --- a/42sh/src/exec/launch_file.c +++ b/42sh/src/exec/launch_file.c @@ -6,7 +6,7 @@ /* 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; - DG("in file"); + /* DG("in file"); */ pid = fork(); 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]); exit(126); } - // for all leaves process_setgroup(p, 0); process_setsig(); if (process_redirect(p)) exit (1); exec_reset(); - // (*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]); exit(42); diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index dbe58ef0..2013bfa2 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/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_FOR, launch_for}, {PROCESS_CASE, launch_case}, - {0, NULL} }; int launch_process(t_process *p) { int pid; + DG("launchprocess"); if (p->type >= PROCESS_MAX) return (-1); if (!g_launchmap[p->type].f) diff --git a/42sh/src/exec/mark_process_status.c b/42sh/src/exec/mark_process_status.c index ecc3c9ea..c2e7dd97 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/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_process *p; + DG("MPS pid=%i,s=%i", pid, status); if (pid > 1) { - DG("MPS pid=%i,s=%i", pid, status); if ((plist = job_getprocess(pid))) { p = plist->content; p->status = status; + DG("marking pid=[%i], name=[%s]", p->pid, p->data.cmd.av[0]); if (WIFSTOPPED(status)) { p->attrs &= ~PROCESS_STATE_MASK; @@ -39,7 +40,8 @@ int mark_process_status(pid_t pid, int status) } 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); } diff --git a/42sh/src/exec/process_setgroup.c b/42sh/src/exec/process_setgroup.c index 60caf7e9..e255b3ed 100644 --- a/42sh/src/exec/process_setgroup.c +++ b/42sh/src/exec/process_setgroup.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/set_process.c b/42sh/src/exec/set_process.c index b8135905..cf7f2fbf 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/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 fds[2]; -// cmd = &((t_astnode *)ast->item)->data.cmd; - /* process_reset(p); */ exec = &data_singleton()->exec; op = pop(&exec->op_stack); 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_READ] = STDIN; if (op == TK_AMP) - exec->attrs |= JOB_BG; + exec->job.attrs |= JOB_BG; else if (op == TK_PIPE) pipe(fds); p->fdin = exec->fdin; diff --git a/42sh/src/exec/set_process_cmd.c b/42sh/src/exec/set_process_cmd.c index 9367917a..76b4b098 100644 --- a/42sh/src/exec/set_process_cmd.c +++ b/42sh/src/exec/set_process_cmd.c @@ -6,7 +6,7 @@ /* 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.execf = NULL; p->data.cmd.stat = ft_memalloc(sizeof(struct stat)); - DG("gonna setexec av[0]=[%s]", p->data.cmd.av[0]); p->type = PROCESS_FILE; if ((func = is_function(p))) { @@ -40,7 +39,6 @@ int set_process_cmd(t_process *p, t_btree *ast) else if (ft_hash(p)) { 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) { ft_memdel((void**)&p->data.cmd.stat); diff --git a/42sh/src/job-control/builtin_jobs.c b/42sh/src/job-control/builtin_jobs.c index 70395bf6..3031cde0 100644 --- a/42sh/src/job-control/builtin_jobs.c +++ b/42sh/src/job-control/builtin_jobs.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/do_job_notification.c b/42sh/src/job-control/do_job_notification.c index 48829692..7d73c78a 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/03 16:46:51 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 20:35:18 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_addprocess.c b/42sh/src/job-control/job_addprocess.c index 42c5229e..af8e039d 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/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; job = &data_singleton()->exec.job; + DG("adding pid=[%i] to job", p->pid); if (IS_PIPESTART(*p)) { job_update_id(); @@ -27,10 +28,7 @@ int job_addprocess(t_process *p) ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job))); } 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)) job_notify_new(job); return (0); diff --git a/42sh/src/job-control/job_is_stopped.c b/42sh/src/job-control/job_is_stopped.c index 60eed462..16c2bee8 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/06 12:31:00 by wescande ### ########.fr */ +/* Updated: 2017/03/08 20:53:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_notify_change.c b/42sh/src/job-control/job_notify_change.c index 3ec46e79..9535b95a 100644 --- a/42sh/src/job-control/job_notify_change.c +++ b/42sh/src/job-control/job_notify_change.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_notify_new.c b/42sh/src/job-control/job_notify_new.c index d19feb96..79e35da1 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: 2016/12/15 17:15:54 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 18:28:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_remove.c b/42sh/src/job-control/job_remove.c index 5dcade64..b1e88928 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 15:06:12 by wescande ### ########.fr */ +/* Updated: 2017/03/08 18:18:34 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_update_status.c b/42sh/src/job-control/job_update_status.c index cae2b934..1cae0944 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/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; do - pid = waitpid (WAIT_ANY, &status, WUNTRACED|WNOHANG); - while (!mark_process_status (pid, status)); + { + pid = waitpid(WAIT_ANY, &status, WUNTRACED | WNOHANG); + DG("pid=[%d]", pid); + } + while (!mark_process_status(pid, status)); } diff --git a/42sh/src/job-control/job_wait.c b/42sh/src/job-control/job_wait.c index 966b5f3c..8b991d00 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 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) { pid_t pid; + t_job *j; + t_jobc *jobc; int status; DG("job wait [%i]", id); + jobc = &data_singleton()->jobc; + j = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content; do - pid = waitpid(WAIT_ANY, &status, WUNTRACED); + pid = waitpid(-j->pgid, &status, WUNTRACED); while (!mark_process_status(pid, status) && !job_is_stopped(id) && !job_is_completed(id)); diff --git a/42sh/src/job-control/process_format.c b/42sh/src/job-control/process_format.c index 96052289..c8a36422 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/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; p = (*plist)->content; -/* if (p->attrs & PROCESS_CONTROL) - 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, ' '); + process_print(p); if ((*plist)->next) ft_putstr(" |"); (*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_RUNNING; } -/* if (p->attrs & PROCESS_CONTROL) - 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, ' '); + process_print(p); if ((*plist)->next) ft_putstr(" | "); (*plist) = (*plist)->next; diff --git a/42sh/src/job-control/process_free.c b/42sh/src/job-control/process_free.c index be1d1d6c..40a156b4 100644 --- a/42sh/src/job-control/process_free.c +++ b/42sh/src/job-control/process_free.c @@ -6,7 +6,7 @@ /* 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_FOR, process_free_list}, {PROCESS_CASE, process_free_list}, - {0, NULL} }; void process_free(void *content, size_t content_size) diff --git a/42sh/src/job-control/process_print.c b/42sh/src/job-control/process_print.c new file mode 100644 index 00000000..af0313dc --- /dev/null +++ b/42sh/src/job-control/process_print.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* process_print.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/42sh/src/job-control/process_print_case.c b/42sh/src/job-control/process_print_case.c new file mode 100644 index 00000000..165045fb --- /dev/null +++ b/42sh/src/job-control/process_print_case.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* process_print_case.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/42sh/src/job-control/process_print_cmd.c b/42sh/src/job-control/process_print_cmd.c new file mode 100644 index 00000000..8ae2307b --- /dev/null +++ b/42sh/src/job-control/process_print_cmd.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* process_print_cmd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/42sh/src/job-control/process_print_for.c b/42sh/src/job-control/process_print_for.c new file mode 100644 index 00000000..0d622e01 --- /dev/null +++ b/42sh/src/job-control/process_print_for.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* process_print_for.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/42sh/src/job-control/process_print_function.c b/42sh/src/job-control/process_print_function.c new file mode 100644 index 00000000..e0f0f91f --- /dev/null +++ b/42sh/src/job-control/process_print_function.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* process_print_function.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/42sh/src/job-control/process_print_if.c b/42sh/src/job-control/process_print_if.c new file mode 100644 index 00000000..a64d3276 --- /dev/null +++ b/42sh/src/job-control/process_print_if.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* process_print_if.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/42sh/src/job-control/process_print_subshell.c b/42sh/src/job-control/process_print_subshell.c new file mode 100644 index 00000000..647db0b5 --- /dev/null +++ b/42sh/src/job-control/process_print_subshell.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* process_print_subshell.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/42sh/src/job-control/process_print_until.c b/42sh/src/job-control/process_print_until.c new file mode 100644 index 00000000..2732e796 --- /dev/null +++ b/42sh/src/job-control/process_print_until.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* process_print_until.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/42sh/src/job-control/process_print_while.c b/42sh/src/job-control/process_print_while.c new file mode 100644 index 00000000..9c4a67f3 --- /dev/null +++ b/42sh/src/job-control/process_print_while.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* process_print_while.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/42sh/src/job-control/put_job_in_background.c b/42sh/src/job-control/put_job_in_background.c index 8498bea7..b72e7e98 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/02 20:57:36 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 20:33:24 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 9532bb25..9e5ae442 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 15:05:31 by wescande ### ########.fr */ +/* Updated: 2017/03/08 20:33:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,25 +17,20 @@ int put_job_in_foreground(t_job *j, int cont) t_jobc *jobc; jobc = &data_singleton()->jobc; + tcsetpgrp(STDIN, j->pgid); + if (cont) + { + tcsetattr(STDIN, TCSADRAIN, &j->tmodes); + if (kill(-j->pgid, SIGCONT) < 0) + DG("kill(SIGCONT) failed"); + } + job_wait(j->id); + job_remove(j->id); + tcsetpgrp(STDIN, jobc->shell_pgid); if (SH_HAS_JOBC(data_singleton()->opts)) { - tcsetpgrp(STDIN, j->pgid); - if (cont) - { - tcsetattr(STDIN, TCSADRAIN, &j->tmodes); - if (kill(-j->pgid, SIGCONT) < 0) - DG("kill(SIGCONT) failed"); - } - job_wait(j->id); - job_remove(j->id); - tcsetpgrp(STDIN, jobc->shell_pgid); tcgetattr(STDIN, &j->tmodes); tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes); } - else - { - job_wait(j->id); - job_remove(j->id); - } return (0); } diff --git a/42sh/src/job-control/sigchld_handler.c b/42sh/src/job-control/sigchld_handler.c index 4fe9724a..22d4c8a6 100644 --- a/42sh/src/job-control/sigchld_handler.c +++ b/42sh/src/job-control/sigchld_handler.c @@ -6,7 +6,7 @@ /* 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) { -// t_data *data; - (void)signo; -// data = data_singleton(); } diff --git a/42sh/src/lexer/lexer_heredoc.c b/42sh/src/lexer/lexer_heredoc.c index a1efef2d..7f0d9c63 100644 --- a/42sh/src/lexer/lexer_heredoc.c +++ b/42sh/src/lexer/lexer_heredoc.c @@ -6,7 +6,7 @@ /* 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->type = HEREDOCDATA; - //token_append_char(token, '\n', 0, 0); while (lexer->str[lexer->pos]) if (token_append_char(token, lexer->str[lexer->pos++], 0, 0)) return (1); 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)); */ } diff --git a/42sh/src/lexer/lexer_sep.c b/42sh/src/lexer/lexer_sep.c index b44b41c5..980aad75 100644 --- a/42sh/src/lexer/lexer_sep.c +++ b/42sh/src/lexer/lexer_sep.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/token_append.c b/42sh/src/lexer/token_append.c index 45a45b97..72a5617b 100644 --- a/42sh/src/lexer/token_append.c +++ b/42sh/src/lexer/token_append.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/control_c_and_d.c b/42sh/src/line-editing/control_c_and_d.c index b80a982c..c4a24893 100644 --- a/42sh/src/line-editing/control_c_and_d.c +++ b/42sh/src/line-editing/control_c_and_d.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/ft_prompt.c b/42sh/src/line-editing/ft_prompt.c index a9a87efa..213c33da 100644 --- a/42sh/src/line-editing/ft_prompt.c +++ b/42sh/src/line-editing/ft_prompt.c @@ -6,7 +6,7 @@ /* 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; pid_t soon; char *exec[] = {"git", "status", "--porcelain", "--branch", NULL}; + int ret; pipe(pip); if ((soon = fork())) { - wait(&soon); - if (WEXITSTATUS(soon)) + waitpid(soon, &ret, WUNTRACED); + if (WEXITSTATUS(ret)) return (-1); close(pip[1]); get_next_line(pip[0], &line); diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 3bb1774b..cb55fd73 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/08 21:02:29 by ariard ### ########.fr */ +/* Updated: 2017/03/08 23:19:16 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index d767aebd..6b0c2fa9 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/08 13:04:03 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 20:56:52 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */