next to do: end of pipe doesnt terminate by itself
This commit is contained in:
parent
9e8939d588
commit
d2982d89bc
15 changed files with 47 additions and 41 deletions
|
|
@ -52,10 +52,10 @@ int do_job_notification(void);
|
|||
void job_notify_new(t_job *job);
|
||||
void job_notify_change(int id, int status);
|
||||
|
||||
int job_wait(t_job *job);
|
||||
int job_wait(int id);
|
||||
void job_update_status(void);
|
||||
int job_is_stopped(t_job *job);
|
||||
int job_is_completed(t_job *job);
|
||||
int job_is_stopped(int id);
|
||||
int job_is_completed(int id);
|
||||
void job_remove(int id);
|
||||
void job_free(void *content, size_t content_size);
|
||||
int process_mark_status(pid_t pid, int status);
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit a26a4be4adbf4d6d4887af95a7307356d52ce85d
|
||||
Subproject commit f4af2f642761111b3395bb69c1766a8c46719d4d
|
||||
|
|
@ -21,25 +21,16 @@ int exec_command(t_btree **ast)
|
|||
node = (*ast)->item;
|
||||
p = &data_singleton()->exec.process;
|
||||
job = &data_singleton()->exec.job;
|
||||
/* job = data_singleton()->jobc.first_job->content; */
|
||||
p->av = ft_sstrdup(node->data.sstr);
|
||||
if (process_setexec(p))
|
||||
process_setexec(p);
|
||||
if (!(launch_process(p)))
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->av[0]);
|
||||
set_exitstatus(127);
|
||||
}
|
||||
else
|
||||
{
|
||||
DG("gonna launch_process now");
|
||||
launch_process(p);
|
||||
DG("launch_process done");
|
||||
job_addprocess(p);
|
||||
DG("job_addprocess done");
|
||||
if (IS_PIPEEND(p->attributes))
|
||||
{
|
||||
JOB_IS_FG(job->attributes) ?
|
||||
put_job_in_foreground(job, 0):
|
||||
put_job_in_background(job, 0);
|
||||
}
|
||||
}
|
||||
process_reset();
|
||||
btree_delone(ast, &ast_free);
|
||||
|
|
|
|||
|
|
@ -24,13 +24,7 @@ int exec_pipe(t_btree **ast)
|
|||
pipe(fds);
|
||||
DG("pipe %i->%i", fds[PIPE_WRITE], fds[PIPE_READ]);
|
||||
p->fdout = fds[PIPE_WRITE];
|
||||
start = 0;
|
||||
if (!IS_PIPESTART(p->attributes))
|
||||
{
|
||||
p->attributes |= PROCESS_PIPESTART;
|
||||
start = 1;
|
||||
}
|
||||
p->attributes &= ~PROCESS_PIPESTART;
|
||||
start = IS_PIPESTART(p->attributes);
|
||||
|
||||
p->attributes &= ~PROCESS_PIPEEND;
|
||||
ft_exec(&(*ast)->left);
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@ int ft_exec(t_btree **ast)
|
|||
while (g_execmap[i].type)
|
||||
{
|
||||
if (item->type == g_execmap[i].type)
|
||||
return ((*g_execmap[i].f)(ast));
|
||||
/* return ((*g_execmap[i].f)(ast)); */
|
||||
(*g_execmap[i].f)(ast);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,11 @@ int launch_process(t_process *p)
|
|||
|
||||
exec = &data_singleton()->exec;
|
||||
if (p->attributes & PROCESS_UNKNOWN)
|
||||
ft_dprintf(2, "%s: command not found: %s\n", SHELL_NAME, p->av[0]);
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->av[0]);
|
||||
set_exitstatus(127);
|
||||
return (1);
|
||||
}
|
||||
else if (p->attributes & PROCESS_BUILTIN && p->fdout == STDOUT)
|
||||
set_exitstatus((*p->execf)(p->path, p->av, data_singleton()->env));
|
||||
else
|
||||
|
|
|
|||
|
|
@ -14,16 +14,17 @@
|
|||
|
||||
int process_setexec(t_process *p)
|
||||
{
|
||||
DG("process_setexec, attr=%b", p->attributes);
|
||||
if ((p->execf = is_builtin(p)))
|
||||
{
|
||||
DG("process is a builtin, attr=%b", p->attributes);
|
||||
DG("process is builtin");
|
||||
p->attributes |= PROCESS_BUILTIN;
|
||||
}
|
||||
else if (ft_strchr(p->av[0], '/'))
|
||||
{
|
||||
DG("process is a script");
|
||||
p->execf = &execve;
|
||||
p->attributes &= PROCESS_SCRIPT;
|
||||
p->attributes |= PROCESS_SCRIPT;
|
||||
p->path = ft_strdup(p->av[0]);
|
||||
}
|
||||
else if ((p->path = ft_findexec(ft_getenv(
|
||||
|
|
|
|||
|
|
@ -27,13 +27,13 @@ int do_job_notification(void)
|
|||
{
|
||||
j = jlist->content;
|
||||
DG("checking job [%i]", j->id);
|
||||
if (job_is_completed(j))
|
||||
if (job_is_completed(j->id))
|
||||
{
|
||||
ret = 1;
|
||||
job_notify_change(j->id, 0);
|
||||
job_remove(j->id);
|
||||
}
|
||||
else if (job_is_stopped(j) && !(j->attributes & JOB_NOTIFIED))
|
||||
else if (job_is_stopped(j->id) && !(j->attributes & JOB_NOTIFIED))
|
||||
{
|
||||
ret = 1;
|
||||
job_notify_change(j->id, 8);
|
||||
|
|
|
|||
|
|
@ -12,15 +12,21 @@
|
|||
|
||||
#include "job_control.h"
|
||||
|
||||
int job_is_completed(t_job *job)
|
||||
int job_is_completed(int id)
|
||||
{
|
||||
t_list *lst;
|
||||
t_job *job;
|
||||
t_jobc *jobc;
|
||||
t_process *p;
|
||||
|
||||
jobc = &data_singleton()->jobc;
|
||||
job = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content;
|
||||
lst = job->first_process;
|
||||
DG("check");
|
||||
while (lst)
|
||||
{
|
||||
p = lst->content;
|
||||
DG("checking pid=%i", p->pid);
|
||||
if (!(p->attributes & PROCESS_COMPLETED))
|
||||
{
|
||||
DG("process %i is not completed", p->pid);
|
||||
|
|
|
|||
|
|
@ -12,11 +12,15 @@
|
|||
|
||||
#include "job_control.h"
|
||||
|
||||
int job_is_stopped(t_job *job)
|
||||
int job_is_stopped(int id)
|
||||
{
|
||||
t_list *lst;
|
||||
t_job *job;
|
||||
t_jobc *jobc;
|
||||
t_process *p;
|
||||
|
||||
jobc = &data_singleton()->jobc;
|
||||
job = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content;
|
||||
lst = job->first_process;
|
||||
while (lst)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ void job_update_status(void)
|
|||
pid_t pid;
|
||||
|
||||
DG("updating job status'");
|
||||
pid = waitpid (WAIT_ANY, &status, WUNTRACED|WNOHANG);
|
||||
pid = waitpid (WAIT_ANY, &status, WUNTRACED | WNOHANG);
|
||||
while (!process_mark_status(pid, status))
|
||||
pid = waitpid (WAIT_ANY, &status, WUNTRACED|WNOHANG);
|
||||
pid = waitpid (WAIT_ANY, &status, WUNTRACED | WNOHANG);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,17 +12,21 @@
|
|||
|
||||
#include "job_control.h"
|
||||
|
||||
int job_wait(t_job *job)
|
||||
int job_wait(int id)
|
||||
{
|
||||
pid_t pid;
|
||||
int status;
|
||||
|
||||
pid = waitpid(WAIT_ANY, &status, WUNTRACED);
|
||||
while (!(process_mark_status(pid, status)
|
||||
|| job_is_stopped(job)
|
||||
|| job_is_completed(job)))
|
||||
while (!process_mark_status(pid, status)
|
||||
&& !job_is_stopped(id)
|
||||
&& !job_is_completed(id))
|
||||
{
|
||||
DG("waitpid now");
|
||||
pid = waitpid(WAIT_ANY, &status, WUNTRACED);
|
||||
DG("waitpid done");
|
||||
}
|
||||
return(0);
|
||||
/* DG("stopped: %i", job_is_stopped(job)); */
|
||||
/* DG("completed: %i", job_is_completed(job)); */
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ int process_mark_status(pid_t pid, int status)
|
|||
{
|
||||
t_process *p;
|
||||
|
||||
DG("marking: pid=%i, status=%i", pid, status);
|
||||
if (pid > 1)
|
||||
{
|
||||
DG("marking: pid=%i, status=%i", pid, status);
|
||||
if ((p = job_getprocess(pid)))
|
||||
{
|
||||
DG("found process pid=%i", pid);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@ int put_job_in_foreground(t_job *job, int cont)
|
|||
perror("kill (SIGCONT)");
|
||||
}
|
||||
/* Wait for it to report. */
|
||||
job_wait(job);
|
||||
DG("gonna wait for job");
|
||||
job_wait(job->id);
|
||||
job_remove(job->id);
|
||||
|
||||
/* Put the shell back in the foreground. */
|
||||
|
|
|
|||
|
|
@ -21,5 +21,5 @@ void sigchld_handler(int signo)
|
|||
DG("got asynchronous notification (SIGCHLD)");
|
||||
/* if (do_job_notification()) */
|
||||
/* ft_putstr(SHELL_PROMPT); */
|
||||
job_update_status();
|
||||
/* job_update_status(); */
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue