This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: static fork strerror and how they interact.
- From: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- To: libc-help at sourceware dot org
- Date: Tue, 22 Dec 2015 10:50:21 -0200
- Subject: Re: static fork strerror and how they interact.
- Authentication-results: sourceware.org; auth=none
- References: <trinity-e1774b10-9cc4-4e09-8dce-005525e3c848-1414501291095 at 3capp-mailcom-lxa08> <CAE2sS1iVCRNNneppQEU1C+4OXWV7g9FqRuYKweNFJpRTQW8BEw at mail dot gmail dot com> <56773521 dot 1040509 at gmail dot com> <CAE2sS1hV43ffODGce9nrQDMUpER_-frv0vSZ=2wzeCJZeYrpsA at mail dot gmail dot com>
On 21-12-2015 13:12, Carlos O'Donell wrote:
> On Sun, Dec 20, 2015 at 6:09 PM, Ãngel GonzÃlez <keisial@gmail.com> wrote:
>> On 28/10/14 15:02, Carlos O'Donell wrote:
>>>
>>> Even more complicated is using vfork safely from a multi-threaded
>>> application. I have written up a very thorough example on this, but
>>> have not posted it yet.
>>
>> Did you finally publish this?
>
> Yes.
>
> You can read it here:
> http://developerblog.redhat.com/2015/08/19/launching-helper-process-under-memory-and-latency-constraints-pthread_create-and-vfork/
>
So it is basically a strip down posix_spawn implementation without the file
actions or spawn attributes implemented with vfork. IMHO I think we can
fix GLIBC posix_spawn issues [1] [2] [3] [4] so there will be no need for
such reimplementation and still having good performance concerned memory
and latency constraints.
My understanding reading the bugzillas reports the fork use in current
GLIBC code for cases where file actions are required are due the fact
they are cancellation entrypoint and since vfork share the VMA it would
be simpler to just use fork to avoid the cancellation action. I see
it can be fixed by setting disabling cancellation on function execution
for the current thread and on child by using direct syscall invocation
or by creating the syscall_no_cancel wrappers.
Also, as pointed out by Rich Felker, instead of vfork() it would be
preferable use clone with CLONE_VM. It has some advantages:
1. The compiler could make optimization in the child function that
might clobber parent's local variable (as pointed out in the
first comment in your blog entry).
2. With strace there might be cases where it allows the vforking
parent to run before the child execs
Also with a simple ipc mechanism (close-on-exec pipe) it is possible
to report exec failures to the posix_spawn caller instead of just
reporting the status 127 on exec error.
This is on my radar list.
[1] https://sourceware.org/bugzilla/show_bug.cgi?id=14499
[2] https://sourceware.org/bugzilla/show_bug.cgi?id=14749
[3] https://sourceware.org/bugzilla/show_bug.cgi?id=14750
[4] https://sourceware.org/bugzilla/show_bug.cgi?id=10354
> Cheers,
> Carlos.
>