From owner-svn-src-all@FreeBSD.ORG Sat Apr 18 23:49:59 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C82B634D; Sat, 18 Apr 2015 23:49:59 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B617E312; Sat, 18 Apr 2015 23:49:59 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t3INnxpb002802; Sat, 18 Apr 2015 23:49:59 GMT (envelope-from bdrewery@FreeBSD.org) Received: (from bdrewery@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t3INnwZc002791; Sat, 18 Apr 2015 23:49:58 GMT (envelope-from bdrewery@FreeBSD.org) Message-Id: <201504182349.t3INnwZc002791@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: bdrewery set sender to bdrewery@FreeBSD.org using -f From: Bryan Drewery Date: Sat, 18 Apr 2015 23:49:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r281718 - in head/bin/sh: . tests/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.20 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, 18 Apr 2015 23:49:59 -0000 Author: bdrewery Date: Sat Apr 18 23:49:57 2015 New Revision: 281718 URL: https://svnweb.freebsd.org/changeset/base/281718 Log: sh: Fix the trap builtin to be POSIX-compliant for 'trap exit SIG' and 'trap n n...'. The parser considered 'trap exit INT' to reset the default for both EXIT and INT. This beahvior is not POSIX compliant. This was avoided if a value was specified for 'exit', but then disallows exiting with the signal received. A possible workaround is using ' exit'. However POSIX does allow this type of behavior if the parameters are all integers. Fix the handling for this and clarify its support in the manpage since it is specifically allowed by POSIX. Differential Revision: https://reviews.freebsd.org/D2325 Reviewed by: jilles MFC after: 2 weeks Added: head/bin/sh/tests/builtins/trap15.0 (contents, props changed) head/bin/sh/tests/builtins/trap16.0 (contents, props changed) Modified: head/bin/sh/sh.1 head/bin/sh/tests/builtins/Makefile head/bin/sh/trap.c Modified: head/bin/sh/sh.1 ============================================================================== --- head/bin/sh/sh.1 Sat Apr 18 23:08:52 2015 (r281717) +++ head/bin/sh/sh.1 Sat Apr 18 23:49:57 2015 (r281718) @@ -32,7 +32,7 @@ .\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95 .\" $FreeBSD$ .\" -.Dd February 22, 2015 +.Dd April 18, 2015 .Dt SH 1 .Os .Sh NAME @@ -2574,8 +2574,7 @@ the former causes the specified signal t and the latter causes the default action to be taken. Omitting the .Ar action -is another way to request the default action, for compatibility reasons this -usage is not recommended though. +and using only signal numbers is another way to request the default action. In a subshell or utility environment, the shell resets trapped (but not ignored) signals to the default action. The Modified: head/bin/sh/tests/builtins/Makefile ============================================================================== --- head/bin/sh/tests/builtins/Makefile Sat Apr 18 23:08:52 2015 (r281717) +++ head/bin/sh/tests/builtins/Makefile Sat Apr 18 23:49:57 2015 (r281718) @@ -137,6 +137,8 @@ FILES+= trap11.0 FILES+= trap12.0 FILES+= trap13.0 FILES+= trap14.0 +FILES+= trap15.0 +FILES+= trap16.0 FILES+= trap2.0 FILES+= trap3.0 FILES+= trap4.0 Added: head/bin/sh/tests/builtins/trap15.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/bin/sh/tests/builtins/trap15.0 Sat Apr 18 23:49:57 2015 (r281718) @@ -0,0 +1,5 @@ +# $FreeBSD$ + +(${SH} -c 'term(){ exit 5;}; trap term TERM; kill -TERM $$') & +wait >/dev/null 2>&1 $! +[ $? -eq 5 ] Added: head/bin/sh/tests/builtins/trap16.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/bin/sh/tests/builtins/trap16.0 Sat Apr 18 23:49:57 2015 (r281718) @@ -0,0 +1,20 @@ +# $FreeBSD$ + +traps=$(${SH} -c 'trap "echo bad" 0; trap - 0; trap') +[ -z "$traps" ] || exit 1 +traps=$(${SH} -c 'trap "echo bad" 0; trap "" 0; trap') +expected_traps=$(${SH} -c 'trap "" EXIT; trap') +[ "$traps" = "$expected_traps" ] || exit 2 +traps=$(${SH} -c 'trap "echo bad" 0; trap 0; trap') +[ -z "$traps" ] || exit 3 +traps=$(${SH} -c 'trap "echo bad" 0; trap -- 0; trap') +[ -z "$traps" ] || exit 4 +traps=$(${SH} -c 'trap "echo bad" 0 1 2; trap - 0 1 2; trap') +[ -z "$traps" ] || exit 5 +traps=$(${SH} -c 'trap "echo bad" 0 1 2; trap "" 0 1 2; trap') +expected_traps=$(${SH} -c 'trap "" EXIT HUP INT; trap') +[ "$traps" = "$expected_traps" ] || exit 6 +traps=$(${SH} -c 'trap "echo bad" 0 1 2; trap 0 1 2; trap') +[ -z "$traps" ] || exit 7 +traps=$(${SH} -c 'trap "echo bad" 0 1 2; trap -- 0 1 2; trap') +[ -z "$traps" ] || exit 8 Modified: head/bin/sh/trap.c ============================================================================== --- head/bin/sh/trap.c Sat Apr 18 23:08:52 2015 (r281717) +++ head/bin/sh/trap.c Sat Apr 18 23:49:57 2015 (r281718) @@ -183,7 +183,7 @@ trapcmd(int argc __unused, char **argv) return 0; } action = NULL; - if (*argv && sigstring_to_signum(*argv) == -1) { + if (*argv && !is_number(*argv)) { if (strcmp(*argv, "-") == 0) argv++; else {