From b470d6fa709b3afbd4f2f4448ab289ec5a300a73 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 7 Sep 2018 11:16:23 +0100 Subject: Add some more debug. --- Src/exec.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'Src/exec.c') diff --git a/Src/exec.c b/Src/exec.c index ad709d307..d6e045770 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -423,6 +423,17 @@ static int nowait, pline_level = 0; static int list_pipe_child = 0, list_pipe_job; static char list_pipe_text[JOBTEXTSIZE]; +#ifdef DEBUG_JOB_CONTROL +int setpgrp_debug(int pid, int pgid, int index) +{ + int ret = setpgrp(pid, pgid); + fprintf(stderr, "setpgrp(%d): pid %d, pgid %d, current pid %d, lpj = %d, gleader = %d, ret %d\n", + index, pid, pgid, getpid(), list_pipe_job, jobtab[list_pipe_job].gleader, ret); + fflush(stderr); + return ret; +} +#endif + /* execute a current shell command */ /**/ @@ -1005,6 +1016,9 @@ static void entersubsh(int flags, struct entersubsh_ret *retp) { int i, sig, monitor, job_control_ok; +#ifdef DEBUG_JOB_CONTROL + int check_later = 0; +#endif if (!(flags & ESUB_KEEPTRAP)) for (sig = 0; sig < SIGCOUNT; sig++) @@ -1036,6 +1050,19 @@ entersubsh(int flags, struct entersubsh_ret *retp) SETPGRP(0L, jobtab[list_pipe_job].gleader, 2); if (!(flags & ESUB_ASYNC)) ATTACHTTY(jobtab[thisjob].gleader, 2); + } else if (gettygrp() == GETPGRP()) { + /* + * There are races where if the process is attached + * to the terminal blocking SIGTTOU causes errors. + * So just leave signals alone. + */ + /* job_control_ok = 1;*/ /* Probably not a * fix */ +#ifdef DEBUG_JOB_CONTROL + fprintf(stderr, "pid = %d, gleader = %d, pgrp = %d, list_pipe_child = %d, mypgrp = %d\n", + getpid(), jobtab[list_pipe_job].gleader, + getpgrp(), list_pipe_child, mypgrp); + check_later = 1; +#endif } if (retp) { retp->gleader = jobtab[list_pipe_job].gleader; @@ -1083,6 +1110,7 @@ entersubsh(int flags, struct entersubsh_ret *retp) if (flags & ESUB_NOMONITOR) { #ifdef DEBUG_JOB_CONTROL fprintf(stderr, "subsh with no monitor, blocking signals\n"); + fflush(stderr); #endif /* * Allowing any form of interactive signalling here is @@ -1095,6 +1123,7 @@ entersubsh(int flags, struct entersubsh_ret *retp) } else if (!job_control_ok) { #ifdef DEBUG_JOB_CONTROL fprintf(stderr, "subsh with no job control, blocking signals\n"); + fflush(stderr); #endif /* * If this process is not going to be doing job control, @@ -1105,6 +1134,20 @@ entersubsh(int flags, struct entersubsh_ret *retp) signal_default(SIGTTOU); signal_default(SIGTTIN); signal_default(SIGTSTP); +#ifdef DEBUG_JOB_CONTROL + if (check_later) + { + if (SETPGRP(0L, jobtab[list_pipe_job].gleader, 101) == -1 || + kill(jobtab[list_pipe_job].gleader, 0) == -1) { + SET_GLEADER(list_pipe_job, + (list_pipe_child ? mypgrp : getpid()), 101); + SET_GLEADER(thisjob, jobtab[list_pipe_job].gleader, 102); + SETPGRP(0L, jobtab[list_pipe_job].gleader, 102); + if (!(flags & ESUB_ASYNC)) + ATTACHTTY(jobtab[thisjob].gleader, 102); + } + } +#endif } if (interact) { signal_default(SIGTERM); -- cgit 1.4.1