The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: Chris Hanson <cmhanson@eschatologist.net>
To: arnold@skeeve.com
Cc: tuhs@tuhs.org
Subject: Re: [TUHS] Unix APIs: elegant or not?
Date: Sun, 4 Nov 2018 13:34:10 -0800	[thread overview]
Message-ID: <C84DDCBC-7699-4078-8E92-521589FADB2C@eschatologist.net> (raw)
In-Reply-To: <201811041228.wA4CSMIA017639@freefriends.org>

On Nov 4, 2018, at 4:28 AM, arnold@skeeve.com wrote:
> 
> Chris Hanson <cmhanson@eschatologist.net> wrote:
> 
>> If anyone ever asks me about the elegance of UNIX, there’s one word, or really term, that springs to mind: EINTR.
>> 
>> The fact that man pages on modern systems still describe calls as returning -1 with errno set to EINTR baffles me.
> 
> Can you explain this some more?  This sounds like a claim that UNIX
> isn't elegant.  But I'm not following whatever it is you're saying.

Every piece of code that wants to call, say, read(2) needs to handle not only real errors but also needs to special-case EINTR and retry the read. Thus you should virtually never use read(2), only ever something like this:

    ssize_t safe_read(int fd, void *buf, size_t buf_size)
    {
        ssize_t rc;
        do {
            rc = read(fd, buf, buf_size);
        } while ((rc == -1) && (errno == EINTR));
        return rc;
    }

And do this for every classic system call, since virtually no client code should ever have to care about EINTR. It was early an implementation expediency that became API and that everyone now has to just deal with because you can’t expect the system call interface you use to do this for you.

This is the sort of wart that should’ve been fixed by System V and/or BSD 4 at latest.

  — Chris



  reply	other threads:[~2018-11-04 22:07 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-31  4:38 Warren Toomey
2018-10-31 15:47 ` Paul Winalski
2018-10-31 17:22   ` Clem Cole
2018-10-31 19:33     ` Lawrence Stewart
2018-10-31 20:57   ` G. Branden Robinson
2018-10-31 21:31   ` Dave Horsfall
2018-11-01  7:42     ` Pierre DAVID
2018-11-01 10:20       ` Dave Horsfall
2018-11-01 12:57         ` Clem Cole
2018-11-01 14:19           ` ron minnich
2018-11-01 14:41             ` Clem Cole
2018-11-01 16:43               ` Warner Losh
2018-11-01 16:48                 ` ron minnich
2018-11-01 16:56                   ` Warner Losh
2018-11-02  5:24                   ` Bakul Shah
2018-11-04 10:53         ` Chris Hanson
2018-11-04 15:34           ` ron minnich
2018-11-04 17:06             ` Warner Losh
2018-11-04 20:00               ` ron minnich
2018-11-04 18:52           ` Bakul Shah
2018-11-04 10:49 ` Chris Hanson
2018-11-04 12:28   ` arnold
2018-11-04 21:34     ` Chris Hanson [this message]
2018-11-05 14:11       ` Donald ODona
2018-11-04 13:35   ` Warner Losh
2018-11-04 19:47   ` Dave Horsfall
2018-11-01 15:39 Noel Chiappa
2018-11-04 22:29 Theodore Y. Ts'o
2018-11-04 22:37 Noel Chiappa
2018-11-05  4:04 ` Dave Horsfall

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=C84DDCBC-7699-4078-8E92-521589FADB2C@eschatologist.net \
    --to=cmhanson@eschatologist.net \
    --cc=arnold@skeeve.com \
    --cc=tuhs@tuhs.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 NNTP newsgroup(s).