aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/unix/sysv/linux/lxstat64.c
diff options
context:
space:
mode:
authorJoseph Myers <josmyers@redhat.com>2025-01-28 20:22:56 +0000
committerJoseph Myers <josmyers@redhat.com>2025-01-28 20:22:56 +0000
commitbe6818be31e756398e45f70e2819d78be0961223 (patch)
treed160a380a2fa37de6e419bc2ce2bf249c833ee21 /sysdeps/unix/sysv/linux/lxstat64.c
parent377e9733b50ce41e496c467ddcc112f73c88f3bd (diff)
downloadglibc-master.zip
glibc-master.tar.gz
glibc-master.tar.bz2
Make fclose seek input file to right offset (bug 12724)HEADmaster
As discussed in bug 12724 and required by POSIX, before an input file (based on an underlying seekable file descriptor) is closed, fclose is sometimes required to seek that file descriptor to the correct offset, so that any other file descriptors sharing the underlying open file description are left at that offset (as a motivating example, a script could call a sequence of commands each of which processes some data from (seekable) stdin using stdio; fclose needs to do this so that each successive command can read exactly the data not handled by previous commands), but glibc fails to do this. The precise POSIX wording has changed a few times; in the 2024 edition it's "If the file is not already at EOF, and the file is one capable of seeking, the file offset of the underlying open file description shall be set to the file position of the stream if the stream is the active handle to the underlying file description.". Add appropriate logic to _IO_new_file_close_it to handle this case. I haven't made any attempt to test or change things in this area for the "old" functions. Note that there was a previous attempt to fix bug 12724, reverted in commit eb6cbd249f4465b01f428057bf6ab61f5f0c07e3. The fix version here addresses the original test in that bug report without breaking the one given in a subsequent comment in that bug report (which works with glibc before the patch, but maybe was broken by the original fix that was reverted). The logic here tries to take care not to seek the file, even to its newly computed current offset, if at EOF / possibly not the active handle; even seeking to the current offset would be problematic because of a potential race (fclose computes the current offset, another thread or process with the active handle does its own seek, fclose does a seek (not permitted by POSIX in this case) that loses the effect of the seek on the active handle in another thread or process). There are tests included for various cases of being or not being the active handle, though there aren't tests for the potential race condition. Tested for x86_64.
Diffstat (limited to 'sysdeps/unix/sysv/linux/lxstat64.c')
0 files changed, 0 insertions, 0 deletions