From 9d02933f729b0d6463e24cbdb8070889a45701a3 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 9 Jan 2017 17:00:56 +0100 Subject: [PATCH] builtin_bg done, doesnt take arguments yet --- 42sh/includes/builtin.h | 3 +- 42sh/includes/exec.h | 5 ++-- 42sh/includes/job_control.h | 2 +- 42sh/src/builtin/is_builtin.c | 3 +- 42sh/src/exec/launch_process.c | 6 ++-- 42sh/src/job-control/builtin_bg.c | 35 ++++++++++++++++++++++ 42sh/src/job-control/builtin_fg.c | 2 +- 42sh/src/job-control/job_format.c | 2 +- 42sh/src/job-control/job_kill_all.c | 2 +- 42sh/src/job-control/job_notify_change.c | 4 +-- 42sh/src/job-control/job_remove.c | 7 +---- 42sh/src/job-control/mark_job_as_running.c | 4 +-- 42sh/src/job-control/process_format.c | 15 ++++++++-- 42sh/src/job-control/sigtstp_handler.c | 2 +- 42sh/src/job-control/sigttin_handler.c | 2 +- 42sh/src/main/shell_exit.c | 2 +- 16 files changed, 70 insertions(+), 26 deletions(-) create mode 100644 42sh/src/job-control/builtin_bg.c diff --git a/42sh/includes/builtin.h b/42sh/includes/builtin.h index e54018ed..42f2543a 100644 --- a/42sh/includes/builtin.h +++ b/42sh/includes/builtin.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:21:56 by jhalford #+# #+# */ -/* Updated: 2017/01/08 14:34:40 by jhalford ### ########.fr */ +/* Updated: 2017/01/09 16:57:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,5 +25,6 @@ int builtin_setenv(const char *path, char *const argv[], char *const envp[]); int builtin_unsetenv(const char *path, char *const argv[], char *const envp[]); int builtin_jobs(const char *path, char *const av[], char *const envp[]); int builtin_fg(const char *path, char *const av[], char *const envp[]); +int builtin_bg(const char *path, char *const av[], char *const envp[]); #endif diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index b3346742..5d047b1b 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/01/09 16:22:39 by jhalford ### ########.fr */ +/* Updated: 2017/01/09 16:58:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,9 +25,10 @@ # define PROCESS_COMPLETED (1 << 6) # define PROCESS_SUSPENDED (1 << 7) # define PROCESS_RUNNING (1 << 8) +# define PROCESS_CONTINUED (1 << 9) # define PROCESS_TYPE_MASK (1 << 0 | 1 << 1 | 1 << 2 | 1 << 3) -# define PROCESS_STATE_MASK (1 << 6 | 1 << 7 | 1 << 8) +# define PROCESS_STATE_MASK (1 << 6 | 1 << 7 | 1 << 8 | 1 << 9) # define IS_PIPESTART(a) (a & PROCESS_PIPESTART) # define IS_PIPEEND(a) (a & PROCESS_PIPEEND) diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index f83713c0..bea10d93 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/01/09 16:23:37 by jhalford ### ########.fr */ +/* Updated: 2017/01/09 16:56:18 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/builtin/is_builtin.c b/42sh/src/builtin/is_builtin.c index f0f653a5..7dbdda0c 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/01/08 14:30:52 by jhalford ### ########.fr */ +/* Updated: 2017/01/09 16:58:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,7 @@ t_stof g_builtin[] = { {"exit", &builtin_exit}, {"jobs", &builtin_jobs}, {"fg", &builtin_fg}, + {"bg", &builtin_bg}, {NULL, NULL}, }; diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index b07ede0f..1ca9757e 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/01/09 16:00:07 by jhalford ### ########.fr */ +/* Updated: 2017/01/09 16:38:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,8 +44,8 @@ int launch_process(t_process *p) signal(SIGINT, SIG_DFL); signal(SIGQUIT, SIG_DFL); signal(SIGTSTP, sigtstp_handler); - signal(SIGTTIN, SIG_DFL); - signal(SIGTTOU, SIG_DFL); + signal(SIGTTIN, sigttin_handler); + signal(SIGTTOU, sigttou_handler); signal(SIGCHLD, SIG_DFL); process_redirect(p); (*p->execf)(p->path, p->av, data_singleton()->env); diff --git a/42sh/src/job-control/builtin_bg.c b/42sh/src/job-control/builtin_bg.c new file mode 100644 index 00000000..427bf7d2 --- /dev/null +++ b/42sh/src/job-control/builtin_bg.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* builtin_bg.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/09 16:54:18 by jhalford #+# #+# */ +/* Updated: 2017/01/09 16:57:20 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + + +#include "job_control.h" + +int builtin_bg(const char *path, char *const av[], char *const envp[]) +{ + t_jobc *jobc; + t_job *job; + int rank[2]; + + (void)path; + (void)envp; + (void)av; + jobc = &data_singleton()->jobc; + job = jobc->first_job->content; + job_getrank(&rank); + if (job) + { + mark_job_as_running(job); + job_format(job, rank, JOBS_OPTS_L); + put_job_in_background(job, 1); + } + return (0); +} diff --git a/42sh/src/job-control/builtin_fg.c b/42sh/src/job-control/builtin_fg.c index d538d039..2f350ea6 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/01/08 15:21:23 by jhalford ### ########.fr */ +/* Updated: 2017/01/09 16:54:39 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_format.c b/42sh/src/job-control/job_format.c index 58ee1a10..0117d3f8 100644 --- a/42sh/src/job-control/job_format.c +++ b/42sh/src/job-control/job_format.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 12:47:17 by jhalford #+# #+# */ -/* Updated: 2017/01/09 14:05:06 by jhalford ### ########.fr */ +/* Updated: 2017/01/09 16:55:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_kill_all.c b/42sh/src/job-control/job_kill_all.c index 158b716a..1d36a8a6 100644 --- a/42sh/src/job-control/job_kill_all.c +++ b/42sh/src/job-control/job_kill_all.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/08 15:36:56 by jhalford #+# #+# */ -/* Updated: 2017/01/09 16:25:25 by jhalford ### ########.fr */ +/* Updated: 2017/01/09 16:35:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_notify_change.c b/42sh/src/job-control/job_notify_change.c index d1e4a292..7d0c4ead 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/09 16:24:32 by jhalford ### ########.fr */ +/* Updated: 2017/01/09 16:49:16 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,5 +21,5 @@ void job_notify_change(int id) jobc = &data_singleton()->jobc; job = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content; job_getrank(&rank); - job_format(job, rank, 0); + job_format(job, rank, JOBS_OPTS_L); } diff --git a/42sh/src/job-control/job_remove.c b/42sh/src/job-control/job_remove.c index 697cc018..297969b9 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/01/08 14:04:48 by jhalford ### ########.fr */ +/* Updated: 2017/01/09 16:46:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,12 +21,7 @@ void job_remove(int id) { DG("job_remove"); if (id < data_singleton()->jobc.current_id) - { data_singleton()->jobc.current_id = id; - DG("ID_UPDATE(downgrade):%i", id); - } - else - DG("ID_UPDATE(no downgrade): %i/%i", id, data_singleton()->jobc.current_id); ft_lst_delif(&jobc->first_job, &id, job_cmp_id, job_free); } else diff --git a/42sh/src/job-control/mark_job_as_running.c b/42sh/src/job-control/mark_job_as_running.c index 3938cd9f..c10a2b5b 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/01/09 14:03:36 by jhalford ### ########.fr */ +/* Updated: 2017/01/09 16:58:38 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ void mark_job_as_running (t_job *j) { p = plist->content; p->attributes &= ~PROCESS_STATE_MASK; - p->attributes |= PROCESS_RUNNING; + p->attributes |= PROCESS_CONTINUED; plist = plist->next; } j->attributes &= ~JOB_NOTIFIED; diff --git a/42sh/src/job-control/process_format.c b/42sh/src/job-control/process_format.c index db30bcaf..d9b0dd4f 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/01/09 14:19:50 by jhalford ### ########.fr */ +/* Updated: 2017/01/09 16:58:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,6 +28,12 @@ void process_format(t_list **plist, int firstp, int opts) ft_putstr("running "); else if (state == PROCESS_SUSPENDED) ft_putstr("suspended"); + else if (state == PROCESS_CONTINUED) + { + ft_putstr("continued"); + p->attributes &= ~PROCESS_STATE_MASK; + p->attributes &= ~PROCESS_RUNNING; + } else if (state == PROCESS_COMPLETED) { if (p->status == 0) @@ -51,9 +57,14 @@ void process_format(t_list **plist, int firstp, int opts) if (!(p->attributes & state) || (state == PROCESS_COMPLETED && p->status != 0)) break; + if (p->attributes & PROCESS_CONTINUED) + { + p->attributes &= ~PROCESS_STATE_MASK; + p->attributes &= ~PROCESS_RUNNING; + } ft_sstrprint(p->av, ' '); if ((*plist)->next) - ft_putstr(" |"); + ft_putstr(" | "); (*plist) = (*plist)->next; } } diff --git a/42sh/src/job-control/sigtstp_handler.c b/42sh/src/job-control/sigtstp_handler.c index 5c02ec84..15f3316c 100644 --- a/42sh/src/job-control/sigtstp_handler.c +++ b/42sh/src/job-control/sigtstp_handler.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 15:14:53 by jhalford #+# #+# */ -/* Updated: 2017/01/08 14:30:53 by jhalford ### ########.fr */ +/* Updated: 2017/01/09 16:37:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/sigttin_handler.c b/42sh/src/job-control/sigttin_handler.c index 4edd2696..1b424bf5 100644 --- a/42sh/src/job-control/sigttin_handler.c +++ b/42sh/src/job-control/sigttin_handler.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 15:14:53 by jhalford #+# #+# */ -/* Updated: 2016/12/10 18:20:57 by jhalford ### ########.fr */ +/* Updated: 2017/01/09 16:37:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/shell_exit.c b/42sh/src/main/shell_exit.c index 02e32f49..2cf67c0e 100644 --- a/42sh/src/main/shell_exit.c +++ b/42sh/src/main/shell_exit.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 17:37:04 by jhalford #+# #+# */ -/* Updated: 2017/01/09 16:25:04 by jhalford ### ########.fr */ +/* Updated: 2017/01/09 16:35:53 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */