Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bug: ZSH crashes upon receiving SIGINT



On Wed, 11 Mar 2015 23:47:07 +0000 (UTC)
John <da_audiophile@xxxxxxxxx> wrote:
> # zmodload zsh/parameter
> # print $options[MONITOR]
> off

OK, that means job control isn't enabled.  Most likely it wasn't enabled
from the start because the shell found something about the environment
that didn't work.  That points towards Bart's explanation --- if
job control isn't enabled, zsh won't pick up the ^C by itself, it'll go
to whatever process group zsh was started in.

The final check for whether it can be enabled is in the init_io()
function and then acquire_pgrp().  It looks like the line editor is
working, otherwise it wouldn't be exiting at the point it is, so that
probably means SHTTY (a rather odd choice of variable for the file
descriptor used by the line editor and job control) is sane.

We might be able to confirm with some instrumentation as below...
Note this will be quite verbose if job control does get enabled
and lots of processes get run as it outputs a message when the
foreground process changes.

Bart may well have more idea what might be going wrong and have more
idea what to instrument, however.

pws

diff --git a/Src/init.c b/Src/init.c
index 3e41fb9..d49a176 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -591,15 +591,21 @@ init_io(void)
 	zsfree(ttystrname);
 	ttystrname = ztrdup("");
     } else {
+	fprintf(stderr, "SHTTY is open\n");
 #ifdef FD_CLOEXEC
 	long fdflags = fcntl(SHTTY, F_GETFD, 0);
 	if (fdflags != (long)-1) {
 	    fdflags |= FD_CLOEXEC;
 	    fcntl(SHTTY, F_SETFD, fdflags);
+	    fprintf(stderr, "Attempted to set FD_CLOEXEC on SHTTY\n");
 	}
 #endif
-	if (!ttystrname)
+	if (!ttystrname) {
 	    ttystrname = ztrdup("/dev/tty");
+	    fprintf(stderr, "Couldn't get TTY name\n");
+	} else {
+	    fprintf(stderr, "TTY name is %s\n", ttystrname);
+	}
     }
 
     /* We will only use zle if shell is interactive, *
@@ -619,11 +625,15 @@ init_io(void)
     if (opts[MONITOR] && (SHTTY != -1)) {
 	origpgrp = GETPGRP();
         acquire_pgrp(); /* might also clear opts[MONITOR] */
-    } else
+    } else {
+	if (opts[MONITOR])
+	    fprintf(stderr, "No terminal for job control\n");
 	opts[MONITOR] = 0;
+    }
 #else
     opts[MONITOR] = 0;
 #endif
+    fflush(stderr);
 }
 
 /**/
diff --git a/Src/jobs.c b/Src/jobs.c
index 295f4c9..6c0a4f7 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -2741,8 +2741,10 @@ acquire_pgrp(void)
 	sigaddset(&blockset, SIGTTOU);
 	sigaddset(&blockset, SIGTSTP);
 	oldset = signal_block(blockset);
+	fprintf(stderr, "Starting with mypgrp = %d\n", mypgrp);
 	while ((ttpgrp = gettygrp()) != -1 && ttpgrp != mypgrp) {
 	    mypgrp = GETPGRP();
+	    fprintf(stderr, "mypgrp -> %d\n", mypgrp);
 	    if (mypgrp == mypid) {
 		if (!interact)
 		    break; /* attachtty() will be a no-op, give up */
@@ -2764,12 +2766,17 @@ acquire_pgrp(void)
 	    if (setpgrp(0, 0) == 0) {
 		mypgrp = mypid;
 		attachtty(mypgrp);
-	    } else
+	    } else {
 		opts[MONITOR] = 0;
+		fprintf(stderr, "setpgrp failed, abandoning job control\n");
+	    }
 	}
 	signal_setmask(oldset);
-    } else
+    } else {
+	fprintf(stderr, "mypgrp = %d, abandoning job control\n",
+		mypgrp);
 	opts[MONITOR] = 0;
+    }
 }
 
 /* revert back to the process group we came from (before acquire_pgrp) */
diff --git a/Src/utils.c b/Src/utils.c
index 3d12807..83e5459 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -4148,6 +4148,7 @@ attachtty(pid_t pgrp)
     static int ep = 0;
 
     if (jobbing && interact) {
+	fprintf(stderr, "Attaching TTY %d to %d\n", SHTTY, pgrp); 
 #ifdef HAVE_TCSETPGRP
 	if (SHTTY != -1 && tcsetpgrp(SHTTY, pgrp) == -1 && !ep)
 #else
@@ -4160,13 +4161,16 @@ attachtty(pid_t pgrp)
 # endif
 #endif
 	{
-	    if (pgrp != mypgrp && kill(-pgrp, 0) == -1)
+	    if (pgrp != mypgrp && kill(-pgrp, 0) == -1) {
+		fprintf(stderr, "Bad process group, attaching to mypgrp\n");
 		attachtty(mypgrp);
-	    else {
+	    } else {
 		if (errno != ENOTTY)
 		{
 		    zwarn("can't set tty pgrp: %e", errno);
 		    fflush(stderr);
+		} else {
+		    fprintf(stderr, "Received ENOTTY, no job control\n");
 		}
 		opts[MONITOR] = 0;
 		ep = 1;




Messages sorted by: Reverse Date, Date, Thread, Author