pipeend and pipestart bits in process attribute, env problems solved
This commit is contained in:
parent
6144e4eab5
commit
c9a39637da
9 changed files with 40 additions and 25 deletions
|
|
@ -16,6 +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_STOPPED (1 << 1)
|
||||||
|
# define PROCESS_BUILTIN (1 << 2)
|
||||||
|
# define PROCESS_BINARY (1 << 3)
|
||||||
|
# define PROCESS_SCRIPT (1 << 4)
|
||||||
|
# define PROCESS_UNKNOWN (1 << 5)
|
||||||
|
# define PROCESS_PIPESTART (1 << 6)
|
||||||
|
# define PROCESS_PIPEEND (1 << 7)
|
||||||
|
|
||||||
|
# define IS_PIPESTART(p) (p & (PROCESS_PIPESTART))
|
||||||
|
# define IS_PIPEEND(p) (p & (PROCESS_PIPEEND))
|
||||||
|
|
||||||
# include "libft.h"
|
# include "libft.h"
|
||||||
# include "types.h"
|
# include "types.h"
|
||||||
# include "job_control.h"
|
# include "job_control.h"
|
||||||
|
|
|
||||||
|
|
@ -19,19 +19,11 @@
|
||||||
# include "libft.h"
|
# include "libft.h"
|
||||||
# include "types.h"
|
# include "types.h"
|
||||||
|
|
||||||
# define PROCESS_COMPLETED (1 << 0)
|
|
||||||
# define PROCESS_STOPPED (1 << 1)
|
|
||||||
# define PROCESS_BUILTIN (1 << 2)
|
|
||||||
# define PROCESS_BINARY (1 << 3)
|
|
||||||
# define PROCESS_SCRIPT (1 << 4)
|
|
||||||
# define PROCESS_UNKNOWN (1 << 5)
|
|
||||||
|
|
||||||
# define JOB_NOTIFIED (1 << 0)
|
# define JOB_NOTIFIED (1 << 0)
|
||||||
# define JOB_BG (1 << 1)
|
# define JOB_BG (1 << 1)
|
||||||
# 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)
|
||||||
|
|
||||||
|
|
||||||
struct s_job
|
struct s_job
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit e7cece5732986cdcd159b40f1d927137e2d6c9f3
|
Subproject commit a26a4be4adbf4d6d4887af95a7307356d52ce85d
|
||||||
|
|
@ -37,7 +37,7 @@ int builtin_setenv(const char *path, char *const av[], char *const envp[])
|
||||||
{
|
{
|
||||||
if (ft_strcmp((*env)[i], av[0]) == '=')
|
if (ft_strcmp((*env)[i], av[0]) == '=')
|
||||||
{
|
{
|
||||||
ft_strdel(*env);
|
ft_strdel(&(*env)[i]);
|
||||||
(*env)[i] = str;
|
(*env)[i] = str;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ int exec_command(t_btree **ast)
|
||||||
DG("gonna launch_process now");
|
DG("gonna launch_process now");
|
||||||
launch_process(p);
|
launch_process(p);
|
||||||
job_addprocess(p);
|
job_addprocess(p);
|
||||||
if (p->fdout == STDOUT)
|
if (IS_PIPEEND(p->fdout == STDOUT))
|
||||||
{
|
{
|
||||||
if (JOB_IS_FG(job->attributes))
|
if (JOB_IS_FG(job->attributes))
|
||||||
put_job_in_foreground(job, 0);
|
put_job_in_foreground(job, 0);
|
||||||
|
|
|
||||||
|
|
@ -16,21 +16,34 @@ int exec_pipe(t_btree **ast)
|
||||||
{
|
{
|
||||||
int fds[2];
|
int fds[2];
|
||||||
t_data *data;
|
t_data *data;
|
||||||
|
t_process *p;
|
||||||
|
|
||||||
data = data_singleton();
|
data = data_singleton();
|
||||||
|
p = &data_singleton()->exec.process;
|
||||||
pipe(fds);
|
pipe(fds);
|
||||||
DG("pipe %i->%i", fds[PIPE_WRITE], fds[PIPE_READ]);
|
DG("pipe %i->%i", fds[PIPE_WRITE], fds[PIPE_READ]);
|
||||||
data->exec.process.fdout = fds[PIPE_WRITE];
|
p->fdout = fds[PIPE_WRITE];
|
||||||
|
if (!IS_PIPEEND(p->attributes))
|
||||||
|
{
|
||||||
|
p->attributes |= PROCESS_PIPESTART;
|
||||||
|
p->attributes &= ~PROCESS_PIPEEND;
|
||||||
|
}
|
||||||
|
|
||||||
ft_exec(&(*ast)->left);
|
ft_exec(&(*ast)->left);
|
||||||
if (data->exec.process.fdout != STDOUT)
|
if (p->fdout != STDOUT)
|
||||||
close(data->exec.process.fdout);
|
close(p->fdout);
|
||||||
data->exec.process.fdout = STDOUT;
|
p->fdout = STDOUT;
|
||||||
data->exec.process.fdin = fds[PIPE_READ];
|
p->fdin = fds[PIPE_READ];
|
||||||
|
|
||||||
|
p->attributes ~= ~PROCESS_PIPESTART;
|
||||||
|
p->attributes |= PROCESS_PIPEEND;
|
||||||
|
|
||||||
ft_exec(&(*ast)->right);
|
ft_exec(&(*ast)->right);
|
||||||
close(fds[PIPE_WRITE]);
|
/* close(fds[PIPE_WRITE]); */
|
||||||
close(fds[PIPE_READ]);
|
/* close(fds[PIPE_READ]); */
|
||||||
data->exec.process.fdin = STDIN;
|
p->fdin = STDIN;
|
||||||
data->exec.process.fdout = STDOUT;
|
p->fdout = STDOUT;
|
||||||
|
p->attributes &= ~PROCESS_PIPEEND;
|
||||||
btree_delone(ast, &ast_free);
|
btree_delone(ast, &ast_free);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,6 @@
|
||||||
|
|
||||||
int process_setexec(t_process *p)
|
int process_setexec(t_process *p)
|
||||||
{
|
{
|
||||||
DG("going to setexec:\nenv at %p\nav[0]=%s", data_singleton()->env, p->argv[0]);
|
|
||||||
DG("going to setexec:\nPATH=%s\nav[0]=%s", ft_getenv(data_singleton()->env, "PATH"), p->argv[0]);
|
|
||||||
if ((p->execf = is_builtin(p)))
|
if ((p->execf = is_builtin(p)))
|
||||||
{
|
{
|
||||||
DG("process is a builtin");
|
DG("process is a builtin");
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ int do_job_notification(void)
|
||||||
{
|
{
|
||||||
ret = 1;
|
ret = 1;
|
||||||
job_notify_change(j->id, 0);
|
job_notify_change(j->id, 0);
|
||||||
/* job_remove(j->id); */
|
job_remove(j->id);
|
||||||
}
|
}
|
||||||
else if (job_is_stopped(j) && !(j->attributes & JOB_NOTIFIED))
|
else if (job_is_stopped(j) && !(j->attributes & JOB_NOTIFIED))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ int job_addprocess(t_process *p)
|
||||||
|
|
||||||
jobc = &data_singleton()->jobc;
|
jobc = &data_singleton()->jobc;
|
||||||
job = &data_singleton()->exec.job;
|
job = &data_singleton()->exec.job;
|
||||||
if (p->fdin == STDIN)
|
if (IS_PIPESTART(p->attributes))
|
||||||
{
|
{
|
||||||
job_update_id();
|
job_update_id();
|
||||||
job->id = jobc->current_id;
|
job->id = jobc->current_id;
|
||||||
|
|
@ -28,7 +28,7 @@ int job_addprocess(t_process *p)
|
||||||
}
|
}
|
||||||
job = jobc->first_job->content;
|
job = jobc->first_job->content;
|
||||||
ft_lstadd(&job->first_process, ft_lstnew(p, sizeof(*p)));
|
ft_lstadd(&job->first_process, ft_lstnew(p, sizeof(*p)));
|
||||||
if (JOB_IS_BG(job->attributes) && p->fdout == STDOUT)
|
if (JOB_IS_BG(job->attributes) && IS_PIPEEND(p->attributes))
|
||||||
job_notify_new(job);
|
job_notify_new(job);
|
||||||
DG("added process to first_job : %i", p->pid);
|
DG("added process to first_job : %i", p->pid);
|
||||||
return(0);
|
return(0);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue