Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 8 Feb 1998 02:56:19 +1100
From:      Bruce Evans <bde@zeta.org.au>
To:        bde@zeta.org.au, cracauer@cons.org
Cc:        cracauer@FreeBSD.ORG, cvs-all@FreeBSD.ORG, cvs-bin@FreeBSD.ORG, cvs-committers@FreeBSD.ORG
Subject:   Re: cvs commit: src/bin/sh jobs.c
Message-ID:  <199802071556.CAA12906@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>OK, I'm convinced it isn't as easy as I thought. We're in bad need for
>clarification what the desired behaviour is.

It's becoming messier in my version too.  The triple ^C's were necessary
because the subshells exited with a status of 128 + SIGINT and weren't
killed by a signal.  sh and (apparently) bash have special handling
for the case where a subshell is killed by SIGINT.  They send themself
a SIGINT in this case.  This should kill them if SIGINT wasn't ignored
initially and isn't trapped.  This was broken in my version because the
SIGINT was caught.  This version calls setsignal() just before the kill
to get the correct handling.  It frobs `rootshell' to avoid getting the
normal handling.  I think the complications handled by setsignal() must
be handled somewhere in your version too.

Here's another difference in behaviour:

---
#!/bin/sh
cat
pwd
---

If `cat' but not the shell is killed by SIGINT, then sh kills itself,
but bash doesn't.  sh should probably only kill itself if (intpending).

Bruce

diff -c2 error.c~ error.c
*** error.c~	Tue Apr 29 04:24:04 1997
--- error.c	Sun Feb  8 01:15:44 1998
***************
*** 107,111 ****
  	sigemptyset(&sigset);
  	sigprocmask(SIG_SETMASK, &sigset, NULL);
! 	out2str("\n");
  	if (rootshell && iflag)
  		exraise(EXINT);
--- 107,111 ----
  	sigemptyset(&sigset);
  	sigprocmask(SIG_SETMASK, &sigset, NULL);
! 	write(STDERR_FILENO, "\n", 1);
  	if (rootshell && iflag)
  		exraise(EXINT);
diff -c2 jobs.c~ jobs.c
*** jobs.c~	Sun Feb  8 01:25:10 1998
--- jobs.c	Sun Feb  8 01:44:43 1998
***************
*** 636,640 ****
  		}
  #endif
! 		if (wasroot && iflag) {
  			setsignal(SIGINT);
  			setsignal(SIGQUIT);
--- 636,640 ----
  		}
  #endif
! 		if (wasroot) {
  			setsignal(SIGINT);
  			setsignal(SIGQUIT);
***************
*** 695,698 ****
--- 695,699 ----
  	int status;
  	int st;
+ 	int wasroot;
  
  	INTOFF;
***************
*** 727,732 ****
  		freejob(jp);
  	CLEAR_PENDING_INT;
! 	if (WIFSIGNALED(status) && WTERMSIG(status) == SIGINT)
  		kill(getpid(), SIGINT);
  	INTON;
  	return st;
--- 728,739 ----
  		freejob(jp);
  	CLEAR_PENDING_INT;
! 	if (WIFSIGNALED(status) && WTERMSIG(status) == SIGINT) {
! 		wasroot = rootshell;
! 		rootshell = 0;		/* XXX */
! 		setsignal(SIGINT);
! 		rootshell = wasroot;
  		kill(getpid(), SIGINT);
+ 		setsignal(SIGINT);
+ 	}
  	INTON;
  	return st;
diff -c2 trap.c~ trap.c
*** trap.c~	Tue Nov 11 18:15:35 1997
--- trap.c	Sat Feb  7 22:05:34 1998
***************
*** 223,228 ****
  		switch (signo) {
  		case SIGINT:
! 			if (iflag)
! 				action = S_CATCH;
  			break;
  		case SIGQUIT:
--- 223,227 ----
  		switch (signo) {
  		case SIGINT:
! 			action = S_CATCH;
  			break;
  		case SIGQUIT:
***************
*** 237,242 ****
  			/* FALLTHROUGH */
  		case SIGTERM:
! 			if (iflag)
! 				action = S_IGN;
  			break;
  #if JOBS
--- 236,240 ----
  			/* FALLTHROUGH */
  		case SIGTERM:
! 			action = S_IGN;
  			break;
  #if JOBS
***************
*** 402,406 ****
  	int on;
  {
! 	static int is_interactive = 0;
  
  	if (on == is_interactive)
--- 400,404 ----
  	int on;
  {
! 	static int is_interactive = -1;
  
  	if (on == is_interactive)



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