From 0616ab05b795ffedb746799fe1b44a80d20e8505 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 +++++++++++++++++++++++++++++++++++++++++++ Src/utils.c | 18 +++++++----------- Src/zsh.h | 2 +- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/Src/exec.c b/Src/exec.c index c46d32e7e..5d0701d88 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 */ /**/ @@ -999,6 +1010,9 @@ static void entersubsh(int flags) { 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++) @@ -1030,6 +1044,19 @@ entersubsh(int flags) 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 } } else if (!jobtab[thisjob].gleader || @@ -1068,6 +1095,7 @@ entersubsh(int flags) 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 @@ -1080,6 +1108,7 @@ entersubsh(int flags) } 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, @@ -1090,6 +1119,20 @@ entersubsh(int flags) 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); diff --git a/Src/utils.c b/Src/utils.c index 42f6ab773..342e31f53 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -4651,8 +4651,9 @@ attachtty(pid_t pgrp if (jobbing && interact) { #ifdef DEBUG_JOB_CONTROL - fprintf(stderr, "attachtty(%d): pgrp = %d, mypgrp = %d\n", - index, pgrp, mypgrp); + fprintf(stderr, "attachtty(%d): pgrp = %d, mypgrp = %d, curpid = %d\n", + index, pgrp, mypgrp, getpid()); + fflush(stderr); #endif #ifdef HAVE_TCSETPGRP if (SHTTY != -1 && tcsetpgrp(SHTTY, pgrp) == -1 && !ep) @@ -4668,6 +4669,7 @@ attachtty(pid_t pgrp { #ifdef DEBUG_JOB_CONTROL fprintf(stderr, "attachtty failed\n"); + fflush(stderr); #endif if (pgrp != mypgrp && kill(-pgrp, 0) == -1) ATTACHTTY(mypgrp, 16); @@ -4690,15 +4692,9 @@ attachtty(pid_t pgrp void set_gleader(int job, int pid, int index) { jobtab[job].gleader = pid; - fprintf(stderr, "set_gleader(%d): %d = %d\n", index, job, pid); -} - -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, ret %d\n", - index, pid, pgid, getpid(), ret); - return ret; + fprintf(stderr, "set_gleader(%d): %d = %d, curpid = %d\n", index, job, pid, + getpid()); + fflush(stderr); } /**/ diff --git a/Src/zsh.h b/Src/zsh.h index bcad47b20..53e1a44cb 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -3306,7 +3306,7 @@ typedef int convchar_t; /* Uncomment to debug problems with job control */ -/*#define DEBUG_JOB_CONTROL*/ +#define DEBUG_JOB_CONTROL #ifdef DEBUG_JOB_CONTROL #define ATTACHTTY(pgrp, index) attachtty(pgrp, index) -- cgit 1.4.1