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 |
2024-06-11 09:07 |
|
Reporter |
geoffclare |
View Status |
public |
|
Assigned To |
|
Priority |
normal |
Resolution |
Accepted |
|
Status |
Closed |
|
|
|
|
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 |
|
|