View Issue Details

IDProjectCategoryView StatusLast Update
00014251003.1(2016/18)/Issue7+TC2Shell and Utilitiespublic2024-06-11 09:08
Reporterkre Assigned To 
PrioritynormalSeverityObjectionTypeError
Status ClosedResolutionAccepted As Marked 
NameRobert Elz
Organization
User Reference
SectionXCU 2.14 / exit
Page Number2399
Line Number76764-5
Interp Status---
Final Accepted Text0001425:0005266
Summary0001425: exit in an EXIT trap is not clearly specified
Descriptionthe page for the special builtin command "exit" says

    A trap on EXIT shall be executed before the shell terminates,
    except when the exit utility is invoked in that trap itself,
    in which case the shell shall exit immediately.

The issue is what "that trap itself" means.

Consider

   $SHELL -c 'trap "trap \"echo bar\" EXIT; echo foo; exit" EXIT'

When the exit command in the outer exit trap is executed, the EXIT
trap has been changed to be something different, that is, the
shell is not executing the (current) EXIT trap when that exit command
is executed, so by a literal reading of the standard, the inner trap
should fire, and the shell should print

    foo
    bar

before exiting.

That is what the FreeBSD and NetBSD shells, and bosh, mksh, and zsh do.
bash yash ksh93 and dash print only "foo", that is they seem to ignore
the "that" in "that exit trap" and treat the text as if it said

    except when the exit utility is invoked in an exit trap

The page in XCU 2.14 for trap says nothing pertinent to this issue
(I am not suggesting that it should, just noting it).
Desired ActionSince the "reference" shells seem to do this the broken way, it is
unlikely that the standard will have words (or an example) added to
reinforce the current wording (I am guessing).

But since the other shells are doing exactly what the standard requires
of them, it would be incorrect, and unfair to specify this so as to
require the currently non-standard behaviour that the reference shells
implement.

Given that, the best that can be done, I believe, is to add a new
sentence, immediately after the one quoted above (which is unchanged
in 202x drafts) something like

    It is unspecified whether an EXIT trap defined while executing
    a previous EXIT trap will be executed before the shell terminates
    after completing execution (via an exit command, or reaching the
    end) of the earlier EXIT trao.

Tagstc3-2008

Activities

rhansen

2021-03-11 17:07

manager   bugnote:0005266

In c181 on page 2399 append another sentence to the paragraph at lines 76764-76765:
It is unspecified whether setting a new trap action on EXIT during execution of a trap action on EXIT will cause the new trap action to be executed before the shell terminates.

Issue History

Date Modified Username Field Change
2020-11-23 23:10 kre New Issue
2020-11-23 23:10 kre Name => Robert Elz
2020-11-23 23:10 kre Section => XCU 2.14 / exit
2020-11-23 23:10 kre Page Number => 2399
2020-11-23 23:10 kre Line Number => 76764-5
2021-03-11 17:07 rhansen Note Added: 0005266
2021-03-11 17:08 rhansen Interp Status => ---
2021-03-11 17:08 rhansen Final Accepted Text => 0001425:0005266
2021-03-11 17:08 rhansen Status New => Resolved
2021-03-11 17:08 rhansen Resolution Open => Accepted As Marked
2021-03-11 17:09 rhansen Tag Attached: tc3-2008
2021-03-25 14:27 geoffclare Status Resolved => Applied
2024-06-11 09:08 agadmin Status Applied => Closed