1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-12-28 16:15:02 +01:00

Add some more debug.

This commit is contained in:
Peter Stephenson 2018-09-07 11:16:23 +01:00 committed by Peter Stephenson
parent efe470254c
commit b470d6fa70
3 changed files with 51 additions and 12 deletions

View file

@ -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);

View file

@ -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);
}
/**/

View file

@ -3314,7 +3314,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)