Bug 193111 - POSIX.1-2001 and later prohibit read(2) from returning -1 EINTR when interrupted after partial read
Summary: POSIX.1-2001 and later prohibit read(2) from returning -1 EINTR when interrup...
Status: RESOLVED CODE_FIX
Alias: None
Product: Documentation
Classification: Unclassified
Component: man-pages (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: documentation_man-pages@kernel-bugs.osdl.org
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-01-22 03:43 UTC by Steven Luo
Modified: 2017-01-23 03:02 UTC (History)
1 user (show)

See Also:
Kernel Version:
Subsystem:
Regression: No
Bisected commit-id:


Attachments

Description Steven Luo 2017-01-22 03:43:01 UTC
Every version of the man-pages read(2) page in the git repository appears to have the following language:

"POSIX allows a read() that is interrupted after reading some data to return -1 (with errno set to EINTR) or to return the number of bytes already read."

But POSIX.1-2001 [1] and later versions of the standard [2] explicitly prohibit returning -1 EINTR in this case:

"If a read() is interrupted by a signal after it has successfully read some data, it shall return the number of bytes read."

The rationale explains:

"Previous versions of IEEE Std 1003.1-2001 allowed two very different behaviors with regard to the handling of interrupts. In order to minimize the resulting confusion, it was decided that IEEE Std 1003.1-2001 should support only one of these behaviors. Historical practice on AT&T-derived systems was to have read() and write() return -1 and set errno to [EINTR] when interrupted after some, but not all, of the data requested had been transferred. However, the U.S. Department of Commerce FIPS 151-1 and FIPS 151-2 require the historical BSD behavior, in which read() and write() return the number of bytes actually transferred before the interrupt. If -1 is returned when any data is transferred, it is difficult to recover from the error on a seekable device and impossible on a non-seekable device. Most new implementations support this behavior. The behavior required by IEEE Std 1003.1-2001 is to return the number of bytes transferred."

Either this text in the manpage should be deleted, or it should be updated to reflect that the standard has changed (and perhaps to note which historical implementations return -1 EINTR when interrupted after a partial read).

[1] http://pubs.opengroup.org/onlinepubs/009695399/functions/read.html
[2] http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html
Comment 1 Michael Kerrisk 2017-01-23 03:02:04 UTC
Actually, the change in the standards seems to be even older. Looking at the text of SUSv1 (1995), the change was already made there. So, that text has been wrong almost as long as Linux has been around. Therefore, I've simply deleted that text.

Note You need to log in before you can comment on or make changes to this bug.