new process group handling is goooooood
This commit is contained in:
parent
4f7b69b283
commit
9061e43bea
12 changed files with 22 additions and 17 deletions
|
|
@ -23,7 +23,7 @@
|
|||
| TK_DO | TK_IF | TK_FI | TK_THEN | TK_ELIF | TK_ELSE)
|
||||
enum e_lexstate
|
||||
{
|
||||
DEFAULT,
|
||||
DEFAULT, //#define DEFAULT 0
|
||||
PAREN,
|
||||
HEREDOC,
|
||||
NEWLINE,
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ int exec_leaf(t_btree **ast)
|
|||
return (1);
|
||||
if (!(launch_process(&p)))
|
||||
{
|
||||
DG("forked pid=[%i], name=[%s]", p.pid, p.data.cmd.av[0]);
|
||||
/* DG("forked pid=[%i], name=[%s]", p.pid, p.data.cmd.av[0]); */
|
||||
job_addprocess(&p);
|
||||
DG("[IS_BG->%i]", JOB_IS_BG(job->attrs));
|
||||
/* DG("[IS_BG->%i]", JOB_IS_BG(job->attrs)); */
|
||||
if (IS_PIPEEND(p))
|
||||
{
|
||||
if (JOB_IS_FG(job->attrs))
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ int launch_file(t_process *p)
|
|||
{
|
||||
/* data_singleton()->opts &= ~SH_INTERACTIVE; */
|
||||
/* data_singleton()->opts &= ~SH_OPTS_JOBC; */
|
||||
DG("fork! [%s]", p->data.cmd.av[0]);
|
||||
/* DG("fork! [%s]", p->data.cmd.av[0]); */
|
||||
process_setgroup(p, 0);
|
||||
process_setsig();
|
||||
if (process_redirect(p))
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ int launch_process(t_process *p)
|
|||
{
|
||||
int pid;
|
||||
|
||||
DG("launchprocess");
|
||||
if (p->type >= PROCESS_MAX)
|
||||
return (-1);
|
||||
if (!g_launchmap[p->type].f)
|
||||
|
|
@ -38,7 +37,6 @@ int launch_process(t_process *p)
|
|||
p->attrs |= PROCESS_RUNNING;
|
||||
if (!(pid = (*g_launchmap[p->type].f)(p)))
|
||||
{
|
||||
DG("gonna reset fds");
|
||||
process_resetfds(p);
|
||||
return (1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,11 +14,14 @@
|
|||
|
||||
static int do_subshell(t_process *p)
|
||||
{
|
||||
int ret;
|
||||
int ret;
|
||||
|
||||
ft_exec(&p->data.subshell.content);
|
||||
ret = ft_atoi(ft_getenv(data_singleton()->env, "?"));
|
||||
DG("CHECK, ret=[%i]", ret);
|
||||
/* p = ft_lstlast(j->first_process)->content; */
|
||||
/* ret = p->status */
|
||||
/* DG("CHECK, ret=[%i]", ret); */
|
||||
return (ret);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ int mark_process_status(pid_t pid, int status)
|
|||
{
|
||||
p = plist->content;
|
||||
p->status = status;
|
||||
DG("marking pid=[%i], name=[%s]", p->pid, p->data.cmd.av[0]);
|
||||
/* DG("found pid=[%i], name=[%s]", p->pid, p->data.cmd.av[0]); */
|
||||
if (WIFSTOPPED(status))
|
||||
{
|
||||
p->attrs &= ~PROCESS_STATE_MASK;
|
||||
|
|
|
|||
|
|
@ -21,13 +21,16 @@ int process_setgroup(t_process *p, pid_t pid)
|
|||
(void)p;
|
||||
data = data_singleton();
|
||||
j = &data->exec.job;
|
||||
if (!SH_IS_INTERACTIVE(data_singleton()->opts))
|
||||
return (0);
|
||||
DG("setpgid(%i, %i)", pid, j->pgid);
|
||||
if (setpgid(pid, j->pgid) == -1)
|
||||
ft_dprintf(2, "{red}%s: internal setpgid() error{eoc}\n", SHELL_NAME);
|
||||
if (pid == 0 && JOB_IS_FG(j->attrs))
|
||||
{
|
||||
DG("I'm taking the terminal !");
|
||||
DG("tcsetpgrp[%i]", j->pgid);
|
||||
tcsetpgrp(STDIN, j->pgid);
|
||||
DG("after tcsetpgrp");
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,5 +19,7 @@ void process_setsig(void)
|
|||
signal(SIGTSTP, SIG_DFL);
|
||||
signal(SIGTTIN, SIG_DFL);
|
||||
signal(SIGTTOU, SIG_DFL);
|
||||
/* signal(SIGTTIN, sigttin_handler); */
|
||||
/* signal(SIGTTOU, sigttou_handler); */
|
||||
signal(SIGCHLD, SIG_DFL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ int job_addprocess(t_process *p)
|
|||
{
|
||||
job_update_id();
|
||||
job->id = jobc->current_id;
|
||||
/* job->pgid = SH_HAS_JOBC(data_singleton()->opts) ? p->pid : getpid(); */
|
||||
job->pgid = p->pid;
|
||||
job->pgid = SH_IS_INTERACTIVE(data_singleton()->opts) ? p->pid : getpgid(0);
|
||||
/* job->pgid = p->pid; */
|
||||
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
|
||||
}
|
||||
DG("adding pid=[%i] to pgid=[%i]", p->pid, job->pgid);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ void job_remove(int id)
|
|||
if (job_is_completed(id))
|
||||
{
|
||||
p = ft_lstlast(j->first_process)->content;
|
||||
/* DG("remove, status=%i", p->status); */
|
||||
set_exitstatus(p->status, 0);
|
||||
if (id < data_singleton()->jobc.current_id)
|
||||
data_singleton()->jobc.current_id = id;
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@ int put_job_in_foreground(t_job *j, int cont)
|
|||
t_jobc *jobc;
|
||||
|
||||
jobc = &data_singleton()->jobc;
|
||||
DG("giving terminal to pgid->[%i]", j->pgid);
|
||||
tcsetpgrp(STDIN, j->pgid);
|
||||
|
||||
DG("tcsetpgrp[%i]", j->pgid);
|
||||
if (SH_IS_INTERACTIVE(data_singleton()->opts))
|
||||
tcsetpgrp(STDIN, j->pgid);
|
||||
if (cont)
|
||||
{
|
||||
tcsetattr(STDIN, TCSADRAIN, &j->tmodes);
|
||||
|
|
@ -28,8 +28,7 @@ int put_job_in_foreground(t_job *j, int cont)
|
|||
}
|
||||
job_wait(j->id);
|
||||
job_remove(j->id);
|
||||
|
||||
if (SH_HAS_JOBC(data_singleton()->opts))
|
||||
if (SH_IS_INTERACTIVE(data_singleton()->opts))
|
||||
{
|
||||
tcsetpgrp(STDIN, jobc->shell_pgid);
|
||||
tcgetattr(STDIN, &j->tmodes);
|
||||
|
|
|
|||
|
|
@ -124,7 +124,6 @@ int main(int ac, char **av)
|
|||
DG("JOBC is %s, fd=[%i]", SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF", fd);
|
||||
while (handle_instruction(fd) == 0)
|
||||
{
|
||||
DG();
|
||||
// lexer_clean;
|
||||
// parser_clean;
|
||||
;
|
||||
|
|
|
|||
Loading…
Reference in a new issue