Page MenuHomeFreeBSD

Fix the trap builtin to be POSIX-compliant for 'trap exit SIG' and 'trap n n n n'.
ClosedPublic

Authored by bdrewery on Apr 18 2015, 5:25 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 8 2024, 12:25 AM
Unknown Object (File)
Mar 7 2024, 10:47 PM
Unknown Object (File)
Jan 28 2024, 12:04 PM
Unknown Object (File)
Dec 20 2023, 1:49 AM
Unknown Object (File)
Sep 1 2023, 11:46 AM
Unknown Object (File)
Aug 21 2023, 6:15 PM
Unknown Object (File)
Jul 15 2023, 10:21 PM
Unknown Object (File)
Jun 26 2023, 11:20 PM
Subscribers

Details

Summary

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.

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.

  • Not for commit log --

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#trap states:

"If the first operand is an unsigned decimal integer, the shell shall treat
all operands as conditions, and shall reset each condition to the default
value. Otherwise, if there are operands, the first is treated as an action
and the remaining as conditions."
Test Plan

kyua test for all of bin/sh.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

bdrewery retitled this revision from to Fix the trap builtin to be POSIX-compliant for 'trap exit SIG' and 'trap n n n n'..
bdrewery updated this object.
bdrewery edited the test plan for this revision. (Show Details)
bdrewery added a reviewer: jilles.

Interestingly dash fails on the last 2 tests. Bash passes on all of them. We have an in-tree file (contrib/bmake/mkdeps.sh) that uses both 'trap 0' and 'trap exit 2 3'.

My test cases fail to detect the original bug. Fixing that.

Fix test case to catch main bug that was fixed.

jilles edited edge metadata.

Looks good to me.

bin/sh/tests/builtins/trap16.0
6 ↗(On Diff #4903)

This may be slightly stricter than required, but existing shells that provide correct output provide that exact string (zsh returns trap -- '' , mksh returns trap -- EXIT).

This revision is now accepted and ready to land.Apr 18 2015, 8:21 PM

By the way, a workaround for the script is:

trap ' exit' INT
bdrewery updated this revision to Diff 4911.

Closed by commit rS281718 (authored by @bdrewery).