Subject: Re: locking in getenv
To: Patrick Welche <>
From: Bill Studenmund <>
List: current-users
Date: 02/02/2004 14:11:39
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sat, Jan 31, 2004 at 08:07:43PM +0000, Patrick Welche wrote:
> In apache, if I LoadModule the php5 module compiled with --enable-libxml,=
> I get the following backtrace. If I disable libxml, all is OK. How
> can this cause a core dump in getenv?!
> #0  0x482949fb in kill () from /usr/lib/
> #1  0x48296c6b in __libc_rwlock_catchall_stub (l=3D0x80d40a5)
>     at /usr/src/lib/libc/thread-stub/thread-stub.c:239
> #2  0x48307979 in getenv (name=3D0x80d40a5 "SHOW_HOOKS")
>     at /usr/src/lib/libc/stdlib/getenv.c:66
> #3  0x0809fb75 in ap_register_hooks (m=3D0x48457a40, p=3D0x80ec018) at co=
> #4  0x0809fd93 in ap_add_loaded_module (mod=3D0x48457a40, p=3D0x80ec018)
>     at config.c:565
> #5  0x0809d7cf in load_module (cmd=3D0xbfbff520, dummy=3D0x0,
>     modname=3D0x8130cb8 "php5_module", filename=3D0x48457a40 "e?1\001\003=
>     at mod_so.c:323
> =20
> Presumably CHECK_NOT_THREADED(); is causing the abort...
> =20
> getenv:
>         rwlock_rdlock(&__environ_lock);
>         result =3D __findenv(name, &offset);
>         rwlock_unlock(&__environ_lock);
> =20
> rwlock_rdlock, rwlock_unlock are all essentially just CHECK_NOT_THREADED,
> i.e., if(__isthreaded)DIE();
> In fact it works now as I recompiled libxml --without-threads. However,
> I'm still confused: why is obtaining a lock the same as checking one
> isn't in a thread? What might the underlying problem be? one in libxml,
> or the way mod_php uses it?

The problem is that you aren't using a threaded version of php. If php had=
been linked against libpthread, it would have been loaded at startup, and=
its symbol aliasing would have mapped that call to=20

Your module is pulling in libpthread, and initializing threading, thus=20
__isthreaded is true. But when your module is loaded is far too late to be=
pulling in libpthread.

Take care,


Content-Type: application/pgp-signature
Content-Disposition: inline

Version: GnuPG v1.2.3 (NetBSD)