On Wednesday 03 April 2002 11:07, Robert Collins wrote:
> The vfork+exec combination is ancient - it dates from unices
> without copy-on-write fork().
And most never got it correct.
> If squid opens all the FD's with close-on-exec set, then to emulate
> posix_spawn we can write
>
> (roughly speaking)
>
> squid_spawn (prog, argc, argv, fdc, fdarray);
>
> int squid_spawn(prog, argc, argv, fdc, fdarray)
> {
> // use fddup to 'backup' current fd's from 0 to fdc-1
> // use fddup to copy the fdarray contents to 0->fdc-1
> // vfork
> // in parent
> // restore fd's
> // in child
> // exec()
> }
Issues:
a) We need to clean up not only filedescriptors but also drop root
privileges etc before starting the child.. with vfork this can only
be done with a intermediary helper.. exec to intermediarey helper who
cleans up things and then execs the real thing.
b) Some UNIX:es have given up on providing a correct vfork() and have
it identical to fork(), making it somewhat counter-productive to
spend time today on making correct use of vfork().
c) Things crash an burn if the child receives a signal between
vfork() and execve().
d) There is no directly clean way to handle a failed execve() when
vfork() is used.
Remains to see if we even can use posix_spawn for Squid (haven't
actually read about it yet, but preleminary it looks good..)
For now we will stick to plain fork().
Regards
Henrik
Received on Wed Apr 03 2002 - 02:30:36 MST
This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:14:57 MST