segfault on 'builtin | binary' fixed, 'binary | builtin' gets a SIGKILL somehow...

This commit is contained in:
Jack Halford 2017-02-19 16:10:23 +01:00
parent 694744bf0c
commit 56fe780999
4 changed files with 7 additions and 4 deletions

View file

@ -22,7 +22,7 @@ int exec_pipe(t_btree **ast)
data = data_singleton(); data = data_singleton();
p = &data_singleton()->exec.process; 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]); */
p->fdout = fds[PIPE_WRITE]; p->fdout = fds[PIPE_WRITE];
start = IS_PIPESTART(p->attributes); start = IS_PIPESTART(p->attributes);
p->toclose = fds[PIPE_READ]; p->toclose = fds[PIPE_READ];

View file

@ -18,7 +18,6 @@ int launch_process(t_process *p)
int pid; int pid;
exec = &data_singleton()->exec; exec = &data_singleton()->exec;
DG("launching");
if (p->attributes & PROCESS_UNKNOWN) if (p->attributes & PROCESS_UNKNOWN)
{ {
ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->av[0]); ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->av[0]);
@ -26,7 +25,6 @@ int launch_process(t_process *p)
} }
else if (p->attributes & PROCESS_BUILTIN && IS_PIPESINGLE(p->attributes)) else if (p->attributes & PROCESS_BUILTIN && IS_PIPESINGLE(p->attributes))
{ {
DG("check 0");
if (process_redirect(p)) if (process_redirect(p))
return (1); return (1);
set_exitstatus((*p->execf)(p->path, p->av, data_singleton()->env), 1); set_exitstatus((*p->execf)(p->path, p->av, data_singleton()->env), 1);
@ -42,7 +40,6 @@ int launch_process(t_process *p)
set_exitstatus(126, 1); set_exitstatus(126, 1);
return (1); return (1);
} }
DG("gonna fork now");
pid = fork(); pid = fork();
if (pid == 0) if (pid == 0)
{ {

View file

@ -14,6 +14,7 @@
int process_setexec(t_type type, t_process *p) int process_setexec(t_type type, t_process *p)
{ {
p->path = NULL;
if (type == TK_SUBSHELL) if (type == TK_SUBSHELL)
{ {
p->execf = &execve; p->execf = &execve;
@ -21,7 +22,9 @@ int process_setexec(t_type type, t_process *p)
p->path = ft_strdup(p->av[0]); p->path = ft_strdup(p->av[0]);
} }
else if ((p->execf = is_builtin(p))) else if ((p->execf = is_builtin(p)))
{
p->attributes |= PROCESS_BUILTIN; p->attributes |= PROCESS_BUILTIN;
}
else if (ft_strchr(p->av[0], '/')) else if (ft_strchr(p->av[0], '/'))
{ {
p->execf = &execve; p->execf = &execve;

View file

@ -26,8 +26,11 @@ int put_job_in_foreground(t_job *j, int cont)
if (kill(-j->pgid, SIGCONT) < 0) if (kill(-j->pgid, SIGCONT) < 0)
DG("kill(SIGCONT) failed"); DG("kill(SIGCONT) failed");
} }
DG("check 00");
job_wait(j->id); job_wait(j->id);
DG("check 01");
job_remove(j->id); job_remove(j->id);
DG("check 02");
tcsetpgrp(STDIN, jobc->shell_pgid); tcsetpgrp(STDIN, jobc->shell_pgid);