pipelines fixed

This commit is contained in:
Jack Halford 2017-01-07 22:27:13 +01:00
parent 9367075a9f
commit df1f449778
11 changed files with 66 additions and 25 deletions

View file

@ -73,6 +73,8 @@ int check_chlds(void);
void sigchld_handler(int signo); void sigchld_handler(int signo);
void sigint_handler(int signo); void sigint_handler(int signo);
void sigtstp_handler(int signo); 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); int process_cmp_pid(t_process *p, pid_t *pid);

View file

@ -21,7 +21,6 @@ int exec_command(t_btree **ast)
node = (*ast)->item; node = (*ast)->item;
p = &data_singleton()->exec.process; p = &data_singleton()->exec.process;
job = &data_singleton()->exec.job; job = &data_singleton()->exec.job;
/* job = data_singleton()->jobc.first_job->content; */
p->av = ft_sstrdup(node->data.sstr); p->av = ft_sstrdup(node->data.sstr);
process_setexec(p); process_setexec(p);
if (!(launch_process(p))) if (!(launch_process(p)))
@ -32,7 +31,9 @@ int exec_command(t_btree **ast)
put_job_in_foreground(job, 0): put_job_in_foreground(job, 0):
put_job_in_background(job, 0); put_job_in_background(job, 0);
} }
process_reset(); p->av = NULL;
p->pid = 0;
p->attributes = PROCESS_PIPESTART | PROCESS_PIPEEND;
btree_delone(ast, &ast_free); btree_delone(ast, &ast_free);
return (0); return (0);
} }

View file

@ -16,11 +16,13 @@ int process_redirect(t_process *p)
{ {
if (p->fdin != STDIN) if (p->fdin != STDIN)
{ {
DG("dup2 %i->%i", p->fdin, STDIN);
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);
dup2(p->fdout, STDOUT); dup2(p->fdout, STDOUT);
close(p->fdout); close(p->fdout);
} }

View file

@ -5,10 +5,4 @@ void process_reset(void)
t_data *data; t_data *data;
data = data_singleton(); data = data_singleton();
data->exec.process.path = NULL;
data->exec.process.av = NULL;
/* data->exec.process.fdin = STDIN; */
/* data->exec.process.fdout = STDOUT; */
data->exec.process.pid = 0;
data->exec.process.attributes = PROCESS_PIPESTART | PROCESS_PIPEEND;
} }

View file

@ -20,9 +20,10 @@ int process_setgroup(t_process *p)
(void)p; (void)p;
job = &data_singleton()->exec.job; job = &data_singleton()->exec.job;
pid = p->pid; pid = getpid();
if (job->pgid == 0) if (job->pgid == 0)
job->pgid = pid; job->pgid = pid;
DG("job->pgid=%i", job->pgid);
setpgid(pid, job->pgid); setpgid(pid, job->pgid);
if (JOB_IS_FG(job->attributes)) if (JOB_IS_FG(job->attributes))
tcsetpgrp(STDIN_FILENO, job->pgid); tcsetpgrp(STDIN_FILENO, job->pgid);

View file

@ -19,10 +19,8 @@ int job_addprocess(t_process *p)
jobc = &data_singleton()->jobc; jobc = &data_singleton()->jobc;
job = &data_singleton()->exec.job; job = &data_singleton()->exec.job;
DG("check; attr=%b", p->attributes);
if (IS_PIPESTART(p->attributes)) if (IS_PIPESTART(p->attributes))
{ {
DG("check");
job_update_id(); job_update_id();
job->id = jobc->current_id; job->id = jobc->current_id;
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job))); ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
@ -32,7 +30,7 @@ int job_addprocess(t_process *p)
if (p->pid > 0) if (p->pid > 0)
{ {
ft_lsteadd(&job->first_process, ft_lstnew(p, sizeof(*p))); ft_lsteadd(&job->first_process, ft_lstnew(p, sizeof(*p)));
DG("added process to first_job : %i", p->pid); DG("added pid=%i to [%i]", p->pid, job->id);
} }
if (JOB_IS_BG(job->attributes) && IS_PIPEEND(p->attributes)) if (JOB_IS_BG(job->attributes) && IS_PIPEEND(p->attributes))
job_notify_new(job); job_notify_new(job);

View file

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sigttin_handler.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 15:14:53 by jhalford #+# #+# */
/* Updated: 2016/12/10 18:20:57 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void sigttin_handler(int signo)
{
(void)signo;
DG("got SIGTTIN");
}

View file

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sigttou_handler.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 15:14:53 by jhalford #+# #+# */
/* Updated: 2016/12/10 18:20:57 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void sigttou_handler(int signo)
{
(void)signo;
DG("got SIGTTOU");
}

View file

@ -12,17 +12,15 @@
#include "minishell.h" #include "minishell.h"
pid_t g_pid;
void sigint_handler(int signo) void sigint_handler(int signo)
{ {
t_job *job;
(void)signo; (void)signo;
if (signo == SIGINT) job = &data_singleton()->exec.job;
{ DG("got SIGINT; job->pgid=%i", job->pgid);
DG("got SIGINT"); if (job->pgid)
if (g_pid) kill(job->pgid, SIGINT);
kill(g_pid, SIGINT); if (kill(job->pgid, 0) == 0)
if (kill(g_pid, 0) == 0) ft_putchar('\n');
ft_putendl("");
}
} }

View file

@ -23,7 +23,14 @@ int data_init(void)
data->line.input = NULL; data->line.input = NULL;
data->env = ft_sstrdup(environ); data->env = ft_sstrdup(environ);
data->line.history = NULL; data->line.history = NULL;
process_reset();
data->exec.process.path = NULL;
data->exec.process.av = NULL;
data->exec.process.fdin = STDIN;
data->exec.process.fdout = STDOUT;
data->exec.process.pid = 0;
data->exec.process.attributes = PROCESS_PIPESTART | PROCESS_PIPEEND;
data->exec.aol_status = NULL; data->exec.aol_status = NULL;
data->exec.aol_search = 0; data->exec.aol_search = 0;
data->exec.job.id = 0; data->exec.job.id = 0;

View file

@ -26,8 +26,8 @@ void shell_init(void)
signal(SIGINT, sigint_handler); signal(SIGINT, sigint_handler);
signal(SIGQUIT, SIG_IGN); signal(SIGQUIT, SIG_IGN);
signal(SIGTSTP, sigtstp_handler); signal(SIGTSTP, sigtstp_handler);
signal(SIGTTIN, SIG_IGN); signal(SIGTTIN, sigttin_handler);
signal(SIGTTOU, SIG_IGN); signal(SIGTTOU, sigttou_handler);
signal(SIGCHLD, sigchld_handler); signal(SIGCHLD, sigchld_handler);
*shell_pgid = getpid(); *shell_pgid = getpid();
if (setpgid(*shell_pgid, *shell_pgid)) if (setpgid(*shell_pgid, *shell_pgid))