View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0000480 | 1003.1(2008)/Issue 7 | System Interfaces | public | 2011-07-28 15:08 | 2019-06-10 08:55 |
Reporter | eblake | Assigned To | ajosey | ||
Priority | normal | Severity | Objection | Type | Error |
Status | Closed | Resolution | Accepted As Marked | ||
Name | Eric Blake | ||||
Organization | Red Hat | ||||
User Reference | ebb.handles | ||||
Section | 2.5.1 Interaction of File Descriptors and Standard I/O Streams | ||||
Page Number | 491 | ||||
Line Number | 16844 | ||||
Interp Status | Approved | ||||
Final Accepted Text | See 0000480:0000894 | ||||
Summary | 0000480: freopen, fclose effect on multiple file handles | ||||
Description | The standard states that freopen always closes a handle and creates a stream that is open to a new file description when describing the interaction of freopen with handles, but later states that freopen with a NULL filename argument may (but not must) reuse the existing stream and underlying file description [XSH freopen lines 30885-89]. Here, I argue that the freopen description is intended, and that the multiple-handle text should be fixed to be made consistent. Also, the following example of two handles should be well-defined, but is currently handled differently in Solaris than it is in glibc 2.14; I argue that the glibc behavior is a bug in trying to implement 0000087 (that is, in trying to fix fclose() vs. ungetc() semantics in glibc bug http://sourceware.org/bugzilla/show_bug.cgi?id=12724, glibc inadvertently also broke fclose() to blindly reposition the file description even if the stream was not otherwise used): const char buf[] = "hello world"; int fd; int fd2; FILE *f; /* Prepare a seekable file. */ fd = open (NAME, O_RDWR | O_CREAT | O_TRUNC, 0600); assert (0 <= fd); assert (write (fd, buf, sizeof buf) == sizeof buf); assert (lseek (fd, 1, SEEK_SET) == 1); /* Create an output stream visiting the file; when it is closed, all other file descriptors visiting the file must see the new file position. */ fd2 = dup (fd); assert (0 <= fd2); f = fdopen (fd2, "w"); // POSIX requires that f be at position 1 assert (f); assert(lseek(fd, 4, SEEK_SET) == 4); // fd is now the active handle assert (fclose (f) == 0); // The f/fd2 handle was never repositioned or made active assert (lseek (fd, 0, SEEK_CUR) == 4); // so fd should still be at 4 Solaris passed this test, but glibc 2.14 ended up repositioning the file description to offset 1, which was then observable in fd and causes the assertion to fail. I think the intent of the standard is clear, but recent wording changes to fclose() mean that we can make this more explicit. | ||||
Desired Action | At line 16844 [XSH 2.5.1], change: A handle which is a stream is considered to be closed when either an fclose( ) or freopen( ) is executed on it (the result of freopen( ) is a new stream, which cannot be a handle on the same open file description as its previous value), to: A handle which is a stream is considered to be closed when either an fclose( ), or freopen( ) with non-null filename, is executed on it (for freopen( ) with a null filename, it is implementation-defined whether a new handle is created or the existing one reused), At line 16880, add a bullet for the second handle: • If fclose( ) is the first (and only) action on the second handle, then the offset of the file description shall not be changed from what it was via the first handle. | ||||
Tags | tc2-2008 |
|
Interpretation response ------------------------ The standard is unclear on this issue, and no conformance distinction can be made between alternative implementations based on this. This is being referred to the sponsor. Rationale: ------------- Standard is contradictory on whether freopen() can reuse a file description when passed a null filename. Notes to the Editor (not part of this interpretation): ------------------------------------------------------- Make the changes in the suggested action except do not make the changes suggested at line 16880. |
|
Interpretation proposed 10 August 2011 for final 30 day review |
|
Interpretation approved 12 Sept 2011 |
Date Modified | Username | Field | Change |
---|---|---|---|
2011-07-28 15:08 | eblake | New Issue | |
2011-07-28 15:08 | eblake | Status | New => Under Review |
2011-07-28 15:08 | eblake | Assigned To | => ajosey |
2011-07-28 15:08 | eblake | Name | => Eric Blake |
2011-07-28 15:08 | eblake | Organization | => Red Hat |
2011-07-28 15:08 | eblake | User Reference | => ebb.handles |
2011-07-28 15:08 | eblake | Section | => 2.5.1 Interaction of File Descriptors and Standard I/O Streams |
2011-07-28 15:08 | eblake | Page Number | => 491 |
2011-07-28 15:08 | eblake | Line Number | => 16844 |
2011-07-28 15:08 | eblake | Interp Status | => --- |
2011-07-28 16:22 | jim_pugsley | Interp Status | --- => Pending |
2011-07-28 16:22 | jim_pugsley | Status | Under Review => Interpretation Required |
2011-07-28 16:22 | jim_pugsley | Resolution | Open => Accepted As Marked |
2011-07-28 16:27 | jim_pugsley | Note Added: 0000894 | |
2011-07-28 16:27 | jim_pugsley | Tag Attached: tc2-2008 | |
2011-07-28 16:29 | jim_pugsley | Final Accepted Text | => See 0000480:0000894 |
2011-07-28 16:31 | eblake | Relationship added | related to 0000087 |
2011-08-10 15:19 | ajosey | Interp Status | Pending => Proposed |
2011-08-10 15:19 | ajosey | Note Added: 0000927 | |
2011-09-12 15:21 | ajosey | Interp Status | Proposed => Approved |
2011-09-12 15:21 | ajosey | Note Added: 0000959 | |
2013-02-21 18:04 | eblake | Relationship added | related to 0000662 |
2019-06-10 08:55 | agadmin | Status | Interpretation Required => Closed |