public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Janne Blomqvist <blomqvist.janne@gmail.com>
To: Fritz Reese <fritzoreese@gmail.com>
Cc: FX <fxcoudert@gmail.com>, Fortran List <fortran@gcc.gnu.org>,
		GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH, libgfortran] PR 67585 Handle EINTR
Date: Fri, 07 Oct 2016 16:09:00 -0000	[thread overview]
Message-ID: <CAO9iq9GBV+JSTg-j589iHwtUGx9nqka2J_+iop-pz-u28wwMkA@mail.gmail.com> (raw)
In-Reply-To: <CAE4aFA=TAzyrPB5rCHEMzkLeSEm1CAPnn10N=yqo_Bd-Kd-vpQ@mail.gmail.com>

On Fri, Oct 7, 2016 at 5:50 PM, Fritz Reese <fritzoreese@gmail.com> wrote:
> On Fri, Oct 7, 2016 at 8:59 AM, Janne Blomqvist
> <blomqvist.janne@gmail.com> wrote:
>> On Fri, Oct 7, 2016 at 2:41 PM, FX <fxcoudert@gmail.com> wrote:
>>>> Many POSIX systems have the bad habit of not restarting interrupted
>>>> syscalls. On these systems it's up to the user to check for an error
>>>> with errno == EINTR and restart manually. This patch does this for
>>>> libgfortran, so that GFortran users don't have to do it.
>>>
>>> I have not much experience with EINTR, but is it garanteed that those EINTR loops will never cycle forever?
>>
>> Hmm, no I don't think so, but I don't think it'll be a problem. So on
>> systems where syscalls are not restarted automatically, EINTR happens
>> when the process receives a signal while blocked in a system call [1].
>> So I suppose in theory you could have a situation where something
>> continuously fires signals at the process, and the result is some kind
>> of race between the process restarting the syscall which then never
>> manages to complete before being interrupted again. But I think this
>> goes into the "Doctor, this hurts! Then don't do that" territory.
>>
>> There's some more info in https://www.python.org/dev/peps/pep-0475/
>> (Python nowadays does the same as this patch).
>
>
> Just one concern (slightly different from the race you described) -
> what if a user wants/expects a system call to be interrupted? With the
> patch we would always restart the system call even if the user was
> expecting it would be interrupted. For small calls like lseek this may
> not be a big deal but if read on a pipe/socket/terminal is restarted
> after being interrupted (e.g. with CTRL-C) we may loop forever even if
> the user program was written to expect and handle EINTR after the read
> call, e.g. to terminate nicely with "non async-safe" calls like printf
> that couldn't be done in the handler.

Concievable yes, but IMHO unlikely. And since many systems
automatically restart syscalls, a program like the above perhaps isn't
that robust to begin with?

> This is discussed as "use case 2" in the PEP you referenced. Python
> handles this case by explicitly calling user defined signal handlers
> directly after EINTR and checking the return value from the handler,
> only trying again if the handler reports success. Not so simple I
> think with libgfortran.

With GFortran, a problem is that due to the buffering, handling of
record markers etc. there is no 1:1 mapping between Fortran READ/WRITE
statements and read(2)/write(2) syscalls. So even if we let EINTR
propagate all the way back up to the Fortran caller (as happens now,
except for write()), it actually has no way of knowing what should be
restarted.



-- 
Janne Blomqvist

  reply	other threads:[~2016-10-07 16:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-07 12:26 Janne Blomqvist
2016-10-07 12:41 ` FX
2016-10-07 12:59   ` Janne Blomqvist
2016-10-07 14:50     ` Fritz Reese
2016-10-07 16:09       ` Janne Blomqvist [this message]
2016-10-07 16:42         ` Jack Howarth
2016-10-07 19:55           ` Mike Stump
2016-10-07 19:46       ` Mike Stump
2016-10-07 19:26     ` Mike Stump
2016-10-07 19:18   ` Mike Stump
2016-10-09 13:59 ` [PATCH] " Janne Blomqvist

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAO9iq9GBV+JSTg-j589iHwtUGx9nqka2J_+iop-pz-u28wwMkA@mail.gmail.com \
    --to=blomqvist.janne@gmail.com \
    --cc=fortran@gcc.gnu.org \
    --cc=fritzoreese@gmail.com \
    --cc=fxcoudert@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).