mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Subject: Re: vfork replacement proposal
Date: Sun, 3 Feb 2013 21:36:37 +0100	[thread overview]
Message-ID: <20130203203637.GP6181@port70.net> (raw)
In-Reply-To: <20130203184923.GA20323@brightrain.aerifal.cx>

* Rich Felker <dalias@aerifal.cx> [2013-02-03 13:49:23 -0500]:
> On Mon, Dec 31, 2012 at 03:34:17PM -0500, Rich Felker wrote:
> > 4. In the child, close the read end of the pipe and then shuffle file
> > descriptors as needed (for setting up stdin/out for popen, or file
> > actions for posix_spawn[p]), but with the added stipulations A-C:
> > 
> > A. Before closing or dup2'ing onto a file descriptor in file actions,
> > check to see if it's occupied by the pipe fd, and if so, use fcntl
> > F_DUPFD_CLOEXEC to move it to a new number first.
> > 
> > B. Before calling open in file actions, always use fcntl with
> > F_DUPFD_CLOEXEC and close the original pipe fd, to ensure that the
> > pipe is never occupying the otherwise-lowest-available fd number.
> 
> I was wrong about (B); the "open" file action does not assign the
> lowest-available fd, but a caller-chosen fd. Thus, for our purposes,
> it's just like close or dup2, targetting a known fd number. This means
> the same logic can be used for all three operations, and it can be
> based on dup() rather than F_DUPFD_CLOEXEC. Note that F_DUPFD_CLOEXEC
> is actually not viable because it's missing on slightly-old kernels
> (up through mid 2.6 series), but we don't need atomicity anyway since
> this thread/process is fully under posix_spawn's control.
> 
> Also, I think it would be possible to abandon the "shuffling" logic
> and compute in advance a safe fd number to put the pipe on. 
> 
> Finally, it seems posix_spawn will be sufficient as a backend for
> implementing popen, wordexp, and system, so I just put all the logic
> in posix_spawn itself rather than trying to design a more abstract API
> with callbacks for the specific caller case.
> 

hm, is it possible to have a non-forking spawn that covers all the
fork+exec cases? (things one might want to do before exec, eg by
specifying extra attributes..)

as far as i can see posix_spawn handles these:

 setenv
 fds (file_actions, O_CLOEXEC)
 setpgid (POSIX_SPAWN_SETPGROUP)
 drop euid, egid (POSIX_SPAWN_RESETIDS)
 sigmask, default sighandlers (POSIX_SPAWN_SETSIGMASK, POSIX_SPAWN_SETSIGDEF)
 sched param/policy (POSIX_SPAWN_SETSCHEDPARAM, POSIX_SPAWN_SETSCHEDULER)

but not these:

 setsid
 setuid, setgid, setgroups
 chdir
 chroot
 rlimits
 enable ptrace
 ioctl, setctty/noctty
 prctl, parent death signal
 (maybe others..)


  reply	other threads:[~2013-02-03 20:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-31 20:34 Rich Felker
2013-02-03 18:49 ` Rich Felker
2013-02-03 20:36   ` Szabolcs Nagy [this message]
2013-02-03 20:47     ` 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=20130203203637.GP6181@port70.net \
    --to=nsz@port70.net \
    --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).