Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15762

Re: Fwd: read -t 0 fails to detect input.

From Chet Ramey <chet.ramey@case.edu>
Newsgroups gnu.bash.bug
Subject Re: Fwd: read -t 0 fails to detect input.
Date 2019-12-20 10:24 -0500
Organization ITS, Case Western Reserve University
Message-ID <mailman.1188.1576855506.1979.bug-bash@gnu.org> (permalink)
References <CAFra36gNku2DTCyivz+caMGnTf7GvGJUTiWicUnBZatcckXGcQ@mail.gmail.com> <7e6fccb4-e5b5-eb2b-8b12-eeee9d638ae1@case.edu> <CAFra36iJqGfocqtVYqcdfkePJZ5xrWg8=pfKZXymD34Gaz02rA@mail.gmail.com> <CAFra36iUQqc-yUmZyu-3ty15jWiN=5o_XQ8pxLsZieEZP8=Lsw@mail.gmail.com> <809a1e02-12d2-e50d-92c8-22e0ba31e71e@case.edu>

Show all headers | View raw


On 12/19/19 3:07 PM, Bize Ma wrote:
> To: Chester Ramey <chet.ramey@case.edu>
> 
> On thu., dec. 19 of 2019 at 12:40, Chet Ramey (<chet.ramey@case.edu>) wrote:
> 
>> On 12/18/19 6:40 PM, Bize Ma wrote:
>>
> 
> 
>>>>> The exit status is 0 if input is available on the specified file
>>>   descriptor, non-zero otherwise.
>>
>> Bash-5.0 uses select/FIONREAD to determine whether or not there is input
>> available on the file descriptor. Those don't wait; they test whether or
>> not there is input on the specified file descriptor at the point they are
>> called.
>>
> 
> Thanks Chet.
> 
> Could you please comment about this assertions:

>From an eight-year-old message?

>  1.-   bash will either do a select() or an ioctl(FIONREAD), or neither of
> them, but not both, as it should for it to work. read -t0 is broken. Do not
> use it – mosvy.

It doesn't matter. You can use both and not change the inherent race
condition at all. The only difference in their behavior is what happens
at EOF (select returns success, ioctl(FIONREAD) returns failure). If you
want to see whether or not there is input on stdin, read stdin.

If you want to test whether a write-only file descriptor that you opened is
ready for reading, it's programmer error.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: Fwd: read -t 0 fails to detect input. Chet Ramey <chet.ramey@case.edu> - 2019-12-20 10:24 -0500

csiph-web