From owner-svn-src-head@freebsd.org Fri Aug 28 15:35:47 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3C8B33B518E; Fri, 28 Aug 2020 15:35:47 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BdNwM0xLhz3VCb; Fri, 28 Aug 2020 15:35:47 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F31B516ED9; Fri, 28 Aug 2020 15:35:46 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 07SFZkJW020312; Fri, 28 Aug 2020 15:35:46 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 07SFZjKb020308; Fri, 28 Aug 2020 15:35:45 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <202008281535.07SFZjKb020308@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Fri, 28 Aug 2020 15:35:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r364919 - in head/bin/sh: . tests/execution X-SVN-Group: head X-SVN-Commit-Author: jilles X-SVN-Commit-Paths: in head/bin/sh: . tests/execution X-SVN-Commit-Revision: 364919 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Aug 2020 15:35:47 -0000 Author: jilles Date: Fri Aug 28 15:35:45 2020 New Revision: 364919 URL: https://svnweb.freebsd.org/changeset/base/364919 Log: sh: Keep ignored SIGINT/SIGQUIT after set in a background job If job control is not enabled, a background job (... &) ignores SIGINT and SIGQUIT, but this can be reverted using the trap builtin in the same shell environment. Using the set builtin to change options would also revert SIGINT and SIGQUIT to their previous dispositions. This broke due to r317298. Calling setsignal() reverts the effect of ignoresig(). Reported by: bdrewery MFC after: 1 week Added: head/bin/sh/tests/execution/bg13.0 (contents, props changed) Modified: head/bin/sh/main.c head/bin/sh/tests/execution/Makefile head/bin/sh/trap.c head/bin/sh/trap.h Modified: head/bin/sh/main.c ============================================================================== --- head/bin/sh/main.c Fri Aug 28 15:09:43 2020 (r364918) +++ head/bin/sh/main.c Fri Aug 28 15:35:45 2020 (r364919) @@ -134,6 +134,7 @@ main(int argc, char *argv[]) setstackmark(&smark); setstackmark(&smark2); procargs(argc, argv); + trap_init(); pwd_init(iflag); INTON; if (iflag) Modified: head/bin/sh/tests/execution/Makefile ============================================================================== --- head/bin/sh/tests/execution/Makefile Fri Aug 28 15:09:43 2020 (r364918) +++ head/bin/sh/tests/execution/Makefile Fri Aug 28 15:35:45 2020 (r364919) @@ -19,6 +19,7 @@ ${PACKAGE}FILES+= bg9.0 ${PACKAGE}FILES+= bg10.0 bg10.0.stdout ${PACKAGE}FILES+= bg11.0 ${PACKAGE}FILES+= bg12.0 +${PACKAGE}FILES+= bg13.0 ${PACKAGE}FILES+= env1.0 ${PACKAGE}FILES+= fork1.0 ${PACKAGE}FILES+= fork2.0 Added: head/bin/sh/tests/execution/bg13.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/bin/sh/tests/execution/bg13.0 Fri Aug 28 15:35:45 2020 (r364919) @@ -0,0 +1,16 @@ +# $FreeBSD$ + +T=`mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXXXX` +trap 'rm -rf $T' 0 +cd $T || exit 3 +mkfifo fifo1 +# Use a trap, not the default action, since the shell may catch SIGINT and +# therefore its processing may be delayed. +{ set -C; trap 'exit 5' TERM; read dummy fifo1 +kill -INT "$!" +kill -TERM "$!" +exec 3>&- +wait "$!" +r=$? +[ "$r" = 5 ] Modified: head/bin/sh/trap.c ============================================================================== --- head/bin/sh/trap.c Fri Aug 28 15:09:43 2020 (r364918) +++ head/bin/sh/trap.c Fri Aug 28 15:35:45 2020 (r364919) @@ -474,14 +474,20 @@ dotrap(void) } +void +trap_init(void) +{ + setsignal(SIGINT); + setsignal(SIGQUIT); +} + + /* * Controls whether the shell is interactive or not based on iflag. */ void setinteractive(void) { - setsignal(SIGINT); - setsignal(SIGQUIT); setsignal(SIGTERM); } Modified: head/bin/sh/trap.h ============================================================================== --- head/bin/sh/trap.h Fri Aug 28 15:09:43 2020 (r364918) +++ head/bin/sh/trap.h Fri Aug 28 15:35:45 2020 (r364919) @@ -45,6 +45,7 @@ void ignoresig(int); int issigchldtrapped(void); void onsig(int); void dotrap(void); +void trap_init(void); void setinteractive(void); void exitshell(int) __dead2; void exitshell_savedstatus(void) __dead2;