coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] tee: recover from EAGAIN returned from fwrite()


From: Pádraig Brady
Subject: Re: [PATCH] tee: recover from EAGAIN returned from fwrite()
Date: Mon, 10 Sep 2018 21:49:09 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

On 10/09/18 09:38, Kamil Dudka wrote:
> On Friday, September 7, 2018 5:21:04 AM CEST Pádraig Brady wrote:
>> On 06/09/18 07:28, Kamil Dudka wrote:
>>> tee expects the output descriptors to operate in blocking mode but this
>>> assumption might be invalidated by other programs connected to the same
>>> terminal, as in the following example:
>>>
>>> $ telnet ... | tee log_file
>>>
>>> telnet calls ioctl(stdin, FIONBIO, [1]), which causes the O_NONBLOCK
>>> flag to be set on tee's output, which is connected to the same terminal.
>>>
>>> This patch has zero impact unless EAGAIN returns from fwrite().  In that
>>> case we try to reset the O_NONBLOCK flag on the output file descriptor
>>> and retry the call to fwrite().
>>
>> Not sure about this.
> 
> I was actually surprised that I did not find similar reports in the archive.
> 
>> Would that not be changing the tty to blocking, which is not what telnet
>> wants?
> 
> It probably does not matter in this specific case.  At least I was not able
> to observe any negative impact on the user session.  Everything seemed to
> work as if the output was not redirected.
> 
> As it is now, the user ends up with unexpectedly frozen output while input 
> still consumes anything that the desperate user types while trying to escape 
> the supposedly frozen telnet session.
> 
>> Also this would be a general issue. Why treat tee specially here?
> 
> Yes, this may happen with any filter-like utility that does not handle
> EAGAIN while writing its output.  Still I believe that recording a session
> using 'tee' is the most common use case and we have a very specific report 
> about it in Red Hat Bugzilla.
> 
>> Also would `cat | telnet ... | tee blah` be a workaround?
> 
> The above command does not really work because telnet is unable to set all 
> the 
> other needed properties on the terminal.  So it let me write my password on 
> the screen (because 'echo' was not disabled), arrow keys in my shell session 
> did not work, etc.

Right. However if telnet wants low level control of the terminal
and tee is unsetting fundamental IO behaviors of the tty like this,
then it wouldn't be general for all uses of telnet (like connecting
to a non line oriented remote session for example).
I.E. this isn't a general solution for all coreutils, or even for tee.

Options:

If one wants simple line oriented connection use netcat or equivalent.

Use script(1) which is more suited to recording terminal sessions.

Adjust telnet to not use FIONBIO when in line mode.

Avoid the tee apparent hang by using the --output-error=exit option.

cheers,
Pádraig



reply via email to

[Prev in Thread] Current Thread [Next in Thread]