From 56fe780999137843b9f763fdbc43734472a11f54 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Sun, 19 Feb 2017 16:10:23 +0100 Subject: [PATCH] segfault on 'builtin | binary' fixed, 'binary | builtin' gets a SIGKILL somehow... --- 42sh/src/exec/exec_pipe.c | 2 +- 42sh/src/exec/launch_process.c | 3 --- 42sh/src/exec/process_setexec.c | 3 +++ 42sh/src/job-control/put_job_in_foreground.c | 3 +++ 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/42sh/src/exec/exec_pipe.c b/42sh/src/exec/exec_pipe.c index 833138c3..c68a0bc3 100644 --- a/42sh/src/exec/exec_pipe.c +++ b/42sh/src/exec/exec_pipe.c @@ -22,7 +22,7 @@ int exec_pipe(t_btree **ast) data = data_singleton(); p = &data_singleton()->exec.process; 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]; start = IS_PIPESTART(p->attributes); p->toclose = fds[PIPE_READ]; diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index 6409bf9b..e3e1f757 100644 --- a/42sh/src/exec/launch_process.c +++ b/42sh/src/exec/launch_process.c @@ -18,7 +18,6 @@ int launch_process(t_process *p) int pid; exec = &data_singleton()->exec; - DG("launching"); if (p->attributes & PROCESS_UNKNOWN) { 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)) { - DG("check 0"); if (process_redirect(p)) return (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); return (1); } - DG("gonna fork now"); pid = fork(); if (pid == 0) { diff --git a/42sh/src/exec/process_setexec.c b/42sh/src/exec/process_setexec.c index e5d0860d..348a2f30 100644 --- a/42sh/src/exec/process_setexec.c +++ b/42sh/src/exec/process_setexec.c @@ -14,6 +14,7 @@ int process_setexec(t_type type, t_process *p) { + p->path = NULL; if (type == TK_SUBSHELL) { p->execf = &execve; @@ -21,7 +22,9 @@ int process_setexec(t_type type, t_process *p) p->path = ft_strdup(p->av[0]); } else if ((p->execf = is_builtin(p))) + { p->attributes |= PROCESS_BUILTIN; + } else if (ft_strchr(p->av[0], '/')) { p->execf = &execve; diff --git a/42sh/src/job-control/put_job_in_foreground.c b/42sh/src/job-control/put_job_in_foreground.c index 187ca02f..4985e4c4 100644 --- a/42sh/src/job-control/put_job_in_foreground.c +++ b/42sh/src/job-control/put_job_in_foreground.c @@ -26,8 +26,11 @@ int put_job_in_foreground(t_job *j, int cont) if (kill(-j->pgid, SIGCONT) < 0) DG("kill(SIGCONT) failed"); } + DG("check 00"); job_wait(j->id); + DG("check 01"); job_remove(j->id); + DG("check 02"); tcsetpgrp(STDIN, jobc->shell_pgid);