Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 5 May 1998 12:29:17 +0200
From:      Martin Cracauer <cracauer@cons.org>
To:        Bruce Evans <bde@zeta.org.au>, cracauer@cons.org, freebsd-current@FreeBSD.ORG
Subject:   Re: make/SIGINT (Re: cvs commit: src/bin/sh jobs.c)
Message-ID:  <19980505122917.01946@cons.org>
In-Reply-To: <19980422101203.65361@cons.org>; from Martin Cracauer on Wed, Apr 22, 1998 at 10:12:03AM %2B0200
References:  <199804191143.VAA00099@godzilla.zeta.org.au> <19980422101203.65361@cons.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--ReaqsoxgOBHFXBhH
Content-Type: text/plain; charset=us-ascii

In <19980422101203.65361@cons.org>, Martin Cracauer wrote: 
> > I thought that this bunch of changes (at least to shell and make) was
> > ready to commit until a few minutes ago when I tried to kill a `make
> > depend' in src/lib.  It didn't work - some sub-make[s] kept running.
> 
> It's mkdep(1)'s fault:
> 
>   trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
> 
> But our sh is broken so it can't be fixed. When a trap handler sets
> SIGINT to default (means exit with signal status) a `kill -INT $$`
> apparently doesn't work. 

Appended are diffs for mkdep, so that it kills itself on trap and a
modified version of your sh fix so that killing oneself in a trap
handler works. 

I updated my sh testsuite with 3 tests for these kind of things
(test20 - 22). I also changed the expectation for two tests. It's
moved to
http://www.freebsd.org/~cracauer/prg/test/sh-interrupt/testsuite/

The only test this sh version still fails on is that the wait builtin
isn't interruptable by SIGINT.

Martin
-- 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Martin Cracauer <cracauer@cons.org> http://www.cons.org/cracauer
  cracauer@wavehh.hanse.de (batched, preferred for large mails)
  Tel.: (daytime) +4940 41478712 Fax.: (daytime) +4940 41478715
  Tel.: (private) +4940 5221829 Fax.: (private) +4940 5228536
  Paper: (private) Waldstrasse 200, 22846 Norderstedt, Germany

--ReaqsoxgOBHFXBhH
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=diff

? sh
? init.c
? l
? syntax.h
? mknodes
? nodes.h
? mksyntax
? nodes.c
? token.h
? mkinit
? builtins.c
? sh.1.gz
? builtins.h
? syntax.c
? old
Index: error.c
===================================================================
RCS file: /home/ftp/pub/FreeBSD/CVS-FreeBSD/src/bin/sh/error.c,v
retrieving revision 1.9
diff -c -r1.9 error.c
*** error.c	1997/04/28 03:06:33	1.9
--- error.c	1998/05/05 10:20:53
***************
*** 50,55 ****
--- 50,56 ----
  #include "output.h"
  #include "error.h"
  #include "show.h"
+ #include "trap.h"
  #include <signal.h>
  #include <unistd.h>
  #include <errno.h>
***************
*** 89,116 ****
   * Called from trap.c when a SIGINT is received.  (If the user specifies
   * that SIGINT is to be trapped or ignored using the trap builtin, then
   * this routine is not called.)  Suppressint is nonzero when interrupts
!  * are held using the INTOFF macro.  The call to _exit is necessary because
!  * there is a short period after a fork before the signal handlers are
!  * set to the appropriate value for the child.  (The test for iflag is
!  * just defensive programming.)
   */
  
  void
  onint() {
  	sigset_t sigset;
  
! 	if (suppressint) {
  		intpending++;
  		return;
  	}
  	intpending = 0;
  	sigemptyset(&sigset);
  	sigprocmask(SIG_SETMASK, &sigset, NULL);
! 	out2str("\n");
! 	if (rootshell && iflag)
  		exraise(EXINT);
! 	else
! 		_exit(128 + SIGINT);
  }
  
  
--- 90,124 ----
   * Called from trap.c when a SIGINT is received.  (If the user specifies
   * that SIGINT is to be trapped or ignored using the trap builtin, then
   * this routine is not called.)  Suppressint is nonzero when interrupts
!  * are held using the INTOFF macro.  If SIGINTs are not suppressed and
!  * the shell is not a root shell, then we want to be terminated if we
!  * get here, as if we were terminated directly by a SIGINT.  Arrange for
!  * this here.
   */
  
  void
  onint() {
  	sigset_t sigset;
  
! 	/* The !in_dotrap is save. The only way we can arrive here with
! 	 * in_dotrap set is that a trap handler set SIGINT to default
! 	 * and killed itself.
! 	 */
! 
! 	if (suppressint && !in_dotrap) {
  		intpending++;
  		return;
  	}
  	intpending = 0;
  	sigemptyset(&sigset);
  	sigprocmask(SIG_SETMASK, &sigset, NULL);
! 	write(STDERR_FILENO, "\n", 1);
! 	if (rootshell /* && iflag ?? */)
  		exraise(EXINT);
! 	else {
! 		signal(SIGINT, SIG_DFL);
! 		kill(getpid(), SIGINT);
! 	}
  }
  
  
Index: jobs.c
===================================================================
RCS file: /home/ftp/pub/FreeBSD/CVS-FreeBSD/src/bin/sh/jobs.c,v
retrieving revision 1.19
diff -c -r1.19 jobs.c
*** jobs.c	1998/02/06 23:50:39	1.19
--- jobs.c	1998/05/05 10:20:53
***************
*** 725,733 ****
  		st = WTERMSIG(status) + 128;
  	if (! JOBS || jp->state == JOBDONE)
  		freejob(jp);
! 	CLEAR_PENDING_INT;
! 	if (WIFSIGNALED(status) && WTERMSIG(status) == SIGINT)
! 		kill(getpid(), SIGINT);
  	INTON;
  	return st;
  }
--- 725,736 ----
  		st = WTERMSIG(status) + 128;
  	if (! JOBS || jp->state == JOBDONE)
  		freejob(jp);
! 	if (int_pending()) {
! 		if (WIFSIGNALED(status) && WTERMSIG(status) == SIGINT)
! 			kill(getpid(), SIGINT);
! 		else
! 			CLEAR_PENDING_INT;
! 	}
  	INTON;
  	return st;
  }
Index: trap.c
===================================================================
RCS file: /home/ftp/pub/FreeBSD/CVS-FreeBSD/src/bin/sh/trap.c,v
retrieving revision 1.10
diff -c -r1.10 trap.c
*** trap.c	1997/11/10 11:32:23	1.10
--- trap.c	1998/05/05 10:20:53
***************
*** 73,79 ****
  
  
  MKINIT char sigmode[NSIG];	/* current value of signal */
! int pendingsigs;			/* indicates some signal received */
  static char *trap[NSIG];	/* trap handler commands */
  static char gotsig[NSIG];	/* indicates specified signal received */
  static int ignore_sigchld;	/* Used while handling SIGCHLD traps. */
--- 73,80 ----
  
  
  MKINIT char sigmode[NSIG];	/* current value of signal */
! int pendingsigs;		/* indicates some signal received */
! int in_dotrap = 0;		/* Do we execute in a trap handler? */
  static char *trap[NSIG];	/* trap handler commands */
  static char gotsig[NSIG];	/* indicates specified signal received */
  static int ignore_sigchld;	/* Used while handling SIGCHLD traps. */
***************
*** 219,229 ****
  		action = S_CATCH;
  	else
  		action = S_IGN;
! 	if (rootshell && action == S_DFL) {
  		switch (signo) {
  		case SIGINT:
! 			if (iflag)
! 				action = S_CATCH;
  			break;
  		case SIGQUIT:
  #ifdef DEBUG
--- 220,229 ----
  		action = S_CATCH;
  	else
  		action = S_IGN;
! 	if (action == S_DFL) {
  		switch (signo) {
  		case SIGINT:
! 			action = S_CATCH;
  			break;
  		case SIGQUIT:
  #ifdef DEBUG
***************
*** 234,248 ****
  				break;
  			}
  #endif
! 			/* FALLTHROUGH */
  		case SIGTERM:
! 			if (iflag)
  				action = S_IGN;
  			break;
  #if JOBS
  		case SIGTSTP:
  		case SIGTTOU:
! 			if (mflag)
  				action = S_IGN;
  			break;
  #endif
--- 234,249 ----
  				break;
  			}
  #endif
! 			action = S_IGN;
! 			break;
  		case SIGTERM:
! 			if (rootshell && iflag)
  				action = S_IGN;
  			break;
  #if JOBS
  		case SIGTSTP:
  		case SIGTTOU:
! 			if (rootshell && mflag)
  				action = S_IGN;
  			break;
  #endif
***************
*** 367,372 ****
--- 368,374 ----
  	int i;
  	int savestatus;
  
+ 	in_dotrap++;
  	for (;;) {
  		for (i = 1; i < NSIG; i++) {
  			if (gotsig[i]) {
***************
*** 390,395 ****
--- 392,398 ----
  		if (i >= NSIG)
  			break;
  	}
+ 	in_dotrap--;
  	pendingsigs = 0;
  }
  
***************
*** 401,407 ****
  setinteractive(on)
  	int on;
  {
! 	static int is_interactive = 0;
  
  	if (on == is_interactive)
  		return;
--- 404,410 ----
  setinteractive(on)
  	int on;
  {
! 	static int is_interactive = -1;
  
  	if (on == is_interactive)
  		return;
Index: trap.h
===================================================================
RCS file: /home/ftp/pub/FreeBSD/CVS-FreeBSD/src/bin/sh/trap.h,v
retrieving revision 1.7
diff -c -r1.7 trap.h
*** trap.h	1997/11/10 11:32:24	1.7
--- trap.h	1998/05/05 10:20:53
***************
*** 38,43 ****
--- 38,44 ----
   */
  
  extern int pendingsigs;
+ extern int in_dotrap;
  
  int trapcmd __P((int, char **));
  void clear_traps __P((void));

--ReaqsoxgOBHFXBhH
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=diff2

Index: mkdep.gcc.sh
===================================================================
RCS file: /home/ftp/pub/FreeBSD/CVS-FreeBSD/src/usr.bin/mkdep/mkdep.gcc.sh,v
retrieving revision 1.12
diff -c -r1.12 mkdep.gcc.sh
*** mkdep.gcc.sh	1997/02/22 19:56:10	1.12
--- mkdep.gcc.sh	1998/05/05 08:33:06
***************
*** 68,74 ****
  esac
  
  TMP=_mkdep$$
! trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
  trap 'rm -f $TMP' 0
  
  # For C sources, mkdep must use exactly the same cpp and predefined flags
--- 68,74 ----
  esac
  
  TMP=_mkdep$$
! trap 'rm -f $TMP ; trap 2 ; kill -2 $$' 1 2 3 13 15
  trap 'rm -f $TMP' 0
  
  # For C sources, mkdep must use exactly the same cpp and predefined flags
Index: mkdep.sh
===================================================================
RCS file: /home/ftp/pub/FreeBSD/CVS-FreeBSD/src/usr.bin/mkdep/mkdep.sh,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 mkdep.sh
*** mkdep.sh	1994/05/27 12:32:18	1.1.1.1
--- mkdep.sh	1998/05/05 08:33:06
***************
*** 69,75 ****
  
  TMP=/tmp/mkdep$$
  
! trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
  
  cc -M $* |
  sed "
--- 69,75 ----
  
  TMP=/tmp/mkdep$$
  
! trap 'rm -f $TMP ; trap 2 ; kill -2 $$' 1 2 3 13 15
  
  cc -M $* |
  sed "

--ReaqsoxgOBHFXBhH--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19980505122917.01946>