zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: John <da_audiophile@yahoo.com>, Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Bug: ZSH crashes upon receiving SIGINT
Date: Thu, 12 Mar 2015 19:58:14 +0000	[thread overview]
Message-ID: <20150312195814.52aa6bed@ntlworld.com> (raw)
In-Reply-To: <91460363.4306421.1426117627753.JavaMail.yahoo@mail.yahoo.com>

On Wed, 11 Mar 2015 23:47:07 +0000 (UTC)
John <da_audiophile@yahoo.com> 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;



  parent reply	other threads:[~2015-03-12 19:58 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-09 17:46 John
2015-03-10 10:46 ` Peter Stephenson
2015-03-10 11:16   ` Peter Stephenson
2015-03-10 22:06   ` John
2015-03-11  0:43     ` Bart Schaefer
2015-03-11  9:44       ` Peter Stephenson
2015-03-11 19:55         ` Peter Stephenson
2015-03-11 18:38       ` John
2015-03-11 20:09         ` Peter Stephenson
2015-03-11 23:23           ` John
2015-03-11 23:31             ` Bart Schaefer
2015-03-11 23:47               ` John
2015-03-12  5:11                 ` Andrew Janke
2015-03-12 19:06                   ` John
2015-03-12 19:58                 ` Peter Stephenson [this message]
2015-03-13  4:00                   ` Bart Schaefer
2015-03-13  6:44       ` Han Pingtian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150312195814.52aa6bed@ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=da_audiophile@yahoo.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).