All of lore.kernel.org
 help / color / mirror / Atom feed
* Q.: Why does tty_ioctl.c: set_termios return EINTR instead of ERESTARTSYS?
       [not found] ` <CAB4+JYJYVFouMYZMX4bGVA+vPm1rD3KY3GvwVjKBZS7bwf6-zQ@mail.gmail.com>
@ 2011-10-14 16:52   ` Godmar Back
  2011-10-15  8:55     ` Jiri Slaby
  0 siblings, 1 reply; 4+ messages in thread
From: Godmar Back @ 2011-10-14 16:52 UTC (permalink / raw)
  To: linux-kernel

A student in my OS class noticed during their shell assignment that
tcsetattr() is being interrupted with EINTR even though they had set
SA_RESTART.

Upon taking a closer look, I noticed that
drivers/char/tty_ioctl.c:set_termios(), which lies on the code path
for the POSIX tcsetattr() function, returns -EINTR when a signal is
pending. Consequently, the SA_RESTART flag is not honored and user
code must check for and handle EINTR.

I don't immediately see what would prevent this system call from being
restartable.

Is there a particular reason why it cannot be made restartable?

Thank your for any insight.

 - Godmar

--
please cc: me on any replies.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Q.: Why does tty_ioctl.c: set_termios return EINTR instead of ERESTARTSYS?
  2011-10-14 16:52   ` Q.: Why does tty_ioctl.c: set_termios return EINTR instead of ERESTARTSYS? Godmar Back
@ 2011-10-15  8:55     ` Jiri Slaby
  2011-10-15  9:25       ` Alan Cox
  2011-10-15 13:12       ` Godmar Back
  0 siblings, 2 replies; 4+ messages in thread
From: Jiri Slaby @ 2011-10-15  8:55 UTC (permalink / raw)
  To: Godmar Back; +Cc: linux-kernel, Alan Cox, Greg KH

On 10/14/2011 06:52 PM, Godmar Back wrote:
> A student in my OS class noticed during their shell assignment that
> tcsetattr() is being interrupted with EINTR even though they had set
> SA_RESTART.
> 
> Upon taking a closer look, I noticed that
> drivers/char/tty_ioctl.c:set_termios(), which lies on the code path
> for the POSIX tcsetattr() function, returns -EINTR when a signal is
> pending. Consequently, the SA_RESTART flag is not honored and user
> code must check for and handle EINTR.
> 
> I don't immediately see what would prevent this system call from being
> restartable.
> 
> Is there a particular reason why it cannot be made restartable?

EINTR is used when there is no way to rollback already performed
actions. In this case, a flush could be performed. (This holds only for
TCSETSF, TCSETSF2 and similar.) So I think this is the reason we cannot
return ERESTARTSYS.

However I CCed tty fellows, they may have a different opinion.

regards,
-- 
js
suse labs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Q.: Why does tty_ioctl.c: set_termios return EINTR instead of ERESTARTSYS?
  2011-10-15  8:55     ` Jiri Slaby
@ 2011-10-15  9:25       ` Alan Cox
  2011-10-15 13:12       ` Godmar Back
  1 sibling, 0 replies; 4+ messages in thread
From: Alan Cox @ 2011-10-15  9:25 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: Godmar Back, linux-kernel, Greg KH

 Is there a particular reason why it cannot be made restartable?
> 
> EINTR is used when there is no way to rollback already performed
> actions. In this case, a flush could be performed. (This holds only for
> TCSETSF, TCSETSF2 and similar.) So I think this is the reason we cannot
> return ERESTARTSYS.
> 
> However I CCed tty fellows, they may have a different opinion.

I don't actually know. I think Linus or Ted T'so were still doing the tty
code that long back. Ted also did some compliance testing on it way back
when (1995 or so ?)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Q.: Why does tty_ioctl.c: set_termios return EINTR instead of ERESTARTSYS?
  2011-10-15  8:55     ` Jiri Slaby
  2011-10-15  9:25       ` Alan Cox
@ 2011-10-15 13:12       ` Godmar Back
  1 sibling, 0 replies; 4+ messages in thread
From: Godmar Back @ 2011-10-15 13:12 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: linux-kernel, Alan Cox, Greg KH

On Sat, Oct 15, 2011 at 4:55 AM, Jiri Slaby <jslaby@suse.cz> wrote:
>
> On 10/14/2011 06:52 PM, Godmar Back wrote:
> > A student in my OS class noticed during their shell assignment that
> > tcsetattr() is being interrupted with EINTR even though they had set
> > SA_RESTART.
> >
> > Upon taking a closer look, I noticed that
> > drivers/char/tty_ioctl.c:set_termios(), which lies on the code path
> > for the POSIX tcsetattr() function, returns -EINTR when a signal is
> > pending. Consequently, the SA_RESTART flag is not honored and user
> > code must check for and handle EINTR.
> >
> > I don't immediately see what would prevent this system call from being
> > restartable.
> >
> > Is there a particular reason why it cannot be made restartable?
>
> EINTR is used when there is no way to rollback already performed
> actions. In this case, a flush could be performed. (This holds only for
> TCSETSF, TCSETSF2 and similar.) So I think this is the reason we cannot
> return ERESTARTSYS.

TCSETSF flushes the terminal buffer (discarding input).

TCSETSW (which I believe is what the call I'm worried about uses:
tcsetattr(, TCSADRAIN,)) calls set_termios with TERMIOS_WAIT, which
results in a call to tty_wait_until_sent() that drains the terminal's
output buffer. See
http://lxr.linux.no/linux+v3.0.4/drivers/tty/tty_ioctl.c#L616

However, why would that necessitate EINTR?  Both draining the output
buffer and flushing the input buffer are, presumably, idempotent
operations (?)

Furthermore, applications will most likely blindly retry on EINTR
anyway. For example, that's what user mode linux does/suggests (see
CATCH_EINTR in http://lxr.linux.no/linux+v3.0.4/arch/um/include/shared/os.h#L15
and http://lxr.linux.no/linux+v3.0.4/arch/um/drivers/chan_user.c#L108
) which is included with the Linux source tree.

 - Godmar

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-10-15 13:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CAB4+JYLiF4wr+U5s_m15baC=Ktf8NnAYFKfcyhM3AxG9PZ4YPA@mail.gmail.com>
     [not found] ` <CAB4+JYJYVFouMYZMX4bGVA+vPm1rD3KY3GvwVjKBZS7bwf6-zQ@mail.gmail.com>
2011-10-14 16:52   ` Q.: Why does tty_ioctl.c: set_termios return EINTR instead of ERESTARTSYS? Godmar Back
2011-10-15  8:55     ` Jiri Slaby
2011-10-15  9:25       ` Alan Cox
2011-10-15 13:12       ` Godmar Back

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.