mailing list of musl libc
 help / color / mirror / code / Atom feed
From: dannym@scratchpost.org
To: musl@lists.openwall.com
Subject: [RFC] EINTR and PC loser-ing library design
Date: Mon, 08 Dec 2014 15:04:57 +0100	[thread overview]
Message-ID: <esm61dmteye.wl-dannym@scratchpost.org> (raw)
In-Reply-To: <esmoarexomn.wl-danny.milo+a@gmail.com>

Hello,

I just had another hunt for bugs through libraries for EINTR-related woes.
I thought before I patch them, I'd make a proposal here.

EINTR is an ancient wart and like anyone else I have learned to live with it. 
But over the years it has never stopped bothering me. 
And this series of EINTR bugs made me lose confidence that the current way is sustainable.

EINTR serves two purposes:
1) makes the kernel easier by it not having to remember kernel-internal state of a running syscall when a signal arrives.
2) allows the user to see immediately when signals arrive - without having to do unsafe things in the signal handler.

Unfortunately, many routines retry on EINTR without thinking about 2).
Many non-libc routines don't even retry, breaking 1).
So 2) is unusable in practise, even though it's the only sane justification for EINTR to be there in the first place.

What I propose is the following:
- add an intr_handler callback (pointer) to libc, setable by the user, defaulting to one just returning (-1).
- adapt the syscall() interface (~50 system call wrappers of system calls that can return EINTR) to:
    on EINTR, call the callback, and retry the interruptible call only if the callback returned 0.
- adapt TEMP_FAILURE_RETRY(x) to do that as well, for forward compatibility.

The callback is supposed to be provided by the user and supposed to check some flags it set in the signal handler.
Once the callback returns (-1), it shall keep returning (-1) until something is reset by the user manually.

That way, both 1) and 2) work.

Backwards compatibility is ensured since the default callback will cause the syscall wrapper to do the same it always did.
But new programs could now not worry about EINTR except if they wanted to.

I put (way) more detail on <http://www.scratchpost.org/software/%3Carticle%3E/EINTR/>.

What do you think? Do we even want to change this to do the right thing?

If yes, I'd we willing to do the work needed.

If no, can we add just the callback pointer so we have a common interface for everyone else to call?

Thanks,
   Danny


       reply	other threads:[~2014-12-08 14:04 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <esmoarexomn.wl-danny.milo+a@gmail.com>
2014-12-08 14:04 ` dannym [this message]
2014-12-08 14:10   ` Rich Felker
2014-12-08 14:29     ` Laurent Bercot
2014-12-08 14:32       ` Rich Felker
2014-12-08 14:45         ` Laurent Bercot
2014-12-08 15:00           ` Rich Felker
2014-12-08 15:09             ` Rich Felker
2014-12-08 15:18           ` dannym
2014-12-08 15:28             ` Rich Felker
2014-12-08 15:49               ` Laurent Bercot
2014-12-08 16:00                 ` Rich Felker

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=esm61dmteye.wl-dannym@scratchpost.org \
    --to=dannym@scratchpost.org \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).