[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: zombie processes in openldap-1.0.3 shell backend

Hallvard B Furuseth wrote:
> Kurt D. Zeilenga writes:
> > I suspect this code is buggy.   Besides the wait() issue, it has
> > a few other problems.  First off, fork() in threaded environments
> > and doing anything other than exec() is a bad idea (including calling
> > close()).
> I'm not about to mess with thread stuff myself, but I imagine
>                 switch ( (pid = fork()) ) {
> in servers/slapd/back-shell/fork.c should be
>         #if HAVE_THR
>                                 pid = fork1();
>         #else
>                                 pid = fork();
>         #endif
>         switch ( pid ) {
> similar to what liblutil/detach.c, since fork() with HAVE_THR copies all
> the threads instead of just the thread doing fork().

When detach() is called only one thread exists and hence use of fork1()
is not necessary.

In back-shell, yes, fork1() should be used over fork() (for THR).
However, fork1() acts like POSIX fork() in that all mutexes are left
locked which might result in close() and other library calls to deadlock.
This is why a surrogate parent is needed.

> Oh, BTW, there is a thread leak in servers/slapd/connection.c: The
> threads createad by pthread_create() are never collected with
> pthread_join().

POSIX 'detached' threads cannot be joined.  We likely
should have lthread_join() which does the right thing
based upon which threading environment we are runnning
in if other threading environments require the join
(likely if they don't support detachment).