Austin Group Defect Tracker

Aardvark Mark IV


Viewing Issue Simple Details Jump to Notes ] Issue History ] Print ]
ID Category Severity Type Date Submitted Last Update
0001425 [1003.1(2016/18)/Issue7+TC2] Shell and Utilities Objection Error 2020-11-23 23:10 2021-03-25 14:27
Reporter kre View Status public  
Assigned To
Priority normal Resolution Accepted As Marked  
Status Applied  
Name Robert Elz
Organization
User Reference
Section XCU 2.14 / exit
Page Number 2399
Line Number 76764-5
Interp Status ---
Final Accepted Text Note: 0005266
Summary 0001425: exit in an EXIT trap is not clearly specified
Description the 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 Action Since 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.

Tags tc3-2008
Attached Files

- Relationships

-  Notes
(0005266)
rhansen (manager)
2021-03-11 17:07

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 => Note: 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


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker