builtin_bg done, doesnt take arguments yet

This commit is contained in:
Jack Halford 2017-01-09 17:00:56 +01:00
parent 153b9aec79
commit 9d02933f72
16 changed files with 70 additions and 26 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

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: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)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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},
};

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: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);

View file

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* builtin_bg.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

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: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);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
}
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */