From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27224 invoked by alias); 12 Mar 2015 19:58:27 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 34708 Received: (qmail 18566 invoked from network); 12 Mar 2015 19:58:22 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-Originating-IP: [86.6.153.127] X-Spam: 0 X-Authority: v=2.1 cv=RdIeCjdv c=1 sm=1 tr=0 a=39NrsSuza2clQiZR/7fYWQ==:117 a=39NrsSuza2clQiZR/7fYWQ==:17 a=kj9zAlcOel0A:10 a=NLZqzBF-AAAA:8 a=CjxXgO3LAAAA:8 a=4qd6y42tUMTUuvPv6jEA:9 a=CjuIK1q_8ugA:10 Date: Thu, 12 Mar 2015 19:58:14 +0000 From: Peter Stephenson To: John , Zsh hackers list Subject: Re: Bug: ZSH crashes upon receiving SIGINT Message-ID: <20150312195814.52aa6bed@ntlworld.com> In-Reply-To: <91460363.4306421.1426117627753.JavaMail.yahoo@mail.yahoo.com> References: <91460363.4306421.1426117627753.JavaMail.yahoo@mail.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 11 Mar 2015 23:47:07 +0000 (UTC) John 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;