public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Zack Weinberg <zackw@panix.com>
To: Szabolcs Nagy <szabolcs.nagy@arm.com>
Cc: Adhemerval Zanella <adhemerval.zanella@linaro.org>,
	nd <nd@arm.com>,  GNU C Library <libc-alpha@sourceware.org>
Subject: Re: system and popen fail in case of big application
Date: Fri, 14 Sep 2018 18:42:00 -0000	[thread overview]
Message-ID: <CAKCAbMiPsN-MS7Gr=QCi1M0W4fiNa9N-hvHWrj+w++eg_SNFSg@mail.gmail.com> (raw)
In-Reply-To: <05593924-cd6b-9099-c177-5d7828bc3189@arm.com>

On Thu, Sep 13, 2018 at 8:11 AM Szabolcs Nagy <szabolcs.nagy@arm.com> wrote:
> On 12/09/18 17:29, Zack Weinberg wrote:
> > I don't want to encourage people to use posix_spawn because
> > posix_spawn is a badly designed API.  It's difficult to use correctly.
> > It's *tedious* to use correctly, which means people won't bother.  It
> > can't do everything you might want to do on the child side (witness
> > the discussion of adding an extension to let it do chdir()).  Its
> > behavior in case of errors is underspecified.  And it might be
>
> the misdesigned api is vfork: it is not just difficult to use
> correctly but impossible: it breaks c language semantics
> (gcc fixes this up to some extent when it sees the actual vfork
> symbol in the code, but there is no guarantee in c that the
> compiler can see that, and even then the shared stack between
> parent and child has various issues as Adhemerval described)
[etc]

The way I see it is that that is all stuff that could be fixed.  I
looked at what Adhemerval did in s/u/s/linux/spawni.c and it appears
that generalizing it to `pid_t nvfork(void (*)(void *))` would solve
_all_ of the problems you list and even be safe to expose to
applications.  (Name provisional.)

On the other hand, in my opinion posix_spawn is an irretrievably
flawed design, because of its underspecification, because of its
license to lose error details, and above all, because it _doesn't_
allow you to perform arbitrary computation on the child side, which
means we will forever be playing catch-up with the list of "actions".
I want to see it deprecated and removed from POSIX, and that means
coming up with a genuinely better way to do what it does.  nvfork()
seems like a step in the right direction.

(I've actually had an even better plan in mind for years now,
involving a new "embryo" process state, but someone would have to pay
me to argue with Linus, or else take over that part of the project
themselves.)

> vfork can be implemented in terms of fork too, memcpy can be
> implemented using syscalls, these are QoI issues

I don't see it that way.  The kind of underspecification that both
vfork and posix_spawn suffer is the same kind of underspecification
that renders it unwise to use signal(), and continuing the analogy,
the virtue of sigaction() is that it _does_ specify all of the
behavioral details like whether or not signal delivery will cause
blocking system calls to fail and set errno to EINTR.

If we were going to add the hypothetical nvfork(), I would write into
its documentation that it is _guaranteed_ to have vfork-like behavior
(that is, it calls the supplied procedure in the memory space of the
parent process; writes through the closure parameter are visible to
the caller, as are any changes to errno; control does not return to
the caller until the procedure finishes) and it will fail and set
errno to ENOSYS if the OS doesn't make that possible.

zw

  reply	other threads:[~2018-09-14 18:42 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-09 22:16 Sergey Melnikov
2018-09-09 22:44 ` Zack Weinberg
2018-09-09 22:47   ` Zack Weinberg
2018-09-09 23:27     ` Sergey Melnikov
2018-09-09 23:49       ` Zack Weinberg
2018-09-10  2:50         ` Martin Buchholz
2018-09-10 15:38       ` Joseph Myers
2018-09-10 15:42         ` Zack Weinberg
2018-09-10 15:43           ` Joseph Myers
     [not found]       ` <CA+kOe0_1k_PbJ-pjHznP4AmTJUgziAdT+4vCcCRSb7GGdvbv7Q@mail.gmail.com>
2018-09-10 15:59         ` Zack Weinberg
2018-09-10 16:55           ` Martin Buchholz
2018-09-11 20:16   ` Adhemerval Zanella
2018-09-12 16:30     ` Zack Weinberg
2018-09-12 19:46       ` Martin Buchholz
2018-09-13  1:27         ` Adhemerval Zanella
2018-09-13  6:31           ` Andreas Schwab
2018-09-13 12:30             ` Adhemerval Zanella
2018-09-18  1:18           ` Martin Buchholz
2018-09-18  1:59             ` Adhemerval Zanella
2018-09-18  2:18               ` Martin Buchholz
2018-09-18  4:31               ` Rich Felker
2018-09-12 23:08       ` Adhemerval Zanella
2018-09-13 12:11       ` Szabolcs Nagy
2018-09-14 18:42         ` Zack Weinberg [this message]
2018-09-17 10:32           ` Szabolcs Nagy
2018-09-17 18:27             ` Adhemerval Zanella

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='CAKCAbMiPsN-MS7Gr=QCi1M0W4fiNa9N-hvHWrj+w++eg_SNFSg@mail.gmail.com' \
    --to=zackw@panix.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    --cc=nd@arm.com \
    --cc=szabolcs.nagy@arm.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.
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).