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
0001490 [1003.1(2016/18)/Issue7+TC2] System Interfaces Comment Omission 2021-07-13 14:41 2021-12-13 15:18
Reporter geoffclare View Status public  
Assigned To
Priority normal Resolution Accepted  
Status Applied  
Name Geoff Clare
Organization The Open Group
User Reference
Section exit()
Page Number 796
Line Number 27080
Interp Status ---
Final Accepted Text
Summary 0001490: warn app writers about flush errors not being detectable by exit()
Description In light of the recent discovery that many implementations of standard utilities have an ancient bug whereby they leave buffer flushing of stdout to be done by exit() when exiting with a status that indicates successful completion, and thus do not handle write errors properly, it would be a good idea to give some advice about this in the exit() APPLICATION USAGE section to try and help application writers avoid falling into the same trap.
Desired Action Change APPLICATION USAGE from "None" to:
When a stream that has unwritten buffered data is flushed by exit() there is no way for the calling process to discover whether or not exit() successfully wrote the data to the underlying file descriptor. Therefore, it is strongly recommended that applications always ensure there is no unwritten buffered data in any stream when calling exit(), or returning from the initial call to main(), with a status value that indicates no errors occurred.

For example, the following code demonstrates one way to ensure that stdout has already been successfully flushed before calling exit() with status 0. If the flush fails, the file descriptor underlying stdout is closed so that exit() will not try to repeat the failed write operation. If the flush succeeds, a final check with ferror() is performed to ensure that there were no write errors during earlier flush operations (that were not handled at the time).
int status = 0;
if (fflush(stdout) != 0) {
    perror("appname: standard output");
    close(fileno(stdout));
    status = 1;
}
else if (ferror(stdout)) {
    fputs("appname: write error on standard output\n", stderr);
    status = 1;
}
exit(status);

Change EXAMPLES from "None" to:
See APPLICATION USAGE.

(This is before the APPLICATION USAGE section, so putting the example
code here would mean it is before the explanation.)
Tags tc3-2008
Attached Files

- Relationships
related to 0001629Applied Shell vs. read(2) errors on the script 

There are no notes attached to this issue.

- Issue History
Date Modified Username Field Change
2021-07-13 14:41 geoffclare New Issue
2021-07-13 14:41 geoffclare Name => Geoff Clare
2021-07-13 14:41 geoffclare Organization => The Open Group
2021-07-13 14:41 geoffclare Section => exit()
2021-07-13 14:41 geoffclare Page Number => 796
2021-07-13 14:41 geoffclare Line Number => 27080
2021-07-13 14:41 geoffclare Interp Status => ---
2021-11-18 17:19 Don Cragun Status New => Resolved
2021-11-18 17:19 Don Cragun Resolution Open => Accepted
2021-11-18 17:20 Don Cragun Tag Attached: tc3-2008
2021-12-13 15:18 geoffclare Status Resolved => Applied
2023-03-20 15:48 eblake Relationship added related to 0001629


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