[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "read" builtin: timeout vs. EOF
From: |
Eric Blake |
Subject: |
Re: "read" builtin: timeout vs. EOF |
Date: |
Mon, 19 Dec 2011 07:07:35 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111115 Thunderbird/8.0 |
On 12/18/2011 09:45 AM, Stephen Gildea wrote:
> The "read" built-in documentation says,
>
> Exit Status:
> The return code is zero, unless end-of-file is encountered, read times
> out,
> or an invalid file descriptor is supplied as the argument to -u.
>
> I would like to be able to distinguish the no-data conditions. In
> particular I want to know whether I got a timeout or an end-of-file,
> but as you can see, Bash is not documented to behave differently in
> these two cases.
>
> As it happens, in Bash 4.2, "read" exits with status 1 on EOF and
> SIGALRM on timeout. This is just what I want. Can I count on this
> behavior? If so, please commit to it with documentation.
http://austingroupbugs.net/view.php?id=367
POSIX made a change to require the following on read:
An error in setting any variable (such as if a var has previously been
marked
readonly) shall be considered an error of read processing, and shall result
in a return value greater than one.
At line 103977 [XCU read EXIT STATUS], change
>0 End-of-file was detected or an error occurred.
to
1 End-of-file was detected.
>1 An error occurred.
Getting a timeout or invalid file descriptor should definitely be
considered error cases that return > 1 (SIGALRM for timeout works well).
--
Eric Blake eblake@redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature