diff --git a/42sh/src/exec/exec_command.c b/42sh/src/exec/exec_command.c index 6a6924fc..13b002f5 100644 --- a/42sh/src/exec/exec_command.c +++ b/42sh/src/exec/exec_command.c @@ -57,7 +57,8 @@ int exec_command(t_btree **ast) } p->av = NULL; p->pid = 0; - p->attributes = PROCESS_PIPESTART | PROCESS_PIPEEND; + /* p->attributes = PROCESS_PIPESTART | PROCESS_PIPEEND; */ + p->attributes &= ~(PROCESS_STATE_MASK | PROCESS_TYPE_MASK); btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/exec/process_setgroup.c b/42sh/src/exec/process_setgroup.c index afac9487..e9db1959 100644 --- a/42sh/src/exec/process_setgroup.c +++ b/42sh/src/exec/process_setgroup.c @@ -23,13 +23,12 @@ int process_setgroup(t_process *p, pid_t pid) j = &data_singleton()->exec.job; if (!j->pgid) j->pgid = pid ? pid : getpid(); - DG("in pid %i gonna setpgid(%i, %i)", getpid(), pid, j->pgid); + DG("pid:%i gonna setpgid(%i, %i)", getpid(), pid, j->pgid); setpgid(pid, j->pgid); if (pid == 0 && JOB_IS_FG(j->attributes)) { - signal(SIGTTOU, SIG_IGN); + DG("pid:%i gonna setpgrp(%i)", getpid(), j->pgid); tcsetpgrp(STDIN, j->pgid); - signal(SIGTTOU, SIG_DFL); } return (0); } diff --git a/42sh/src/exec/process_setsig.c b/42sh/src/exec/process_setsig.c index 920424cc..b2a68b09 100644 --- a/42sh/src/exec/process_setsig.c +++ b/42sh/src/exec/process_setsig.c @@ -2,7 +2,7 @@ void process_setsig(void) { - signal(SIGINT, SIG_DFL); + /* signal(SIGINT, SIG_DFL); */ signal(SIGQUIT, SIG_DFL); signal(SIGTSTP, SIG_DFL); signal(SIGTTIN, SIG_DFL); diff --git a/42sh/src/job-control/job_run.c b/42sh/src/job-control/job_run.c index ce5c0f07..bd9d0f48 100644 --- a/42sh/src/job-control/job_run.c +++ b/42sh/src/job-control/job_run.c @@ -16,5 +16,8 @@ void job_run(t_job *job, int foreground) { mark_job_as_running(job); job_format(job, JOBS_OPTS_L); - foreground ? put_job_in_foreground(job, 1) : put_job_in_background(job, 1); + if (foreground) + put_job_in_foreground(job, 1); + else + put_job_in_background(job, 1); } diff --git a/42sh/src/job-control/job_wait.c b/42sh/src/job-control/job_wait.c index 1c49950a..4bfb6b60 100644 --- a/42sh/src/job-control/job_wait.c +++ b/42sh/src/job-control/job_wait.c @@ -17,8 +17,10 @@ int job_wait(int id) pid_t pid; int status; - if (job_is_stopped(id) || job_is_completed(id)) + DG("waiting for [%i]", id); + if (job_is_stopped(id)) return (0); + job_update_status(); pid = waitpid(WAIT_ANY, &status, WUNTRACED); while (!process_mark_status(pid, status) && !job_is_completed(id) diff --git a/42sh/src/job-control/process_mark_status.c b/42sh/src/job-control/process_mark_status.c index b02290e7..21cf949c 100644 --- a/42sh/src/job-control/process_mark_status.c +++ b/42sh/src/job-control/process_mark_status.c @@ -32,7 +32,7 @@ int process_mark_status(pid_t pid, int status) p->attributes |= PROCESS_COMPLETED; if (WIFSIGNALED(status)) ft_printf("{mag}%d: Terminated by signal %d.\n{eoc}", - (int)pid, WTERMSIG(p->status)); + (int)pid, WTERMSIG(status)); } return (0); } diff --git a/42sh/src/job-control/put_job_in_background.c b/42sh/src/job-control/put_job_in_background.c index 40820cc2..02357157 100644 --- a/42sh/src/job-control/put_job_in_background.c +++ b/42sh/src/job-control/put_job_in_background.c @@ -16,6 +16,6 @@ int put_job_in_background(t_job *j, int cont) { if (cont) if (kill(-j->pgid, SIGCONT) < 0) - DG("kill (SIGCONT) malfunction"); + DG("kill(SIGCONT) failed"); return (0); } diff --git a/42sh/src/job-control/put_job_in_foreground.c b/42sh/src/job-control/put_job_in_foreground.c index 65ee9de3..0f462a1a 100644 --- a/42sh/src/job-control/put_job_in_foreground.c +++ b/42sh/src/job-control/put_job_in_foreground.c @@ -17,16 +17,21 @@ int put_job_in_foreground(t_job *j, int cont) t_jobc *jobc; jobc = &data_singleton()->jobc; - tcsetpgrp (STDIN, j->pgid); + DG("pid:%i gonna setpgrp(%i) (JOB)", getpid(), j->pgid); + tcsetpgrp(STDIN, j->pgid); + tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes); + if (cont) { tcsetattr(STDIN, TCSADRAIN, &j->tmodes); if (kill(-j->pgid, SIGCONT) < 0) - DG("kill (SIGCONT) malfunction"); + DG("kill(SIGCONT) failed"); } job_wait(j->id); + DG("finished waiting for [%i]", j->id); job_remove(j->id); + DG("pid:%i gonna setpgrp(%i) (SHELL)", getpid(), jobc->shell_pgid); tcsetpgrp(STDIN, jobc->shell_pgid); tcgetattr(STDIN, &j->tmodes); diff --git a/42sh/src/job-control/sigint_handler.c b/42sh/src/job-control/sigint_handler.c index de5ec7dd..9ca6a1b3 100644 --- a/42sh/src/job-control/sigint_handler.c +++ b/42sh/src/job-control/sigint_handler.c @@ -15,5 +15,5 @@ void sigint_handler(int signo) { (void)signo; - DG("got SIGINT in process %i", getpid()); + DG("pid:%i got SIGINT", getpid()); } diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c index 67a48bbd..28c4beaa 100644 --- a/42sh/src/line-editing/readline.c +++ b/42sh/src/line-editing/readline.c @@ -66,6 +66,7 @@ void ft_reset_stats_term(int signal) int ft_readline(void) { signal(SIGWINCH, ft_reset_stats_term); + ft_save_stats_term(); if (tcsetattr(0, TCSANOW, ft_stats_term_termcaps()) == -1) return (-1); if (data_singleton()->line.input)