On Wed, Dec 8, 2010 at 11:34 AM, Benjamin R. Haskell <[email protected]> wrote:
> On Wed, 8 Dec 2010, Bram Moolenaar wrote:
>
>>
>> Xavier de Gaye wrote:
>>
>>> On Mon, Dec 6, 2010 at 7:54 PM, Benjamin R. Haskell wrote:
>>>>
>>>> If Vim receives a SIGWINCH (_sig_nal that the _win_dow _ch_anged size)
>>>> while editing stdin, a program piping input to Vim gets killed prematurely.
>>>>  Is there an easy way to avoid this?
>>>>
>>>
>>>
>>> Actually, it is Vim that terminates prematurely.
>>> This is a bug in Vim: when vim receives the SIGWINCH signal, the
>>> vim_read() call that is reading stdin, returns -1 and vim handles that as an
>>> error in readfile().
>>>
>>> [...]
>>
>> This looks like a hack.  I think the proper solution is to have vim_read()
>> check for EINTR and retry.
>>
>> I'm a bit confused about what happens when read() is interrupted before
>> reading anything, does it return zero or -1?  Perhaps this depends on the
>> system.
>
> """ from `man 2 read` (on OpenSUSE)
> 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.
> """
>
> To me that implies, but doesn't explicitly state, that it *doesn't* return
> the number of bytes read [which is 0] if it *hasn't* read any bytes.
>
> It also seems like it would conflict with being able to detect EOF.
>
> Thus, I think it's safe to assume that an interrupted read() with no
> returned data returns -1.

SUS[0] states it a bit more explicitly:

  If a read() is interrupted by a signal before it reads any data, it
  shall return -1 with errno set to [EINTR].

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

[0]: http://www.opengroup.org/onlinepubs/009695399/functions/read.html
-- 
James
GPG Key: 1024D/61326D40 2003-09-02 James Vega <[email protected]>

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui