diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index afb375d9..08f66b66 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/15 20:31:07 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 23:10:35 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -42,7 +42,7 @@ void job_update_id(void); void job_update_rank(void); int do_job_notification(void); -void job_notify_new(t_job *job); +void job_notify_new(int id); void job_notify_change(int id); void job_format(t_job *j, int opts); void job_format_head(t_job *j); diff --git a/42sh/libft/src/str/ft_atoi.c b/42sh/libft/src/str/ft_atoi.c index 711e3d68..b583a198 100644 --- a/42sh/libft/src/str/ft_atoi.c +++ b/42sh/libft/src/str/ft_atoi.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/08/03 16:17:21 by jhalford #+# #+# */ -/* Updated: 2016/11/03 15:13:04 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 20:36:22 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,6 +27,8 @@ int ft_atoi(const char *str) int res; int sign; + if (!str || !*str) + return (0); i = 0; res = 0; sign = 1; diff --git a/42sh/src/builtin/is_builtin.c b/42sh/src/builtin/is_builtin.c index 205380d2..4f43e139 100644 --- a/42sh/src/builtin/is_builtin.c +++ b/42sh/src/builtin/is_builtin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */ -/* Updated: 2017/03/17 23:19:52 by ariard ### ########.fr */ +/* Updated: 2017/03/18 00:53:53 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,7 +37,6 @@ t_execf *is_builtin(t_process *p) { int i; - DG("in builtin"); i = -1; while (g_builtin[++i].name) { diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 4fdd864f..9de326b8 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -1,4 +1,4 @@ -/*ss ************************************************************************** */ +/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* exec_leaf.c :+: :+: :+: */ @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ -/* Updated: 2017/03/16 21:45:47 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 23:10:43 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,6 +45,8 @@ int exec_leaf(t_btree **ast) { if (JOB_IS_FG(job->attrs)) put_job_in_foreground(job, 0); + else + job_notify_new(job->id); job->pgid = 0; } DG("check"); diff --git a/42sh/src/exec/mark_process_status.c b/42sh/src/exec/mark_process_status.c index dbde6d7d..7f6470a6 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/17 21:38:46 by jhalford ### ########.fr */ +/* Updated: 2017/03/18 00:04:46 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_brace.c b/42sh/src/exec/plaunch_brace.c index f584cb6b..791104d8 100644 --- a/42sh/src/exec/plaunch_brace.c +++ b/42sh/src/exec/plaunch_brace.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 19:09:30 by jhalford #+# #+# */ -/* Updated: 2017/03/16 21:42:35 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 20:35:24 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,16 +14,6 @@ int plaunch_brace(t_process *p) { - DG(" do brace"); - if (IS_PIPESINGLE(*p)) - { - DG("is pipgesingle"); - if (process_redirect(p)) - set_exitstatus(1, 1); - else - ft_exec(&p->data.brace.content); - return (0); - } - else - return (plaunch_subshell(p)); + ft_exec(&p->data.brace.content); + return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); } diff --git a/42sh/src/exec/plaunch_builtin.c b/42sh/src/exec/plaunch_builtin.c index 4a937d65..f4506d45 100644 --- a/42sh/src/exec/plaunch_builtin.c +++ b/42sh/src/exec/plaunch_builtin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */ -/* Updated: 2017/03/14 22:34:53 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 20:22:12 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,32 +14,8 @@ int plaunch_builtin(t_process *p) { - pid_t pid; - - if (IS_PIPESINGLE(*p)) - { - if (process_redirect(p)) - { - set_exitstatus(1, 1); - return (0); - } - set_exitstatus((*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env), 1); - return (0); - } - pid = fork(); - if (pid == 0) - { - if (process_redirect(p)) - exit (1); - process_setgroup(p, 0); - process_setsig(); - exec_reset();///A FAIRE POUR LES BUILTIN OU PAS ? -> Q de William - // je pense ca ne change rien si on l'enleve car on excve apres - exit((*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env)); - } - else if (pid > 0) - return (pid); - else if (pid == -1) - ft_dprintf(2, "{red}%s: internal fork error{eoc}\n", SHELL_NAME); - return (0); + return ((*p->data.cmd.execf)( + p->data.cmd.path, + p->data.cmd.av, + data_singleton()->env)); } diff --git a/42sh/src/exec/plaunch_case.c b/42sh/src/exec/plaunch_case.c index 8c7e49b1..413c2ca8 100644 --- a/42sh/src/exec/plaunch_case.c +++ b/42sh/src/exec/plaunch_case.c @@ -6,13 +6,13 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:02:23 by wescande #+# #+# */ -/* Updated: 2017/03/15 01:10:32 by ariard ### ########.fr */ +/* Updated: 2017/03/17 20:17:07 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -static int do_case(t_process *p) +int plaunch_case(t_process *p) { t_exec *exec; @@ -23,29 +23,3 @@ static int do_case(t_process *p) ft_exec(&p->data.d_if.content); return (0); } - -int plaunch_case(t_process *p) -{ - pid_t pid; - - if (SH_IS_INTERACTIVE(data_singleton()->opts)) - { - pid = fork(); - if (pid == 0) - { - data_singleton()->opts &= ~SH_INTERACTIVE; - data_singleton()->opts &= ~SH_OPTS_JOBC; - process_setgroup(p, 0); - process_setsig(); - if (process_redirect(p)) - exit (1); - exec_reset(); - exit(do_case(p)); - } - else if (pid > 0) - return (pid); - } - else - do_case(p); - return (0); -} diff --git a/42sh/src/exec/plaunch_empty.c b/42sh/src/exec/plaunch_empty.c index 18630e16..39173fb8 100644 --- a/42sh/src/exec/plaunch_empty.c +++ b/42sh/src/exec/plaunch_empty.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 17:26:01 by jhalford #+# #+# */ -/* Updated: 2017/03/13 20:29:43 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 20:23:18 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,23 +14,7 @@ int plaunch_empty(t_process *p) { - int pid; - - pid = fork(); - if (pid == 0) - { - if (process_redirect(p)) - exit (1); - process_setgroup(p, 0); - process_setsig(); - exec_reset(); - DG("empty exit"); - exit(0); - } - else if (pid > 0) - return (pid); - else if (pid == -1) - ft_dprintf(2, "{red}%s: internal fork error{eoc}\n", SHELL_NAME); + (void)p; return (0); } diff --git a/42sh/src/exec/plaunch_file.c b/42sh/src/exec/plaunch_file.c index 472e349b..0ec58d4d 100644 --- a/42sh/src/exec/plaunch_file.c +++ b/42sh/src/exec/plaunch_file.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */ -/* Updated: 2017/03/15 23:11:53 by wescande ### ########.fr */ +/* Updated: 2017/03/17 20:22:38 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,34 +20,18 @@ static void error_launch(char *error_ori, char *error_type, int error_code) int plaunch_file(t_process *p) { - int pid; - - DG("plaunch_file"); - pid = fork(); - if (pid == 0) - { - /* data_singleton()->opts &= ~SH_INTERACTIVE; */ - /* data_singleton()->opts &= ~SH_OPTS_JOBC; */ - DG("fork! [%s]", p->data.cmd.av[0]); - if (process_redirect(p)) - exit (1); - process_setgroup(p, 0); - process_setsig(); - exec_reset(); - if (!p->data.cmd.path) - error_launch("command not found: ", p->data.cmd.av[0], 127); - else if (!p->data.cmd.stat) - error_launch(p->data.cmd.av[0], ": no such file or directory", 127); - else if (S_ISDIR(p->data.cmd.stat->st_mode)) - error_launch(p->data.cmd.av[0], ": is a directory", 126); - else if (access(p->data.cmd.path, X_OK) == -1) - error_launch("permission denied: ", p->data.cmd.av[0], 126); - (*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env); - error_launch("internal execve error on ", p->data.cmd.av[0], 42); - } - else if (pid > 0) - return (pid); - else if (pid == -1) - ft_dprintf(2, "{red}%s: internal fork error{eoc}\n", SHELL_NAME); + if (!p->data.cmd.path) + error_launch("command not found: ", p->data.cmd.av[0], 127); + else if (!p->data.cmd.stat) + error_launch(p->data.cmd.av[0], ": no such file or directory", 127); + else if (S_ISDIR(p->data.cmd.stat->st_mode)) + error_launch(p->data.cmd.av[0], ": is a directory", 126); + else if (access(p->data.cmd.path, X_OK) == -1) + error_launch("permission denied: ", p->data.cmd.av[0], 126); + (*p->data.cmd.execf)( + p->data.cmd.path, + p->data.cmd.av, + data_singleton()->env); + error_launch("internal execve error on ", p->data.cmd.av[0], 42); return (0); } diff --git a/42sh/src/exec/plaunch_for.c b/42sh/src/exec/plaunch_for.c index 560c46f2..c7c4d510 100644 --- a/42sh/src/exec/plaunch_for.c +++ b/42sh/src/exec/plaunch_for.c @@ -6,13 +6,13 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/15 00:49:20 by wescande #+# #+# */ -/* Updated: 2017/03/15 23:10:25 by wescande ### ########.fr */ +/* Updated: 2017/03/17 20:16:46 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -static int do_for(t_process *p) +int plaunch_for(t_process *p) { t_ld *temp; int i; @@ -38,29 +38,3 @@ static int do_for(t_process *p) } return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); } - -int plaunch_for(t_process *p) -{ - pid_t pid; - - if (SH_IS_INTERACTIVE(data_singleton()->opts)) - { - pid = fork(); - if (pid == 0) - { - data_singleton()->opts &= ~SH_INTERACTIVE; - data_singleton()->opts &= ~SH_OPTS_JOBC; - process_setgroup(p, 0); - process_setsig(); - if (process_redirect(p)) - exit (1); - exec_reset(); - exit(do_for(p)); - } - else if (pid > 0) - return (pid); - } - else - do_for(p); - return (0); -} diff --git a/42sh/src/exec/plaunch_function.c b/42sh/src/exec/plaunch_function.c index ed07ac41..d312345e 100644 --- a/42sh/src/exec/plaunch_function.c +++ b/42sh/src/exec/plaunch_function.c @@ -6,41 +6,15 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 03:23:59 by wescande #+# #+# */ -/* Updated: 2017/03/15 19:17:01 by ariard ### ########.fr */ +/* Updated: 2017/03/17 20:29:36 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -static int do_function(t_process *p) +int plaunch_function(t_process *p) { DG("do function"); ft_exec(&p->data.function.content); return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); } - -int plaunch_function(t_process *p) -{ - pid_t pid; - - if (SH_IS_INTERACTIVE(data_singleton()->opts)) - { - pid = fork(); - if (pid == 0) - { - data_singleton()->opts &= ~SH_INTERACTIVE; - data_singleton()->opts &= ~SH_OPTS_JOBC; - process_setgroup(p, 0); - process_setsig(); - if (process_redirect(p)) - exit (1); - exec_reset(); - exit(do_function(p)); - } - else if (pid > 0) - return (pid); - } - else - do_function(p); - return (0); -} diff --git a/42sh/src/exec/plaunch_if.c b/42sh/src/exec/plaunch_if.c index 3efe9b9e..dccd5209 100644 --- a/42sh/src/exec/plaunch_if.c +++ b/42sh/src/exec/plaunch_if.c @@ -6,44 +6,15 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:26:53 by wescande #+# #+# */ -/* Updated: 2017/03/15 02:04:23 by ariard ### ########.fr */ +/* Updated: 2017/03/17 20:30:36 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -static int do_if(t_process *p) +int plaunch_if(t_process *p) { - t_exec *exec; - - exec = &data_singleton()->exec; - exec->attrs &= ~EXEC_IF_BRANCH; + data_singleton()->exec.attrs &= ~EXEC_IF_BRANCH; ft_exec(&p->data.d_if.content); return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); } - -int plaunch_if(t_process *p) -{ - pid_t pid; - - if (SH_IS_INTERACTIVE(data_singleton()->opts)) - { - pid = fork(); - if (pid == 0) - { - data_singleton()->opts &= ~SH_INTERACTIVE; - data_singleton()->opts &= ~SH_OPTS_JOBC; - process_setgroup(p, 0); - process_setsig(); - if (process_redirect(p)) - exit (1); - exec_reset(); - exit(do_if(p)); - } - else if (pid > 0) - return (pid); - } - else - do_if(p); - return (0); -} diff --git a/42sh/src/exec/plaunch_subshell.c b/42sh/src/exec/plaunch_subshell.c index de2b3f2f..ef8cd15a 100644 --- a/42sh/src/exec/plaunch_subshell.c +++ b/42sh/src/exec/plaunch_subshell.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:11:44 by wescande #+# #+# */ -/* Updated: 2017/03/14 00:00:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 20:28:08 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,24 +14,6 @@ int plaunch_subshell(t_process *p) { - pid_t pid; - - pid = fork(); - if (pid == 0) - { - data_singleton()->opts &= ~SH_INTERACTIVE; - data_singleton()->opts &= ~SH_OPTS_JOBC; - if (process_redirect(p)) - exit (1); - process_setgroup(p, 0); - process_setsig(); - exec_reset(); - ft_exec(&p->data.subshell.content); - exit(ft_atoi(ft_getenv(data_singleton()->env, "?"))); - } - else if (pid > 0) - return (pid); - else if (pid == -1) - ft_dprintf(2, "{red}%s: internal fork error{eoc}\n", SHELL_NAME); - return (0); + ft_exec(&p->data.subshell.content); + exit(ft_atoi(ft_getenv(data_singleton()->env, "?"))); } diff --git a/42sh/src/exec/plaunch_until.c b/42sh/src/exec/plaunch_until.c index 96df7079..3d3cab25 100644 --- a/42sh/src/exec/plaunch_until.c +++ b/42sh/src/exec/plaunch_until.c @@ -6,13 +6,13 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 22:04:42 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 20:20:04 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -static int do_until(t_process *p) +int plaunch_until(t_process *p) { int ret; @@ -26,29 +26,3 @@ static int do_until(t_process *p) } return (ret); } - -int plaunch_until(t_process *p) -{ - pid_t pid; - - if (SH_IS_INTERACTIVE(data_singleton()->opts)) - { - pid = fork(); - if (pid == 0) - { - data_singleton()->opts &= ~SH_INTERACTIVE; - data_singleton()->opts &= ~SH_OPTS_JOBC; - process_setgroup(p, 0); - process_setsig(); - if (process_redirect(p)) - exit (1); - exec_reset(); - exit(do_until(p)); - } - else if (pid > 0) - return (pid); - } - else - do_until(p); - return (0); -} diff --git a/42sh/src/exec/plaunch_while.c b/42sh/src/exec/plaunch_while.c index 7f4ff6d5..db22b136 100644 --- a/42sh/src/exec/plaunch_while.c +++ b/42sh/src/exec/plaunch_while.c @@ -6,13 +6,13 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:20:53 by wescande #+# #+# */ -/* Updated: 2017/03/16 18:44:00 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 20:16:10 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -static int do_while(t_process *p) +int plaunch_while(t_process *p) { int ret; @@ -26,29 +26,3 @@ static int do_while(t_process *p) } return (ret); } - -int plaunch_while(t_process *p) -{ - pid_t pid; - - if (SH_IS_INTERACTIVE(data_singleton()->opts)) - { - pid = fork(); - if (pid == 0) - { - data_singleton()->opts &= ~SH_INTERACTIVE; - data_singleton()->opts &= ~SH_OPTS_JOBC; - process_setgroup(p, 0); - process_setsig(); - if (process_redirect(p)) - exit (1); - exec_reset(); - exit(do_while(p)); - } - else if (pid > 0) - return (pid); - } - else - do_while(p); - return (0); -} diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 52036dec..234fdd4d 100644 --- a/42sh/src/exec/process_launch.c +++ b/42sh/src/exec/process_launch.c @@ -6,60 +6,59 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */ -/* Updated: 2017/03/16 20:08:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 23:49:43 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int check_pipe(t_process *p) + +int do_the_muther_forker(t_process *p) { pid_t pid; - if (p->map.launch == plaunch_file) - return (0); - if (IS_PIPESINGLE(*p)) + if (IS_PIPESINGLE(*p) && p->type != PROCESS_FILE && p->type != PROCESS_SUBSHELL) { -/* if (process_redirect(p)) + if (process_redirect(p)) { set_exitstatus(1, 1); return (0); } - set_exitstatus((*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env), 1);*/ + set_exitstatus(p->map.launch(p), 1); return (0); } - pid = fork(); - if (!pid) + if ((pid = fork()) == -1) { - data_singleton()->opts &= ~SH_INTERACTIVE; - data_singleton()->opts &= ~SH_OPTS_JOBC; - if (process_redirect(p)) - exit (1); - process_setgroup(p, 0); - process_setsig(); - exec_reset(); + ft_dprintf(3, "{red}%s: internal fork error{eoc}\n", SHELL_NAME); + exit(1); } - return (pid); + else if (pid) + return (pid); + DG("START OF FORK"); + if (process_redirect(p)) + exit (1); + process_setgroup(p, 0); + process_setsig(); + exec_reset(); + data_singleton()->opts &= ~SH_INTERACTIVE; + data_singleton()->opts &= ~SH_OPTS_JOBC; + exit(p->map.launch(p)); } int process_launch(t_process *p) { pid_t pid; - /* pid_t manage_pid; */ DG("p->type=%i", p->type); p->attrs &= ~PROCESS_STATE_MASK; p->attrs |= PROCESS_RUNNING; - /* if (!(manage_pid = check_pipe(p))) */ - if (!(pid = (*p->map.launch)(p))) - { - DG("launcher did not fork!"); - process_resetfds(p); - return (1); - } - /* if (manage_pid) */ - /* pid = manage_pid; */ - DG("launcher forked!"); + if (!(pid = do_the_muther_forker(p))) + { + DG("launcher did not fork!"); + process_resetfds(p); + return (1); + } + DG("launcher forked! with : %d ", pid); p->pid = pid; process_setgroup(p, pid); if (p->fdin != STDIN) diff --git a/42sh/src/exec/process_setgroup.c b/42sh/src/exec/process_setgroup.c index 8664eac8..08b822e9 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/16 13:54:18 by jhalford ### ########.fr */ +/* Updated: 2017/03/18 00:23:57 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,7 +26,8 @@ int process_setgroup(t_process *p, pid_t pid) DG("setpgid(%i, %i)", pid, j->pgid); if (setpgid(pid, j->pgid) == -1) ft_dprintf(2, "{red}%s: internal setpgid() errno=%i{eoc}\n", SHELL_NAME, errno); - if (pid == 0 && JOB_IS_FG(j->attrs)) + /* if (JOB_IS_FG(j->attrs)) */ + if (pid ==0 && JOB_IS_FG(j->attrs)) { DG("tcsetpgrp[%i]", j->pgid); tcsetpgrp(STDIN, j->pgid); diff --git a/42sh/src/exec/process_setsig.c b/42sh/src/exec/process_setsig.c index 96b44ad1..21f96de6 100644 --- a/42sh/src/exec/process_setsig.c +++ b/42sh/src/exec/process_setsig.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 14:08:35 by jhalford #+# #+# */ -/* Updated: 2017/03/11 14:08:37 by jhalford ### ########.fr */ +/* Updated: 2017/03/18 00:16:37 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,12 +14,10 @@ void process_setsig(void) { - /* signal(SIGINT, SIG_DFL); */ + signal(SIGINT, SIG_DFL); signal(SIGQUIT, SIG_DFL); signal(SIGTSTP, SIG_DFL); signal(SIGTTIN, SIG_DFL); signal(SIGTTOU, SIG_DFL); - /* signal(SIGTTIN, sigttin_handler); */ - /* signal(SIGTTOU, sigttou_handler); */ signal(SIGCHLD, SIG_DFL); } diff --git a/42sh/src/job-control/do_job_notification.c b/42sh/src/job-control/do_job_notification.c index 09ff6659..8bec9af4 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/16 18:35:01 by jhalford ### ########.fr */ +/* Updated: 2017/03/18 00:07:12 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,8 +33,7 @@ int do_job_notification(void) ret = 1; job_notify_change(j->id); j->attrs |= JOB_NOTIFIED; - if (job_is_completed(j->id)) - job_remove(j->id); + job_remove(j->id); } } return (ret); diff --git a/42sh/src/job-control/job_addprocess.c b/42sh/src/job-control/job_addprocess.c index 9ad707f9..fb77e1fc 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/16 22:23:24 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 23:06:08 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,7 +29,7 @@ int job_addprocess(t_process *p) } job = jobc->first_job->content; ft_lsteadd(&job->first_process, ft_lstnew(p, sizeof(*p))); - if (JOB_IS_BG(job->attrs) && IS_PIPEEND(*p)) - job_notify_new(job); + /* if (JOB_IS_BG(job->attrs) && IS_PIPEEND(*p)) */ + /* job_notify_new(job); */ return (0); } diff --git a/42sh/src/job-control/job_notify_change.c b/42sh/src/job-control/job_notify_change.c index 9535b95a..fa0e8a3e 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/03/08 17:18:20 by jhalford ### ########.fr */ +/* Updated: 2017/03/18 00:51:40 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,5 +19,6 @@ void job_notify_change(int id) jobc = &data_singleton()->jobc; job = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content; - job_format(job, JOBS_OPTS_L); +// if (job->attrs & JOB_BG) utilise pour notif dynamic + job_format(job, JOBS_OPTS_L); } diff --git a/42sh/src/job-control/job_notify_new.c b/42sh/src/job-control/job_notify_new.c index ac26426c..dd7068f2 100644 --- a/42sh/src/job-control/job_notify_new.c +++ b/42sh/src/job-control/job_notify_new.c @@ -6,19 +6,25 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:27:01 by jhalford #+# #+# */ -/* Updated: 2017/03/10 15:36:10 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 23:10:47 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -void job_notify_new(t_job *job) +void job_notify_new(int id) { t_list *plist; t_process *p; + t_jobc *jobc; + t_job *job; - ft_printf("{mag}[%i]", job->id); + jobc = &data_singleton()->jobc; + if (!(plist = ft_lst_find(jobc->first_job, &id, job_cmp_id))) + return ; + job = plist->content; plist = job->first_process; + ft_printf("{mag}[%i]", job->id); while (plist) { p = plist->content; diff --git a/42sh/src/job-control/sigchld_handler.c b/42sh/src/job-control/sigchld_handler.c index 22d4c8a6..f9201c27 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/08 17:21:34 by jhalford ### ########.fr */ +/* Updated: 2017/03/18 00:05:39 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,5 +14,6 @@ void sigchld_handler(int signo) { + //do_job_notification();dynamic notif ??? (void)signo; } diff --git a/42sh/src/line-editing/ft_prompt.c b/42sh/src/line-editing/ft_prompt.c index bf6626f3..b3a6331d 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/03/16 16:43:35 by gwojda ### ########.fr */ +/* Updated: 2017/03/18 00:14:42 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index a8441c2e..0ef8b902 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/17 21:18:46 by jhalford ### ########.fr */ +/* Updated: 2017/03/18 00:04:33 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -62,12 +62,12 @@ static int interactive_settings(void) shell_pgid = &data->jobc.shell_pgid; while (tcgetpgrp(STDIN) != (*shell_pgid = getpgrp())) kill(-*shell_pgid, SIGTTIN); - signal(SIGINT, sigint_handler); + signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); - signal(SIGTSTP, sigtstp_handler); + signal(SIGTSTP, SIG_IGN); signal(SIGTTIN, SIG_IGN); signal(SIGTTOU, SIG_IGN); - signal(SIGCHLD, SIG_DFL); + signal(SIGCHLD, SIG_DFL);//sigchld_handler); TBC IF dynamic notification are wanted *shell_pgid = getpid(); if (setpgid(*shell_pgid, *shell_pgid)) {