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

Re: signal handling bug



hzoli@xxxxxxxxxx wrote:
> % zsh -c 'trap "echo Interrupt ; exit" INT ; while true ; do sleep 1 ; done'
> 
> After applying the patches, this is interruptible, but the trap is not
> executed (and it is interruptible even if I use trap - INT).

I was about to report failure when I had an idea (pity this doesn't
happen very often) and I've managed to fix the first half of the
problem, so what Robert the Bruce said is probably right.

The problem was the test for whether the job that just ran was in the
foreground:  it was relying on the job handling code, so didn't work
in a non-interactive shell.  I've separated the job handling part out
and set `inforeground' in updatestatus() simply according to whether
we are using the status of the current job to update the global status
variable, which sounds pretty plausible to me.  inforeground is later
tested to see if the trap should be run.

This doesn't fix the other half of the problem, that the job is
interruptible when supposedly ignoring SIGINT.  That's certainly a
separate problem, possibly beyond my signal knowledge (meaning of
course ``knowledge of signals'', rather than ``notable knowledge''),
but I'll probably take a look at it anyway.

Point to note: ksh M-11/16/88f (the most widespread version of ksh
'88) has the same problem --- the problem reported by Zoltan after the
previous set of patches, that is --- so we should feel either smug or
uneasy.

This patch is intended to go on top of all the other trap patches, of
course.  I don't know whether or not it actually needs them, but it's
pointless to use it without the others.

*** Src/jobs.c.spec	Mon Apr 15 11:45:03 1996
--- Src/jobs.c	Tue Apr 16 17:36:50 1996
***************
*** 123,140 ****
  	    return;
      } else {                   /* job is done, so remember return value */
  	lastval2 = val;
! 	/* If last process was run in the currrent shell, keep old status */
! 	if (job == thisjob && !(jn->stat & STAT_CURSH))
! 	    lastval = val;
      }
  
      pgrp = gettygrp();           /* get process group of tty      */
  
!     /* is this job in the foreground */
!     if (jn->gleader == pgrp || (pgrp > 1 && kill(-pgrp, 0) == -1))
! 	inforeground = 1;
! 
!     if (inforeground && !ttyfrozen && !val && !jn->stty_in_env)
  	gettyinfo(&shttyinfo);
      adjustwinsize();             /* check window size and adjust if necessary */
      if (somestopped && jn->stat & STAT_SUPERJOB)
--- 123,142 ----
  	    return;
      } else {                   /* job is done, so remember return value */
  	lastval2 = val;
! 	/* If last process was run in the current shell, keep old status
! 	 * and let it handle its own traps
! 	 */
! 	if (job == thisjob && !(jn->stat & STAT_CURSH)) {
! 	  lastval = val;
! 	  inforeground = 1;
! 	}
      }
  
      pgrp = gettygrp();           /* get process group of tty      */
  
!     /* is this job in the foreground of an interactive shell? */
!     if ((jn->gleader == pgrp || (pgrp > 1 && kill(-pgrp, 0) == -1)) &&
! 	!ttyfrozen && !val && !jn->stty_in_env)
  	gettyinfo(&shttyinfo);
      adjustwinsize();             /* check window size and adjust if necessary */
      if (somestopped && jn->stat & STAT_SUPERJOB)
-- 
Peter Stephenson <pws@xxxxxx>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77330
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.




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