pretty stable version of job control, ready to merge

This commit is contained in:
Jack Halford 2017-01-10 11:32:02 +01:00
parent 9d02933f72
commit 0ec9313b4c
17 changed files with 58 additions and 38 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
/* Updated: 2017/01/09 16:58:55 by jhalford ### ########.fr */
/* Updated: 2017/01/10 10:23:55 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

@ -1 +1 @@
Subproject commit eded1f1d189a6fd631b705f9d4a466fe088b94b3
Subproject commit d799465c2e0d51f24fe4d5cf1e51c5109a1617a0

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
/* Updated: 2017/01/09 12:20:24 by jhalford ### ########.fr */
/* Updated: 2017/01/10 11:03:44 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,9 +27,12 @@ int exec_command(t_btree **ast)
{
job_addprocess(p);
if (IS_PIPEEND(p->attributes))
{
JOB_IS_FG(job->attributes) ?
put_job_in_foreground(job, 0):
put_job_in_background(job, 0);
job->pgid = 0;
}
}
p->av = NULL;
p->pid = 0;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
/* Updated: 2017/01/09 16:38:21 by jhalford ### ########.fr */
/* Updated: 2017/01/10 10:30:35 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 16:54:18 by jhalford #+# #+# */
/* Updated: 2017/01/09 16:57:20 by jhalford ### ########.fr */
/* Updated: 2017/01/10 11:11:21 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,19 +17,27 @@ int builtin_bg(const char *path, char *const av[], char *const envp[])
{
t_jobc *jobc;
t_job *job;
t_list *jlist;
int rank[2];
int id;
(void)path;
(void)envp;
(void)av;
jobc = &data_singleton()->jobc;
job = jobc->first_job->content;
job_getrank(&rank);
if (job)
id = av[1] ? ft_atoi(av[1]) : rank[0];
if (id == 0 && !av[1])
return (0);
jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id);
if (jlist)
{
job = jlist->content;
mark_job_as_running(job);
job_format(job, rank, JOBS_OPTS_L);
put_job_in_background(job, 1);
}
else
ft_dprintf(2, "{red}bg: job not found: %i{eoc}\n", id);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/08 14:30:07 by jhalford #+# #+# */
/* Updated: 2017/01/09 16:54:39 by jhalford ### ########.fr */
/* Updated: 2017/01/10 11:16:03 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,16 +16,26 @@ int builtin_fg(const char *path, char *const av[], char *const envp[])
{
t_jobc *jobc;
t_job *job;
t_list *jlist;
int rank[2];
int id;
(void)path;
(void)envp;
(void)av;
jobc = &data_singleton()->jobc;
job = jobc->first_job->content;
if (job)
job_getrank(&rank);
id = av[1] ? ft_atoi(av[1]) : rank[0];
if (id == 0 && !av[1])
return (0);
jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id);
if (jlist)
{
job = jlist->content;
mark_job_as_running(job);
put_job_in_foreground(job, 1);
}
else
ft_dprintf(2, "{red}fg: job not found: [%i]{eoc}\n", id);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */
/* Updated: 2017/01/09 16:20:09 by jhalford ### ########.fr */
/* Updated: 2017/01/10 11:16:16 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 13:38:13 by jhalford #+# #+# */
/* Updated: 2017/01/09 12:34:05 by jhalford ### ########.fr */
/* Updated: 2017/01/10 11:08:46 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 12:47:17 by jhalford #+# #+# */
/* Updated: 2017/01/09 16:55:36 by jhalford ### ########.fr */
/* Updated: 2017/01/10 11:16:50 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 12:38:31 by jhalford #+# #+# */
/* Updated: 2017/01/09 12:47:08 by jhalford ### ########.fr */
/* Updated: 2017/01/10 10:30:20 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,23 +14,21 @@
void job_getrank(int (*rank)[2])
{
t_job *job;
t_jobc *jobc;
t_list *jlist;
t_job *job;
t_jobc *jobc;
t_list *jlist;
int i;
i = 0;
jobc = &data_singleton()->jobc;
jlist = jobc->first_job;
(*rank)[0] = 0;
(*rank)[1] = 0;
if (jlist)
while (jlist && i < 2)
{
job = jlist->content;
(*rank)[0] = job->id;
if (job_is_stopped(job->id))
(*rank)[i++] = job->id;
jlist = jlist->next;
if (jlist)
{
job = jlist->content;
(*rank)[1] = job->id;
}
}
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 15:06:45 by jhalford #+# #+# */
/* Updated: 2017/01/09 14:02:13 by jhalford ### ########.fr */
/* Updated: 2017/01/10 10:31:56 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 15:04:03 by jhalford #+# #+# */
/* Updated: 2017/01/09 16:49:16 by jhalford ### ########.fr */
/* Updated: 2017/01/10 11:16:17 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/08 14:40:40 by jhalford #+# #+# */
/* Updated: 2017/01/09 16:58:38 by jhalford ### ########.fr */
/* Updated: 2017/01/10 10:52:36 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,8 +21,11 @@ void mark_job_as_running (t_job *j)
while (plist)
{
p = plist->content;
p->attributes &= ~PROCESS_STATE_MASK;
p->attributes |= PROCESS_CONTINUED;
if (p->attributes & PROCESS_SUSPENDED)
{
p->attributes &= ~PROCESS_STATE_MASK;
p->attributes |= PROCESS_CONTINUED;
}
plist = plist->next;
}
j->attributes &= ~JOB_NOTIFIED;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 13:05:55 by jhalford #+# #+# */
/* Updated: 2017/01/09 16:58:36 by jhalford ### ########.fr */
/* Updated: 2017/01/10 11:30:52 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,7 +22,6 @@ void process_format(t_list **plist, int firstp, int opts)
ft_printf(" ");
if (opts & JOBS_OPTS_L)
ft_printf("%i ", p->pid);
state = p->attributes & PROCESS_STATE_MASK;
if (state == PROCESS_RUNNING)
ft_putstr("running ");
@ -32,7 +31,7 @@ void process_format(t_list **plist, int firstp, int opts)
{
ft_putstr("continued");
p->attributes &= ~PROCESS_STATE_MASK;
p->attributes &= ~PROCESS_RUNNING;
p->attributes |= PROCESS_RUNNING;
}
else if (state == PROCESS_COMPLETED)
{

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
/* Updated: 2017/01/09 14:04:19 by jhalford ### ########.fr */
/* Updated: 2017/01/10 10:55:31 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,13 +23,13 @@ int process_mark_status(pid_t pid, int status)
p->status = status;
if (WIFSTOPPED(status))
{
DG("marking: pid=%i, status=%i (stopped)", pid, status);
DG("marking: pid=%i, status=%i (stopped sig %i)", pid, status, WTERMSIG(status));
p->attributes &= ~PROCESS_STATE_MASK;
p->attributes |= PROCESS_SUSPENDED;
}
else
{
DG("marking: pid=%i, status=%i (completed)", pid, status);
DG("marking: pid=%i, status=%i (completed sig %i)", pid, status, WTERMSIG(status));
p->attributes &= ~PROCESS_STATE_MASK;
p->attributes |= PROCESS_COMPLETED;
if (WIFSIGNALED(status))

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */
/* Updated: 2017/01/09 12:29:04 by jhalford ### ########.fr */
/* Updated: 2017/01/10 11:06:02 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -35,7 +35,6 @@ int put_job_in_foreground(t_job *job, int cont)
DG("gonna wait for job id=%i", job->id);
job_wait(job->id);
job_remove(job->id);
job->pgid = 0;
/* Put the shell back in the foreground. */
signal(SIGTTOU, SIG_IGN);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 15:14:53 by jhalford #+# #+# */
/* Updated: 2017/01/09 16:37:41 by jhalford ### ########.fr */
/* Updated: 2017/01/10 10:30:27 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */