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
0001902 [1003.1(2024)/Issue8] Shell and Utilities Objection Enhancement Request 2025-01-23 11:53 2025-01-23 16:21
Reporter geoffclare View Status public  
Assigned To
Priority normal Resolution Accepted  
Status Resolved  
Name Geoff Clare
Organization The Open Group
User Reference
Section exec
Page Number 2538
Line Number 82764
Interp Status ---
Final Accepted Text See desired action
Summary 0001902: exec redirection and test -t
Description Currently it is not portable (by the standard; it works in practice) for an application to do something like:
exec 3> "$outfile"
test -t 3
This is because of the following text in the exec DESCRIPTION:
If any file descriptors with numbers greater than 2 are opened by those redirections, it is unspecified whether those file descriptors remain open when the shell invokes another utility.
which allows fd 3 to be closed when the shell invokes "test".

This text was included in POSIX.2-1992 because ksh88 would set the FD_CLOEXEC bit on fd's greater than 2 when opened by exec. However, since "test" was built into ksh88, this did not cause any problem with the above usage.

Making this usage portable by the standard requires two changes:

1. The text on the exec page should change so that fd's greater than 2 can only be closed when the shell invokes utilities that are not built into the shell. (Note the careful phrasing here: this is not the same as "invokes a non-built-in utility" because regular built-ins are not required to be actually built into the shell - see the XBD definition of "built-in utility".)

2. The "test" utility needs to be required to be built into the shell, as a minimum in shells where exec sets FD_CLOEXEC, but it would be simpler just to require it in all shells. As far as I'm aware, the shells where it was not actually built in are now all ancient relics.
Desired Action On page 2538 line 82764 section exec (DESCRIPTION), change:
when the shell invokes another utility
to:
when the shell invokes a utility that is not built into the shell

After page 2539 line 82829 section exec (RATIONALE), add a paragraph:
Versions of this standard earlier than Issue 8 TC1 allowed file descriptors greater than 2 that were opened by exec to be closed when the shell invokes any other utility. In practice this has always been implemented by setting the FD_CLOEXEC flag on these descriptors, meaning they are not closed when invoking a utility that is built into the shell. The wording has been updated to match this implementation practice. In particular, this makes the use of test -t file_descriptor portable for such file descriptors when the built-in version of test is used.

On page 3431 line 116983 section test (DESCRIPTION), change:
The test and [ utilities may be implemented as a single linked utility which examines ...
to:
The test and [ utilities shall be implemented both as regular built-in utilities that are built into the shell and as utilities that can be executed via the exec family of functions defined in the System Interfaces volume of POSIX.1-2024. The latter may be implemented as a single linked utility which examines ...

After page 3436 line 117214 section test (APPLICATION USAGE), add a paragraph:
The use of the -t file_descriptor primary with file_descriptor values greater than 2 that were opened by exec is only portable when using the shell built-in version of these utilities. When the version that is not built into the shell is invoked, file descriptors greater than 2 may be closed (see [xref to exec]).

After page 3438 line 117285 section test (RATIONALE), add a paragraph:
Unlike most regular built-in utilities, test and [ are required to be implemented by being built into the shell. This is because if the shell sets the FD_CLOEXEC flag on file descriptors greater than 2 that are opened by exec, they need to remain open when the shell invokes test or [ in order for the -t file_descriptor primary to be able to test them.

Tags tc1-2024
Attached Files

- Relationships

There are no notes attached to this issue.

- Issue History
Date Modified Username Field Change
2025-01-23 11:53 geoffclare New Issue
2025-01-23 11:53 geoffclare Name => Geoff Clare
2025-01-23 11:53 geoffclare Organization => The Open Group
2025-01-23 11:53 geoffclare Section => exec
2025-01-23 11:53 geoffclare Page Number => 2538
2025-01-23 11:53 geoffclare Line Number => 82764
2025-01-23 11:53 geoffclare Interp Status => ---
2025-01-23 16:21 nick Final Accepted Text => See desired action
2025-01-23 16:21 nick Status New => Resolved
2025-01-23 16:21 nick Resolution Open => Accepted
2025-01-23 16:23 nick Tag Attached: tc1-2024


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