The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* Re: [TUHS] Unix APIs: elegant or not?
@ 2018-11-04 22:29 Theodore Y. Ts'o
  0 siblings, 0 replies; 30+ messages in thread
From: Theodore Y. Ts'o @ 2018-11-04 22:29 UTC (permalink / raw)
  To: The Eunuchs Hysterical Society

On Sun, 4 Nov 2018, Chris Hanson wrote:
> 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:
> ...
> 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.

But it *was* fixed in BSD, and it's in POSIX as the SA_RESTART flag to
sigaction (which gives you BSD signal semantics).

POSIX supports both the original V7 and BSD signal semantics, because
by then there were programs which expected system calls to be
interrupted by signals (and to be fair, there are times when that's
the more convenient way of handling an interrupt, as opposed to using
setjump/longjump to break out of a restartable system call).

					- Ted

P.S.  The original implementation of ERESTARTSYS / ERESTARTNOHAND /
ERESTARTNOINTR errno handling in Linux's system call return path was
my fault.  :-)

^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: [TUHS] Unix APIs: elegant or not?
@ 2018-11-04 22:37 Noel Chiappa
  2018-11-05  4:04 ` Dave Horsfall
  0 siblings, 1 reply; 30+ messages in thread
From: Noel Chiappa @ 2018-11-04 22:37 UTC (permalink / raw)
  To: tuhs; +Cc: jnc

    > From: Chris Hanson

    > you should virtually never use read(2), only ever something like this:
    > ...
    > And do this for every classic system call, since virtually no client
    > code should ever have to care about EINTR.

"Virtually". Maybe there are places that want to know if their read call was
interrupted; if you don't make this version available to them, how can they
tell? Leaving the user as much choice as possible is the only way to go, IMO;
why force them to do it the way _you_ think is best?

And it makes the OS simpler; any time you can move functionality out of the
OS, to the user, that's a Good Thing, IMO. There's nothing stopping people
from using the EINTR-hiding wrapper. (Does the Standard I/O library do this,
does anyone know?)

	Noel

PS: Only system calls that can block can return EINTR; there are quite a few
that don't, not sure what the counts are in modern Unix.

^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: [TUHS] Unix APIs: elegant or not?
@ 2018-11-01 15:39 Noel Chiappa
  0 siblings, 0 replies; 30+ messages in thread
From: Noel Chiappa @ 2018-11-01 15:39 UTC (permalink / raw)
  To: tuhs; +Cc: jnc

    > From: Clem Cole

    > (probably because Larry Allen implemented both UNIX Chaos and Aegis IIRC).

Maybe there are two Larry Allen's - the one who did networking stuff at
MIT-LCS was Larry W. Allen, and I'm pretty sure he didn't do Unix CHAOS code
(he was part of our group at LCS, and we only did TCP/IP stuff; someone over
in EE had a Unix with CHAOS code at the time, so it pre-dated his time with
us).

	Noel


^ permalink raw reply	[flat|nested] 30+ messages in thread
* [TUHS] Unix APIs: elegant or not?
@ 2018-10-31  4:38 Warren Toomey
  2018-10-31 15:47 ` Paul Winalski
  2018-11-04 10:49 ` Chris Hanson
  0 siblings, 2 replies; 30+ messages in thread
From: Warren Toomey @ 2018-10-31  4:38 UTC (permalink / raw)
  To: tuhs

I was just reading this book review:
http://www.pathsensitive.com/2018/10/book-review-philosophy-of-software.html
and came across these paragraphs:

    <book quote>
    The mechanism for file IO provided by the Unix operating system
    and its descendants, such as Linux, is a beautiful example of a
    deep interface. There are only five basic system calls for I/O,
    with simple signatures:

    int open(const char* path, int flags, mode_t permissions);
    ssize_t read(int fd, void* buffer, size_t count);
    ssize_t write(int fd, const void* buffer, size_t count);
    off_t lseek(int fd, off_t offset, int referencePosition);
    int close(int fd);
    </book quote>

  The POSIX file API is a great example, but not of a deep
  interface. Rather, it’s a great example of how code with a very
  complicated interface may look deceptively simple when reduced to C-style
  function signatures. It’s a stateful API with interesting orderings
  and interactions between calls. The flags and permissions parameters
  of open hide an enormous amount of complexity, with hidden requirements
  like “exactly one of these five bits should be specified.” open may
  return 20 different error codes, each with their own meaning, and many
  with references to specific implementations.

  The authors of SibylIFS tried to write down an exact description of the
  open interface. Their annotated version[1] of the POSIX standard is over
  3000 words. Not counting basic machinery, it took them over 200 lines[2]
  to write down the properties of open in higher-order logic, and another
  70 to give the interactions between open and close.
  [1]: https://github.com/sibylfs/sibylfs_src/blob/8a7f53ba58654249b0ec0725ce3887840d6a1812/fs_spec/src/posix/open.md
  [2]: https://github.com/sibylfs/sibylfs_src/blob/8a7f53ba58654249b0ec0725ce3887840d6a1812/fs_spec/src/t_fs_spec_fs_command_properties.lem_cppo#L460

I just thought it was a thought-provoking comment on the apparent elegance
of the Unix file API that actually has some subtle complexity.

Cheers, Warren

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

end of thread, other threads:[~2018-11-05 15:38 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-04 22:29 [TUHS] Unix APIs: elegant or not? Theodore Y. Ts'o
  -- strict thread matches above, loose matches on Subject: below --
2018-11-04 22:37 Noel Chiappa
2018-11-05  4:04 ` Dave Horsfall
2018-11-01 15:39 Noel Chiappa
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
2018-11-05 14:11       ` Donald ODona
2018-11-04 13:35   ` Warner Losh
2018-11-04 19:47   ` Dave Horsfall

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).