diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 302c2a52..42f3da0c 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/20 09:46:31 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 10:35:30 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,13 +17,6 @@ # include "job_control.h" # include -# define PROCESS_COMPLETED (1 << 0) -# define PROCESS_SUSPENDED (1 << 1) -# define PROCESS_RUNNING (1 << 2) -# define PROCESS_CONTINUED (1 << 3) - -# define PROCESS_STATE_MASK ((1 << 4) - (1 << 0)) - # define IS_PIPESTART(p) ((p).fdin == STDIN) # define IS_PIPEEND(p) ((p).fdout == STDOUT) # define IS_PIPESINGLE(p) (IS_PIPESTART(p) && IS_PIPEEND(p)) @@ -80,6 +73,14 @@ union u_process_data struct s_data_list d_case; }; +enum e_process_state +{ + PROCESS_COMPLETED, + PROCESS_SUSPENDED, + PROCESS_RUNNING, + PROCESS_CONTINUED, +}; + enum e_process_type { PROCESS_FUNCTION, @@ -109,13 +110,13 @@ struct s_process t_process_type type; t_process_data data; t_process_map map; + t_process_state state; pid_t pid; int fdin; int fdout; int to_close; t_list *redirs; int status; - t_flag attrs; }; struct s_job diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index e4687eca..4d65e4f3 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ -/* Updated: 2017/03/20 09:37:28 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 10:35:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/types.h b/42sh/includes/types.h index a275a8fa..726270b3 100644 --- a/42sh/includes/types.h +++ b/42sh/includes/types.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */ -/* Updated: 2017/03/17 00:06:21 by ariard ### ########.fr */ +/* Updated: 2017/03/20 10:38:12 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -62,6 +62,7 @@ typedef int (t_execf)(const char *path, char *const argv[], char *const envp[]); typedef enum e_process_type t_process_type; +typedef enum e_process_state t_process_state; typedef union u_process_data t_process_data; typedef struct s_process_map t_process_map; typedef struct s_data_cond t_data_while; diff --git a/42sh/libft/src/ft_printf/ft_transform.c b/42sh/libft/src/ft_printf/ft_transform.c index 94bfc6ac..67abd6e1 100644 --- a/42sh/libft/src/ft_printf/ft_transform.c +++ b/42sh/libft/src/ft_printf/ft_transform.c @@ -6,25 +6,12 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/07 13:33:32 by jhalford #+# #+# */ -/* Updated: 2017/03/20 09:23:01 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 10:26:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_printf.h" -enum e_conversion = -{ - CONV_D, - CONV_I, - CONV_U, - CONV_O, - CONV_x, - CONV_X, - CONV_B, - CONV_S, - CONV_C, -}; - char *ft_transform(t_fmt *fmt, va_list ap) { char *ret; diff --git a/42sh/src/exec/ast_free.c b/42sh/src/exec/ast_free.c index 54f30952..9ec0e141 100644 --- a/42sh/src/exec/ast_free.c +++ b/42sh/src/exec/ast_free.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */ -/* Updated: 2017/03/18 18:17:20 by ariard ### ########.fr */ +/* Updated: 2017/03/20 10:24:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/bad_fd.c b/42sh/src/exec/bad_fd.c index 031c26cf..8851abcd 100644 --- a/42sh/src/exec/bad_fd.c +++ b/42sh/src/exec/bad_fd.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:32:43 by jhalford #+# #+# */ -/* Updated: 2017/02/07 16:02:12 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 10:24:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 9de326b8..86881c51 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/17 23:10:43 by wescande ### ########.fr */ +/* Updated: 2017/03/20 10:54:59 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,7 +49,6 @@ int exec_leaf(t_btree **ast) job_notify_new(job->id); job->pgid = 0; } - DG("check"); } return (0); } diff --git a/42sh/src/exec/mark_process_status.c b/42sh/src/exec/mark_process_status.c index 7f6470a6..6762e9e7 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/18 00:04:46 by wescande ### ########.fr */ +/* Updated: 2017/03/20 10:40:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,18 +22,12 @@ int mark_process_status(pid_t pid, int status) p = plist->content; p->status = status; if (WIFSTOPPED(status)) - { - p->attrs &= ~PROCESS_STATE_MASK; - p->attrs |= PROCESS_SUSPENDED; - } + p->state = PROCESS_SUSPENDED; else { - p->attrs &= ~PROCESS_STATE_MASK; - p->attrs |= PROCESS_COMPLETED; + p->state = PROCESS_COMPLETED; if (WIFSIGNALED(status)) - psignal(WTERMSIG(status), NULL); - /* ft_printf("{mag}%d: Terminated by signal %d.\n{eoc}", */ - /* (int)pid, WTERMSIG(status)); */ + ft_dprintf(2, "%s\n", strsignal((WTERMSIG(status)))); } return (0); } diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 234fdd4d..4bd9d9bc 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 23:49:43 by wescande ### ########.fr */ +/* Updated: 2017/03/20 10:35:14 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,8 +50,7 @@ int process_launch(t_process *p) pid_t pid; DG("p->type=%i", p->type); - p->attrs &= ~PROCESS_STATE_MASK; - p->attrs |= PROCESS_RUNNING; + p->state = PROCESS_RUNNING; if (!(pid = do_the_muther_forker(p))) { DG("launcher did not fork!"); diff --git a/42sh/src/exec/process_set.c b/42sh/src/exec/process_set.c index fb6c739b..b3f61ed8 100644 --- a/42sh/src/exec/process_set.c +++ b/42sh/src/exec/process_set.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/19 16:00:16 by wescande ### ########.fr */ +/* Updated: 2017/03/20 10:57:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pset_brace.c b/42sh/src/exec/pset_brace.c index b9997a48..a61a3792 100644 --- a/42sh/src/exec/pset_brace.c +++ b/42sh/src/exec/pset_brace.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 19:07:34 by jhalford #+# #+# */ -/* Updated: 2017/03/13 20:31:21 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 10:29:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pset_case.c b/42sh/src/exec/pset_case.c index bbc0ddb6..5e373168 100644 --- a/42sh/src/exec/pset_case.c +++ b/42sh/src/exec/pset_case.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 20:36:04 by wescande #+# #+# */ -/* Updated: 2017/03/15 01:46:29 by ariard ### ########.fr */ +/* Updated: 2017/03/20 10:27:59 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pset_cmd.c b/42sh/src/exec/pset_cmd.c index 8f09fecb..3e7f6139 100644 --- a/42sh/src/exec/pset_cmd.c +++ b/42sh/src/exec/pset_cmd.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:06:05 by wescande #+# #+# */ -/* Updated: 2017/03/19 16:42:10 by wescande ### ########.fr */ +/* Updated: 2017/03/20 10:28:38 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pset_for.c b/42sh/src/exec/pset_for.c index 3049e566..19573f9c 100644 --- a/42sh/src/exec/pset_for.c +++ b/42sh/src/exec/pset_for.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:38:05 by wescande #+# #+# */ -/* Updated: 2017/03/15 01:57:17 by ariard ### ########.fr */ +/* Updated: 2017/03/20 10:28:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pset_if.c b/42sh/src/exec/pset_if.c index 5d29ef80..130af429 100644 --- a/42sh/src/exec/pset_if.c +++ b/42sh/src/exec/pset_if.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:19:50 by wescande #+# #+# */ -/* Updated: 2017/03/15 02:03:19 by ariard ### ########.fr */ +/* Updated: 2017/03/20 10:27:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pset_subshell.c b/42sh/src/exec/pset_subshell.c index bbe43f32..e21b35de 100644 --- a/42sh/src/exec/pset_subshell.c +++ b/42sh/src/exec/pset_subshell.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:02:01 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:31:21 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 10:28:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pset_until.c b/42sh/src/exec/pset_until.c index 120c12d6..c5b91a3f 100644 --- a/42sh/src/exec/pset_until.c +++ b/42sh/src/exec/pset_until.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 22:22:24 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:31:21 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 10:27:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pset_while.c b/42sh/src/exec/pset_while.c index 8360e2be..f8d92c2f 100644 --- a/42sh/src/exec/pset_while.c +++ b/42sh/src/exec/pset_while.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:38:10 by wescande #+# #+# */ -/* Updated: 2017/03/13 20:31:19 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 10:27:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/token_to_argv.c b/42sh/src/exec/token_to_argv.c index 0e1ea38b..34547a15 100644 --- a/42sh/src/exec/token_to_argv.c +++ b/42sh/src/exec/token_to_argv.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:55:53 by wescande #+# #+# */ -/* Updated: 2017/03/14 22:39:25 by ariard ### ########.fr */ +/* Updated: 2017/03/20 10:24:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/builtin_fg.c b/42sh/src/job_control/builtin_fg.c index df1cf8c1..0201de78 100644 --- a/42sh/src/job_control/builtin_fg.c +++ b/42sh/src/job_control/builtin_fg.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/08 14:30:07 by jhalford #+# #+# */ -/* Updated: 2017/03/10 16:27:01 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 11:00:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,16 +27,23 @@ int builtin_fg(const char *path, char *const av[], char *const envp[]) return (-1); } jobc = &data_singleton()->jobc; - job_getrank(&rank); - id = av[1] ? ft_atoi(av[1]) : rank[0]; - if ((jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id))) + job_getrank(&rank); + if (av[1] ? (id = *av[1]) : 0) { - job_run(jlist->content, 1); - return (0); + if ((jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id))) + job_run(jlist->content, 1); + else + ft_dprintf(2, "{red}fg: job not found: [%i]{eoc}\n", id); } - else if (av[1]) - ft_dprintf(2, "{red}fg: job not found: [%i]{eoc}\n", id); else - ft_dprintf(2, "{red}fg: no current job{eoc}\n"); - return (1); + { + DG("rank:%i:%i", rank[0], rank[1]); + if ((jlist = ft_lst_find(jobc->first_job, &rank[0], job_cmp_id))) + job_run(jlist->content, 1); + else if ((jlist = ft_lst_find(jobc->first_job, &rank[1], job_cmp_id))) + job_run(jlist->content, 1); + else + ft_dprintf(2, "{red}fg: no current job{eoc}\n"); + } + return (0); } diff --git a/42sh/src/job_control/job_addprocess.c b/42sh/src/job_control/job_addprocess.c index fb77e1fc..02181cb8 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/17 23:06:08 by wescande ### ########.fr */ +/* Updated: 2017/03/20 10:57:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,7 +29,5 @@ 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); */ return (0); } diff --git a/42sh/src/job_control/job_getrank.c b/42sh/src/job_control/job_getrank.c index 6da80d6b..8c766f23 100644 --- a/42sh/src/job_control/job_getrank.c +++ b/42sh/src/job_control/job_getrank.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 12:38:31 by jhalford #+# #+# */ -/* Updated: 2017/01/31 15:04:33 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 11:10:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/job_is_completed.c b/42sh/src/job_control/job_is_completed.c index 8a6712d4..83bc6ecb 100644 --- a/42sh/src/job_control/job_is_completed.c +++ b/42sh/src/job_control/job_is_completed.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 15:10:20 by jhalford #+# #+# */ -/* Updated: 2017/03/16 18:26:29 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 11:10:14 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,7 @@ int job_is_completed(int id) while (lst) { p = lst->content; - if (!(p->attrs & PROCESS_COMPLETED)) + if (!(p->state == PROCESS_COMPLETED)) return (0); lst = lst->next; } diff --git a/42sh/src/job_control/job_is_stopped.c b/42sh/src/job_control/job_is_stopped.c index 2f71c258..45c0cb64 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/16 18:26:27 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 11:10:12 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,8 @@ int job_is_stopped(int id) while (lst) { p = lst->content; - if (!(p->attrs & (PROCESS_COMPLETED | PROCESS_SUSPENDED))) + if (!(p->state == PROCESS_COMPLETED) + || !(p->state == PROCESS_SUSPENDED)) return (0); lst = lst->next; } diff --git a/42sh/src/job_control/job_notify_change.c b/42sh/src/job_control/job_notify_change.c index fa0e8a3e..96c750dc 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/18 00:51:40 by wescande ### ########.fr */ +/* Updated: 2017/03/20 10:21:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,5 @@ void job_notify_change(int id) jobc = &data_singleton()->jobc; job = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content; -// if (job->attrs & JOB_BG) utilise pour notif dynamic - job_format(job, JOBS_OPTS_L); + job_format(job, JOBS_OPTS_L); } diff --git a/42sh/src/job_control/job_remove.c b/42sh/src/job_control/job_remove.c index 46b33738..782aa632 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/16 18:29:43 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 10:20:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,8 +15,8 @@ void job_remove(int id) { t_jobc *jobc; - t_job *j; - t_list *jlist; + t_job *j; + t_list *jlist; t_process *p; jobc = &data_singleton()->jobc; diff --git a/42sh/src/job_control/job_run.c b/42sh/src/job_control/job_run.c index 412af6df..7dae037f 100644 --- a/42sh/src/job_control/job_run.c +++ b/42sh/src/job_control/job_run.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 16:54:18 by jhalford #+# #+# */ -/* Updated: 2017/01/31 14:47:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 10:40:16 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/mark_job_as_running.c b/42sh/src/job_control/mark_job_as_running.c index ae34335f..eb4b8623 100644 --- a/42sh/src/job_control/mark_job_as_running.c +++ b/42sh/src/job_control/mark_job_as_running.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/08 14:40:40 by jhalford #+# #+# */ -/* Updated: 2017/03/06 12:30:50 by wescande ### ########.fr */ +/* Updated: 2017/03/20 10:56:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,11 +21,8 @@ void mark_job_as_running(t_job *j) while (plist) { p = plist->content; - if (p->attrs & PROCESS_SUSPENDED) - { - p->attrs &= ~PROCESS_STATE_MASK; - p->attrs |= PROCESS_CONTINUED; - } + if (p->state == PROCESS_SUSPENDED) + p->state = PROCESS_CONTINUED; plist = plist->next; } j->attrs &= ~JOB_NOTIFIED; diff --git a/42sh/src/job_control/process_format.c b/42sh/src/job_control/process_format.c index 783fea8c..d6e54143 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/17 21:35:27 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 10:54:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,22 +34,19 @@ static int redirection_print(t_redir *redir) static void process_format_state(t_process *p) { - int state; char *statestr; - state = p->attrs & PROCESS_STATE_MASK; statestr = NULL; - if (state == PROCESS_RUNNING) + if (p->state == PROCESS_RUNNING) ft_asprintf(&statestr, "running"); - else if (state == PROCESS_SUSPENDED) + else if (p->state == PROCESS_SUSPENDED) ft_asprintf(&statestr, "suspended"); - else if (state == PROCESS_CONTINUED) + else if (p->state == PROCESS_CONTINUED) { ft_asprintf(&statestr, "continued"); - p->attrs &= ~PROCESS_STATE_MASK; - p->attrs |= PROCESS_RUNNING; + p->state = PROCESS_RUNNING; } - else if (state == PROCESS_COMPLETED) + else if (p->state == PROCESS_COMPLETED) { if (WIFSIGNALED(p->status)) ft_asprintf(&statestr, strsignal(WTERMSIG(p->status))); @@ -82,14 +79,10 @@ static void process_format_com_short(t_list **plist, t_flag state) while (*plist) { p = (*plist)->content; - if (!(p->attrs & state) || - (state == PROCESS_COMPLETED && p->status != 0)) + if (p->state != state) break ; - if (p->attrs & PROCESS_CONTINUED) - { - p->attrs &= ~PROCESS_STATE_MASK; - p->attrs &= ~PROCESS_RUNNING; - } + if (p->state == PROCESS_CONTINUED) + p->state = PROCESS_RUNNING; if (p->map.print) (p->map.print)(p); ft_lstiter(p->redirs, redirection_print); @@ -102,10 +95,8 @@ static void process_format_com_short(t_list **plist, t_flag state) void process_format(t_list **plist, int firstp, int opts) { t_process *p; - t_flag state; p = (*plist)->content; - state = p->attrs & PROCESS_STATE_MASK; if (!firstp) ft_printf(" "); if (opts & JOBS_OPTS_L) @@ -114,6 +105,6 @@ void process_format(t_list **plist, int firstp, int opts) if (opts & JOBS_OPTS_L) process_format_com_long(plist); else - process_format_com_short(plist, state); + process_format_com_short(plist, p->state); ft_putchar('\n'); } diff --git a/42sh/src/job_control/sigchld_handler.c b/42sh/src/job_control/sigchld_handler.c index f9201c27..d7ddade0 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/18 00:05:39 by wescande ### ########.fr */ +/* Updated: 2017/03/20 10:20:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,5 @@ void sigchld_handler(int signo) { - //do_job_notification();dynamic notif ??? (void)signo; } diff --git a/42sh/src/job_control/sigttou_handler.c b/42sh/src/job_control/sigttou_handler.c index a710c83e..f411d744 100644 --- a/42sh/src/job_control/sigttou_handler.c +++ b/42sh/src/job_control/sigttou_handler.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 15:14:53 by jhalford #+# #+# */ -/* Updated: 2017/03/14 10:55:49 by gwojda ### ########.fr */ +/* Updated: 2017/03/20 10:30:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/get_state_global.c b/42sh/src/lexer/get_state_global.c index 44acee6b..31701a10 100644 --- a/42sh/src/lexer/get_state_global.c +++ b/42sh/src/lexer/get_state_global.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */ -/* Updated: 2017/03/20 10:02:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 10:02:52 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index 11ac219f..9d9ee45c 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/20 09:54:18 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 11:21:53 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,11 +34,8 @@ static int get_input_fd(t_data *data) char *file; struct stat buf; - /* fds = (int[2]){-1, STDIN}; */ - if (data->opts & SH_OPTS_LC) + if (data->opts & SH_OPTS_LC && (file = data->c_arg)) { - DG("-c"); - file = data->c_arg; pipe(fds); write(fds[PIPE_WRITE], file, ft_strlen(file)); close(fds[PIPE_WRITE]); @@ -51,8 +48,11 @@ static int get_input_fd(t_data *data) ft_printf("{red}%s: %s: No such file or directory\n{eoc}", data->argv[0], file); } - fds[PIPE_WRITE] = fds[PIPE_READ] != -1 ? - fcntl(fds[PIPE_READ], F_DUPFD_CLOEXEC, 10) : STDIN; + else + return (STDIN); + if (fds[PIPE_READ] < 0) + return (-1); + fds[PIPE_WRITE] = fcntl(fds[PIPE_READ], F_DUPFD_CLOEXEC, 10); close(fds[PIPE_READ]); return (fds[PIPE_WRITE]); } diff --git a/42sh/src/parser/tree_wrapper.c b/42sh/src/parser/tree_wrapper.c index f5523c97..51002717 100644 --- a/42sh/src/parser/tree_wrapper.c +++ b/42sh/src/parser/tree_wrapper.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 18:57:44 by ariard #+# #+# */ -/* Updated: 2017/03/14 00:36:34 by ariard ### ########.fr */ +/* Updated: 2017/03/20 10:35:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */