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/includes/libft.h b/42sh/libft/includes/libft.h index 56cdf59b..986cda46 100644 --- a/42sh/libft/includes/libft.h +++ b/42sh/libft/includes/libft.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ -/* Updated: 2017/03/15 20:51:55 by ariard ### ########.fr */ +/* Updated: 2017/03/17 21:30:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft/src/ft_printf/ft_printf.c b/42sh/libft/src/ft_printf/ft_printf.c index fb813acd..f392b79e 100644 --- a/42sh/libft/src/ft_printf/ft_printf.c +++ b/42sh/libft/src/ft_printf/ft_printf.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */ -/* Updated: 2017/03/14 20:24:44 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 21:33:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/builtin/is_builtin.c b/42sh/src/builtin/is_builtin.c index 270c70ef..4f9cc686 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 19:51:06 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 23:33:54 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 807f1d95..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 22:55:09 by wescande ### ########.fr */ +/* Updated: 2017/03/18 00:04:46 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,23 +19,21 @@ int mark_process_status(pid_t pid, int status) if ((plist = job_getprocess(pid))) { - DG("#######################"); p = plist->content; p->status = status; if (WIFSTOPPED(status)) { - DG("#######################"); p->attrs &= ~PROCESS_STATE_MASK; p->attrs |= PROCESS_SUSPENDED; } else { - DG("#######################"); p->attrs &= ~PROCESS_STATE_MASK; p->attrs |= PROCESS_COMPLETED; - if (WIFSIGNALED(status) && DEBUG_MODE) - ft_printf("{mag}%d: Terminated by signal %d.\n{eoc}", - (int)pid, WTERMSIG(status)); + if (WIFSIGNALED(status)) + psignal(WTERMSIG(status), NULL); + /* ft_printf("{mag}%d: Terminated by signal %d.\n{eoc}", */ + /* (int)pid, WTERMSIG(status)); */ } return (0); } diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 20fe1e87..234fdd4d 100644 --- a/42sh/src/exec/process_launch.c +++ b/42sh/src/exec/process_launch.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */ -/* Updated: 2017/03/17 22:49:31 by wescande ### ########.fr */ +/* Updated: 2017/03/17 23:49:43 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,12 +35,6 @@ int do_the_muther_forker(t_process *p) else if (pid) return (pid); DG("START OF FORK"); - signal(SIGINT, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - signal(SIGTSTP, SIG_DFL); - signal(SIGTTIN, SIG_DFL); - signal(SIGTTOU, SIG_DFL); - signal(SIGCHLD, SIG_DFL); if (process_redirect(p)) exit (1); process_setgroup(p, 0); 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 94e43f14..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/17 22:53:45 by wescande ### ########.fr */ +/* Updated: 2017/03/18 00:07:12 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,19 +27,14 @@ int do_job_notification(void) { j = jlist->content; jlist = jlist->next; - DG(); - if (job_is_completed(j->id)) - DG(); if (job_is_completed(j->id) || (job_is_stopped(j->id) && !(j->attrs & JOB_NOTIFIED))) { - DG(); ret = 1; job_notify_change(j->id); j->attrs |= JOB_NOTIFIED; job_remove(j->id); } - DG(); } 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_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/process_format.c b/42sh/src/job-control/process_format.c index facaad6f..783fea8c 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/16 16:41:10 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 21:35:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,27 +34,32 @@ static int redirection_print(t_redir *redir) static void process_format_state(t_process *p) { - int state; + int state; + char *statestr; state = p->attrs & PROCESS_STATE_MASK; + statestr = NULL; if (state == PROCESS_RUNNING) - ft_putstr("running "); + ft_asprintf(&statestr, "running"); else if (state == PROCESS_SUSPENDED) - ft_putstr("suspended"); + ft_asprintf(&statestr, "suspended"); else if (state == PROCESS_CONTINUED) { - ft_putstr("continued"); + ft_asprintf(&statestr, "continued"); p->attrs &= ~PROCESS_STATE_MASK; p->attrs |= PROCESS_RUNNING; } else if (state == PROCESS_COMPLETED) { - if (p->status == 0) - ft_putstr("done "); + if (WIFSIGNALED(p->status)) + ft_asprintf(&statestr, strsignal(WTERMSIG(p->status))); + else if (p->status == 0) + ft_asprintf(&statestr, "done"); else - ft_printf("exit %i ", p->status); + ft_asprintf(&statestr, "%s %i", "exit", WEXITSTATUS(p->status)); } - ft_putchar('\t'); + ft_printf("%-*s\t", 12, statestr); + ft_strdel(&statestr); } static void process_format_com_long(t_list **plist) diff --git a/42sh/src/job-control/sigchld_handler.c b/42sh/src/job-control/sigchld_handler.c index 1f83749f..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/17 22:39:21 by wescande ### ########.fr */ +/* Updated: 2017/03/18 00:05:39 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,6 @@ void sigchld_handler(int signo) { - DG("<<<<<<<<<<<<<<<<<<<<<<<<<<<"); - do_job_notification(); + //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 4bdae5e0..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/17 22:41:13 by wescande ### ########.fr */ +/* Updated: 2017/03/18 00:14:42 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -107,9 +107,7 @@ void ft_prompt(void) ft_printf("\x1b[38;5;10m➜ "); ft_putstr("\x1b[38;5;361m"); ret += ft_currend_dir(); - signal(SIGCHLD, SIG_DFL); ret += ft_git_status(); - signal(SIGCHLD, sigchld_handler); ft_putstr("\033[22;37m"); data_singleton()->line.prompt_size = ret + 4; } diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 71d87f6b..7c901196 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/17 21:16:25 by jhalford ### ########.fr */ +/* Updated: 2017/03/17 21:18:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index 519c04ff..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 22:38:39 by wescande ### ########.fr */ +/* Updated: 2017/03/18 00:04:33 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,7 +67,7 @@ static int interactive_settings(void) signal(SIGTSTP, SIG_IGN); signal(SIGTTIN, SIG_IGN); signal(SIGTTOU, SIG_IGN); - signal(SIGCHLD, sigchld_handler); + signal(SIGCHLD, SIG_DFL);//sigchld_handler); TBC IF dynamic notification are wanted *shell_pgid = getpid(); if (setpgid(*shell_pgid, *shell_pgid)) {