pipelines broken in this commit

This commit is contained in:
Jack Halford 2017-01-09 16:01:09 +01:00
parent bbdaedef06
commit 204d5b9795
31 changed files with 249 additions and 109 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
/* Updated: 2017/01/08 16:10:11 by jhalford ### ########.fr */ /* Updated: 2017/01/09 15:57:08 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,14 +16,18 @@
# define PIPE_READ 0 # define PIPE_READ 0
# define PIPE_WRITE 1 # define PIPE_WRITE 1
# define PROCESS_COMPLETED (1 << 0) # define PROCESS_BUILTIN (1 << 0)
# define PROCESS_STOPPED (1 << 1) # define PROCESS_BINARY (1 << 1)
# define PROCESS_BUILTIN (1 << 2) # define PROCESS_SCRIPT (1 << 2)
# define PROCESS_BINARY (1 << 3) # define PROCESS_UNKNOWN (1 << 3)
# define PROCESS_SCRIPT (1 << 4) # define PROCESS_PIPESTART (1 << 4)
# define PROCESS_UNKNOWN (1 << 5) # define PROCESS_PIPEEND (1 << 5)
# define PROCESS_PIPESTART (1 << 6) # define PROCESS_COMPLETED (1 << 6)
# define PROCESS_PIPEEND (1 << 7) # define PROCESS_SUSPENDED (1 << 7)
# define PROCESS_RUNNING (1 << 8)
# define PROCESS_TYPE_MASK (1 << 0 | 1 << 1 | 1 << 2 | 1 << 3)
# define PROCESS_STATE_MASK (1 << 6 | 1 << 7 | 1 << 8)
# define IS_PIPESTART(a) (a & PROCESS_PIPESTART) # define IS_PIPESTART(a) (a & PROCESS_PIPESTART)
# define IS_PIPEEND(a) (a & PROCESS_PIPEEND) # define IS_PIPEEND(a) (a & PROCESS_PIPEEND)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */ /* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
/* Updated: 2017/01/08 16:10:10 by jhalford ### ########.fr */ /* Updated: 2017/01/09 14:05:43 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,6 +24,8 @@
# define JOB_IS_BG(j) (j & JOB_BG) # define JOB_IS_BG(j) (j & JOB_BG)
# define JOB_IS_FG(j) !(j & JOB_BG) # define JOB_IS_FG(j) !(j & JOB_BG)
#define JOBS_OPTS_L (1 << 0)
struct s_job struct s_job
{ {
int id; int id;
@ -51,33 +53,36 @@ void job_update_rank(void);
int do_job_notification(void); int do_job_notification(void);
void job_notify_new(t_job *job); void job_notify_new(t_job *job);
void job_notify_change(int id, int status); void job_notify_change(int id, int status);
void job_format(t_job *j, int rank[2], int opts);
void job_format_head(t_job *j, int rank[2]);
int job_wait(int id);
void job_update_status(void); void job_update_status(void);
void mark_job_as_running (t_job *j);
int process_mark_status(pid_t pid, int status);
int job_is_stopped(int id); int job_is_stopped(int id);
int job_is_completed(int id); int job_is_completed(int id);
void job_new(char **av, pid_t pid);
int job_wait(int id);
void job_remove(int id); void job_remove(int id);
void job_free(void *content, size_t content_size); void job_free(void *content, size_t content_size);
void job_kill_all(void); void job_kill_all(void);
void mark_job_as_running (t_job *j);
int process_mark_status(pid_t pid, int status);
int put_job_in_foreground(t_job *job, int cont); int put_job_in_foreground(t_job *job, int cont);
int put_job_in_background(t_job *job, int cont); int put_job_in_background(t_job *job, int cont);
void job_new(char **av, pid_t pid);
int job_cmp_pid(t_job *job, pid_t *pid); int job_cmp_pid(t_job *job, pid_t *pid);
int job_cmp_id(t_job *job, int *id); int job_cmp_id(t_job *job, int *id);
void job_getrank(int (*rank)[2]);
int check_chlds(void); void sigchld_handler(int signo);
void sigint_handler(int signo);
void sigtstp_handler(int signo);
void sigttin_handler(int signo);
void sigttou_handler(int signo);
void sigchld_handler(int signo); int process_cmp_pid(t_process *p, pid_t *pid);
void sigint_handler(int signo); void process_format(t_list **p, int firstp, int opts);
void sigtstp_handler(int signo);
void sigttin_handler(int signo);
void sigttou_handler(int signo);
int process_cmp_pid(t_process *p, pid_t *pid);
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
/* Updated: 2017/01/08 16:10:25 by jhalford ### ########.fr */ /* Updated: 2017/01/09 12:14:43 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */ /* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
/* Updated: 2016/12/13 17:51:11 by jhalford ### ########.fr */ /* Updated: 2017/01/09 13:58:39 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

@ -1 +1 @@
Subproject commit f4af2f642761111b3395bb69c1766a8c46719d4d Subproject commit eded1f1d189a6fd631b705f9d4a466fe088b94b3

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */ /* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
/* Updated: 2016/12/07 16:29:11 by jhalford ### ########.fr */ /* Updated: 2017/01/09 15:53:07 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,7 +22,6 @@ int builtin_setenv(const char *path, char *const av[], char *const envp[])
(void)path; (void)path;
i = 0; i = 0;
env = &data_singleton()->env; env = &data_singleton()->env;
DG("doing setenv now");
if (ft_strcmp(av[0], "setenv") == 0) if (ft_strcmp(av[0], "setenv") == 0)
av++; av++;
if (!av[0]) if (!av[0])
@ -41,7 +40,6 @@ int builtin_setenv(const char *path, char *const av[], char *const envp[])
{ {
ft_strdel(&(*env)[i]); ft_strdel(&(*env)[i]);
(*env)[i] = str; (*env)[i] = str;
DG("done setenv");
return (0); return (0);
} }
i++; i++;
@ -49,6 +47,5 @@ int builtin_setenv(const char *path, char *const av[], char *const envp[])
*env = ft_sstradd(*env, str); *env = ft_sstradd(*env, str);
ft_strdel(&str); ft_strdel(&str);
} }
DG("done setenv");
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */ /* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
/* Updated: 2017/01/08 15:24:20 by jhalford ### ########.fr */ /* Updated: 2017/01/09 12:20:24 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 21:13:23 by jhalford #+# #+# */ /* Created: 2016/11/27 21:13:23 by jhalford #+# #+# */
/* Updated: 2017/01/08 11:03:05 by jhalford ### ########.fr */ /* Updated: 2017/01/09 15:56:40 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -30,8 +30,7 @@ int exec_pipe(t_btree **ast)
ft_exec(&(*ast)->left); ft_exec(&(*ast)->left);
p->attributes &= ~PROCESS_PIPESTART; p->attributes &= ~PROCESS_PIPESTART;
DG("p->fdout=%i", p->fdout); close(fds[PIPE_WRITE]);
close(p->fdout);
p->fdout = STDOUT; p->fdout = STDOUT;
p->fdin = fds[PIPE_READ]; p->fdin = fds[PIPE_READ];

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */ /* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
/* Updated: 2017/01/08 15:23:37 by jhalford ### ########.fr */ /* Updated: 2017/01/09 16:00:07 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -28,7 +28,9 @@ int launch_process(t_process *p)
set_exitstatus((*p->execf)(p->path, p->av, data_singleton()->env)); set_exitstatus((*p->execf)(p->path, p->av, data_singleton()->env));
else else
{ {
DG("process is to be forked, fdout=%i, attr=%b", p->fdout, p->attributes); DG("process is to be forked, %i->[]->%i, attr=%b", p->fdin, p->fdout, p->attributes);
p->attributes &= ~PROCESS_STATE_MASK;
p->attributes |= PROCESS_RUNNING;
if (p->attributes & (PROCESS_BINARY | PROCESS_SCRIPT) if (p->attributes & (PROCESS_BINARY | PROCESS_SCRIPT)
&& access(p->path, X_OK) == -1) && access(p->path, X_OK) == -1)
{ {

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */ /* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */
/* Updated: 2016/12/13 17:49:09 by jhalford ### ########.fr */ /* Updated: 2017/01/09 15:35:39 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,13 +16,13 @@ int process_redirect(t_process *p)
{ {
if (p->fdin != STDIN) if (p->fdin != STDIN)
{ {
DG("dup2 %i->%i", p->fdin, STDIN); DG("redirect STDIN to %i", p->fdin);
dup2(p->fdin, STDIN); dup2(p->fdin, STDIN);
close(p->fdin); close(p->fdin);
} }
if (p->fdout != STDOUT) if (p->fdout != STDOUT)
{ {
DG("dup2 %i->%i", p->fdout, STDOUT); DG("redirect STDOUT to %i", p->fdout);
dup2(p->fdout, STDOUT); dup2(p->fdout, STDOUT);
close(p->fdout); close(p->fdout);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */ /* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */
/* Updated: 2017/01/02 19:11:00 by jhalford ### ########.fr */ /* Updated: 2017/01/09 15:49:10 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,15 +14,12 @@
int process_setexec(t_process *p) int process_setexec(t_process *p)
{ {
DG("process_setexec, attr=%b", p->attributes);
if ((p->execf = is_builtin(p))) if ((p->execf = is_builtin(p)))
{ {
DG("process is builtin");
p->attributes |= PROCESS_BUILTIN; p->attributes |= PROCESS_BUILTIN;
} }
else if (ft_strchr(p->av[0], '/')) else if (ft_strchr(p->av[0], '/'))
{ {
DG("process is a script");
p->execf = &execve; p->execf = &execve;
p->attributes |= PROCESS_SCRIPT; p->attributes |= PROCESS_SCRIPT;
p->path = ft_strdup(p->av[0]); p->path = ft_strdup(p->av[0]);
@ -30,13 +27,11 @@ int process_setexec(t_process *p)
else if ((p->path = ft_findexec(ft_getenv( else if ((p->path = ft_findexec(ft_getenv(
data_singleton()->env, "PATH"), p->av[0]))) data_singleton()->env, "PATH"), p->av[0])))
{ {
DG("process is binary");
p->execf = &execve; p->execf = &execve;
p->attributes |= PROCESS_BINARY; p->attributes |= PROCESS_BINARY;
} }
else else
{ {
DG("process is '%s' unknown type", p->av[0]);
p->execf = NULL; p->execf = NULL;
p->attributes |= PROCESS_UNKNOWN; p->attributes |= PROCESS_UNKNOWN;
return (1); return (1);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */ /* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */
/* Updated: 2017/01/08 15:23:36 by jhalford ### ########.fr */ /* Updated: 2017/01/09 15:58:32 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,9 +23,8 @@ int process_setgroup(t_process *p)
pid = getpid(); pid = getpid();
if (job->pgid == 0) if (job->pgid == 0)
job->pgid = pid; job->pgid = pid;
DG("job->pgid=%i", job->pgid);
if (setpgid(pid, job->pgid)) if (setpgid(pid, job->pgid))
ft_dprintf(2, "{red}setpgid failed{eoc}\n"); DG("setpgid(%i, %i) failed", pid, job->pgid);
if (JOB_IS_FG(job->attributes)) if (JOB_IS_FG(job->attributes))
{ {
signal(SIGTTOU, SIG_IGN); signal(SIGTTOU, SIG_IGN);

View file

@ -6,59 +6,38 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */ /* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */
/* Updated: 2017/01/08 15:33:32 by jhalford ### ########.fr */ /* Updated: 2017/01/09 14:05:27 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "job_control.h" #include "job_control.h"
int builtin_jobs(const char *path, char *const av[], char *const envp[]) int builtin_jobs(const char *path, char *const av[], char *const envp[])
{ {
t_jobc *jobc; t_jobc *jobc;
t_list *jlist; t_list *jlist;
t_job *job; t_list *tmplist;
t_list *plist; int rank[2];
t_process *p; int opts;
char rank;
int lg;
int firstp;
jobc = &data_singleton()->jobc;
jlist = jobc->first_job;
(void)path; (void)path;
(void)envp; (void)envp;
(void)av; (void)av;
lg = 0; jobc = &data_singleton()->jobc;
jlist = jobc->first_job;
job_getrank(&rank);
opts = 0;
if (ft_strcmp(av[1], "-l") == 0) if (ft_strcmp(av[1], "-l") == 0)
lg = 1; opts |= JOBS_OPTS_L;
rank = '+'; tmplist = ft_lst_filter(jlist, NULL, NULL);
ft_lstsort(&tmplist, job_cmp_id);
jlist = tmplist;
while (jlist) while (jlist)
{ {
firstp = 1; job_format(jlist->content, rank, opts);
job = jlist->content;
ft_printf("{mag}[%i] %c ", job->id, rank);
ft_printf("attr=%#b ", job->attributes);
plist = job->first_process;
while (plist)
{
p = plist->content;
if (lg)
{
if (!firstp)
ft_printf("\n ");
ft_printf("%i ", p->pid);
}
else
ft_putchar(' ');
ft_sstrprint(p->av, ' ');
if (plist->next)
ft_printf(" |");
plist = plist->next;
firstp = 0;
}
jlist = jlist->next; jlist = jlist->next;
rank = (rank == '+') ? '-' : ' ';
ft_printf("{eoc}\n");
} }
ft_lstdel(&tmplist, ft_lst_cfree);
return (0); return (0);
} }

View file

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

View file

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* job_format.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 12:47:17 by jhalford #+# #+# */
/* Updated: 2017/01/09 14:05:06 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "job_control.h"
void job_format(t_job *j, int rank[2], int opts)
{
t_list *plist;
int firstp;
job_format_head(j, rank);
plist = j->first_process;
firstp = 1;
while (plist)
{
process_format(&plist, firstp, opts);
firstp = 0;
}
}

View file

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* job_format_head.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 13:10:38 by jhalford #+# #+# */
/* Updated: 2017/01/09 13:53:48 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "job_control.h"
void job_format_head(t_job *j, int rank[2])
{
char crank;
if (j->id == rank[0])
crank = '+';
else if (j->id == rank[1])
crank = '-';
else
crank = ' ';
ft_printf("{mag}[%i] %c ", j->id, crank);
ft_printf("{eoc}");
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
/* Updated: 2016/12/12 13:02:05 by jhalford ### ########.fr */ /* Updated: 2017/01/09 13:22:16 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* job_getrank.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 12:38:31 by jhalford #+# #+# */
/* Updated: 2017/01/09 12:47:08 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "job_control.h"
void job_getrank(int (*rank)[2])
{
t_job *job;
t_jobc *jobc;
t_list *jlist;
jobc = &data_singleton()->jobc;
jlist = jobc->first_job;
(*rank)[0] = 0;
(*rank)[1] = 0;
if (jlist)
{
job = jlist->content;
(*rank)[0] = 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> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 15:10:20 by jhalford #+# #+# */ /* Created: 2016/12/13 15:10:20 by jhalford #+# #+# */
/* Updated: 2017/01/08 14:04:16 by jhalford ### ########.fr */ /* Updated: 2017/01/09 14:03:40 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 15:06:45 by jhalford #+# #+# */ /* Created: 2016/12/13 15:06:45 by jhalford #+# #+# */
/* Updated: 2017/01/08 14:39:35 by jhalford ### ########.fr */ /* Updated: 2017/01/09 14:02:13 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -25,7 +25,7 @@ int job_is_stopped(int id)
while (lst) while (lst)
{ {
p = lst->content; p = lst->content;
if (!(p->attributes & (PROCESS_COMPLETED | PROCESS_STOPPED))) if (!(p->attributes & (PROCESS_COMPLETED | PROCESS_SUSPENDED)))
return (0); return (0);
lst = lst->next; lst = lst->next;
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 15:04:03 by jhalford #+# #+# */ /* Created: 2016/12/12 15:04:03 by jhalford #+# #+# */
/* Updated: 2017/01/08 13:52:53 by jhalford ### ########.fr */ /* Updated: 2017/01/09 12:39:33 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/08 14:40:40 by jhalford #+# #+# */ /* Created: 2017/01/08 14:40:40 by jhalford #+# #+# */
/* Updated: 2017/01/08 14:53:34 by jhalford ### ########.fr */ /* Updated: 2017/01/09 14:03:36 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,7 +21,8 @@ void mark_job_as_running (t_job *j)
while (plist) while (plist)
{ {
p = plist->content; p = plist->content;
p->attributes &= ~PROCESS_STOPPED; p->attributes &= ~PROCESS_STATE_MASK;
p->attributes |= PROCESS_RUNNING;
plist = plist->next; plist = plist->next;
} }
j->attributes &= ~JOB_NOTIFIED; j->attributes &= ~JOB_NOTIFIED;

View file

@ -0,0 +1,61 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_format.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 13:05:55 by jhalford #+# #+# */
/* Updated: 2017/01/09 14:19:50 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "job_control.h"
void process_format(t_list **plist, int firstp, int opts)
{
t_process *p;
int state;
p = (*plist)->content;
if (!firstp)
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 ");
else if (state == PROCESS_SUSPENDED)
ft_putstr("suspended");
else if (state == PROCESS_COMPLETED)
{
if (p->status == 0)
ft_putstr("done ");
else
ft_printf("exit %i ", p->status);
}
ft_putchar('\t');
if (opts & JOBS_OPTS_L)
{
ft_sstrprint(p->av, ' ');
if ((*plist)->next)
ft_putstr(" |");
(*plist) = (*plist)->next;
}
else
{
while (*plist)
{
p = (*plist)->content;
if (!(p->attributes & state) ||
(state == PROCESS_COMPLETED && p->status != 0))
break;
ft_sstrprint(p->av, ' ');
if ((*plist)->next)
ft_putstr(" |");
(*plist) = (*plist)->next;
}
}
ft_putchar('\n');
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
/* Updated: 2017/01/08 14:55:52 by jhalford ### ########.fr */ /* Updated: 2017/01/09 14:04:19 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,11 +24,13 @@ int process_mark_status(pid_t pid, int status)
if (WIFSTOPPED(status)) if (WIFSTOPPED(status))
{ {
DG("marking: pid=%i, status=%i (stopped)", pid, status); DG("marking: pid=%i, status=%i (stopped)", pid, status);
p->attributes |= PROCESS_STOPPED; p->attributes &= ~PROCESS_STATE_MASK;
p->attributes |= PROCESS_SUSPENDED;
} }
else else
{ {
DG("marking: pid=%i, status=%i (completed)", pid, status); DG("marking: pid=%i, status=%i (completed)", pid, status);
p->attributes &= ~PROCESS_STATE_MASK;
p->attributes |= PROCESS_COMPLETED; p->attributes |= PROCESS_COMPLETED;
if (WIFSIGNALED(status)) if (WIFSIGNALED(status))
ft_printf("{mag}%d: Terminated by signal %d.\n{eoc}", ft_printf("{mag}%d: Terminated by signal %d.\n{eoc}",

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */ /* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */
/* Updated: 2017/01/08 15:33:03 by jhalford ### ########.fr */ /* Updated: 2017/01/09 12:29:04 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,16 +17,16 @@ int put_job_in_foreground(t_job *job, int cont)
t_jobc *jobc; t_jobc *jobc;
jobc = &data_singleton()->jobc; jobc = &data_singleton()->jobc;
/* Put the job into the foreground. */
signal(SIGTTOU, SIG_IGN);
if (tcsetpgrp(STDIN, job->pgid) == -1)
DG("couldn't put process in control. errno=%i, pgid=%i", errno, job->pgid);
else
DG("pgid %i is now in control.", job->pgid);
signal(SIGTTOU, sigttou_handler);
/* Send the job a continue signal, if necessary. */ /* Send the job a continue signal, if necessary. */
if (cont) if (cont)
{ {
/* Put the job into the foreground. */
signal(SIGTTOU, SIG_IGN);
if (tcsetpgrp(STDIN, job->pgid) == -1)
DG("couldn't put process in control. errno=%i, pgid=%i", errno, job->pgid);
else
DG("pgid %i is now in control.", job->pgid);
signal(SIGTTOU, sigttou_handler);
tcsetattr (STDIN, TCSANOW, &job->tmodes); tcsetattr (STDIN, TCSANOW, &job->tmodes);
if (kill(-job->pgid, SIGCONT) < 0) if (kill(-job->pgid, SIGCONT) < 0)
perror("kill (SIGCONT)"); perror("kill (SIGCONT)");
@ -35,6 +35,7 @@ int put_job_in_foreground(t_job *job, int cont)
DG("gonna wait for job id=%i", job->id); DG("gonna wait for job id=%i", job->id);
job_wait(job->id); job_wait(job->id);
job_remove(job->id); job_remove(job->id);
job->pgid = 0;
/* Put the shell back in the foreground. */ /* Put the shell back in the foreground. */
signal(SIGTTOU, SIG_IGN); signal(SIGTTOU, SIG_IGN);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:14:12 by jhalford #+# #+# */ /* Created: 2016/12/01 12:14:12 by jhalford #+# #+# */
/* Updated: 2016/12/12 17:42:04 by jhalford ### ########.fr */ /* Updated: 2017/01/09 14:28:54 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 14:22:34 by jhalford #+# #+# */ /* Created: 2016/11/10 14:22:34 by jhalford #+# #+# */
/* Updated: 2017/01/08 16:00:49 by jhalford ### ########.fr */ /* Updated: 2017/01/09 14:28:20 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:14:09 by jhalford #+# #+# */ /* Created: 2016/12/01 12:14:09 by jhalford #+# #+# */
/* Updated: 2017/01/08 14:26:55 by jhalford ### ########.fr */ /* Updated: 2017/01/09 15:44:47 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,8 +17,12 @@ int ft_set_termios(t_data *data, int input_mode)
struct termios term; struct termios term;
(void)data; (void)data;
/* term = data_singleton()->jobc.shell_tmodes; */
if (tcgetattr(0, &term) == -1) if (tcgetattr(0, &term) == -1)
{
DG("tcgetattr failed, errno=%i", errno);
return (-1); return (-1);
}
if (input_mode) if (input_mode)
term.c_lflag &= ~(ICANON) & ~(ISIG) & ~(ECHO); term.c_lflag &= ~(ICANON) & ~(ISIG) & ~(ECHO);
else else

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 13:35:03 by jhalford #+# #+# */ /* Created: 2016/12/03 13:35:03 by jhalford #+# #+# */
/* Updated: 2017/01/08 14:27:01 by jhalford ### ########.fr */ /* Updated: 2017/01/09 15:35:56 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 15:14:47 by jhalford #+# #+# */ /* Created: 2016/12/10 15:14:47 by jhalford #+# #+# */
/* Updated: 2017/01/08 15:12:58 by jhalford ### ########.fr */ /* Updated: 2017/01/09 15:59:05 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */
/* Updated: 2017/01/08 15:11:34 by jhalford ### ########.fr */ /* Updated: 2017/01/09 15:36:12 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */