From owner-svn-src-all@FreeBSD.ORG Sat Feb 23 22:50:59 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 3A167F8E; Sat, 23 Feb 2013 22:50:59 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 1D2398ED; Sat, 23 Feb 2013 22:50:59 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id r1NMowql084231; Sat, 23 Feb 2013 22:50:59 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id r1NMovZE084223; Sat, 23 Feb 2013 22:50:57 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201302232250.r1NMovZE084223@svn.freebsd.org> From: Jilles Tjoelker Date: Sat, 23 Feb 2013 22:50:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r247206 - in head: bin/sh tools/regression/bin/sh/builtins X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 23 Feb 2013 22:50:59 -0000 Author: jilles Date: Sat Feb 23 22:50:57 2013 New Revision: 247206 URL: http://svnweb.freebsd.org/changeset/base/247206 Log: sh: If a SIGINT or SIGQUIT interrupts "wait", return status 128+sig. Added: head/tools/regression/bin/sh/builtins/wait4.0 (contents, props changed) head/tools/regression/bin/sh/builtins/wait5.0 (contents, props changed) Modified: head/bin/sh/eval.c head/bin/sh/jobs.c head/bin/sh/main.c head/bin/sh/trap.c head/bin/sh/trap.h Modified: head/bin/sh/eval.c ============================================================================== --- head/bin/sh/eval.c Sat Feb 23 22:48:12 2013 (r247205) +++ head/bin/sh/eval.c Sat Feb 23 22:50:57 2013 (r247206) @@ -301,7 +301,7 @@ evaltree(union node *n, int flags) } while (n != NULL); out: popstackmark(&smark); - if (pendingsigs) + if (pendingsig) dotrap(); if (eflag && exitstatus != 0 && do_etest) exitshell(exitstatus); Modified: head/bin/sh/jobs.c ============================================================================== --- head/bin/sh/jobs.c Sat Feb 23 22:48:12 2013 (r247205) +++ head/bin/sh/jobs.c Sat Feb 23 22:50:57 2013 (r247206) @@ -521,7 +521,7 @@ waitcmd(int argc, char **argv) } while (dowait(DOWAIT_BLOCK | DOWAIT_SIG, (struct job *)NULL) != -1); in_waitcmd--; - return 0; + return pendingsig + 128; } Modified: head/bin/sh/main.c ============================================================================== --- head/bin/sh/main.c Sat Feb 23 22:48:12 2013 (r247205) +++ head/bin/sh/main.c Sat Feb 23 22:50:57 2013 (r247206) @@ -196,7 +196,7 @@ cmdloop(int top) TRACE(("cmdloop(%d) called\n", top)); setstackmark(&smark); for (;;) { - if (pendingsigs) + if (pendingsig) dotrap(); inter = 0; if (iflag && top) { Modified: head/bin/sh/trap.c ============================================================================== --- head/bin/sh/trap.c Sat Feb 23 22:48:12 2013 (r247205) +++ head/bin/sh/trap.c Sat Feb 23 22:50:57 2013 (r247206) @@ -73,7 +73,7 @@ __FBSDID("$FreeBSD$"); MKINIT char sigmode[NSIG]; /* current value of signal */ -int pendingsigs; /* indicates some signal received */ +volatile sig_atomic_t pendingsig; /* indicates some signal received */ int in_dotrap; /* do we execute in a trap handler? */ static char *volatile trap[NSIG]; /* trap handler commands */ static volatile sig_atomic_t gotsig[NSIG]; @@ -388,22 +388,25 @@ onsig(int signo) return; } - if (signo != SIGCHLD || !ignore_sigchld) - gotsig[signo] = 1; - pendingsigs++; - /* If we are currently in a wait builtin, prepare to break it */ - if ((signo == SIGINT || signo == SIGQUIT) && in_waitcmd != 0) - breakwaitcmd = 1; - /* - * If a trap is set, not ignored and not the null command, we need - * to make sure traps are executed even when a child blocks signals. - */ - if (Tflag && - trap[signo] != NULL && - ! (trap[signo][0] == '\0') && - ! (trap[signo][0] == ':' && trap[signo][1] == '\0')) + if ((signo == SIGINT || signo == SIGQUIT) && in_waitcmd != 0) { breakwaitcmd = 1; + pendingsig = signo; + } + + if (trap[signo] != NULL && trap[signo][0] != '\0' && + (signo != SIGCHLD || !ignore_sigchld)) { + gotsig[signo] = 1; + pendingsig = signo; + + /* + * If a trap is set, not ignored and not the null command, we + * need to make sure traps are executed even when a child + * blocks signals. + */ + if (Tflag && !(trap[signo][0] == ':' && trap[signo][1] == '\0')) + breakwaitcmd = 1; + } #ifndef NO_HISTORY if (signo == SIGWINCH) @@ -424,7 +427,7 @@ dotrap(void) in_dotrap++; for (;;) { - pendingsigs = 0; + pendingsig = 0; for (i = 1; i < NSIG; i++) { if (gotsig[i]) { gotsig[i] = 0; Modified: head/bin/sh/trap.h ============================================================================== --- head/bin/sh/trap.h Sat Feb 23 22:48:12 2013 (r247205) +++ head/bin/sh/trap.h Sat Feb 23 22:50:57 2013 (r247206) @@ -33,7 +33,7 @@ * $FreeBSD$ */ -extern int pendingsigs; +extern volatile sig_atomic_t pendingsig; extern int in_dotrap; extern volatile sig_atomic_t gotwinch; Added: head/tools/regression/bin/sh/builtins/wait4.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/bin/sh/builtins/wait4.0 Sat Feb 23 22:50:57 2013 (r247206) @@ -0,0 +1,12 @@ +# $FreeBSD$ + +T=`mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX` +trap 'rm -rf $T' 0 +cd $T || exit 3 +mkfifo fifo1 +trapped= +trap trapped=1 QUIT +{ kill -QUIT $$; sleep 1; exit 4; } >fifo1 & +wait $! fifo1 & +wait