Subject: Re: locking in getenv
To: Patrick Welche <prlw1@newn.cam.ac.uk>
From: Bill Studenmund <wrstuden@netbsd.org>
List: current-users
Date: 02/02/2004 14:11:39
--oyUTqETQ0mS9luUI
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,=
=20
> I get the following backtrace. If I disable libxml, all is OK. How
> can this cause a core dump in getenv?!
>=20
> #0  0x482949fb in kill () from /usr/lib/libc.so.12
> #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=
nfig.c:433
> #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();
>=20
> 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=
=20
been linked against libpthread, it would have been loaded at startup, and=
=20
its symbol aliasing would have mapped that call to=20
pthread_rwlock_rdlock().

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=
=20
pulling in libpthread.

Take care,

Bill

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

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (NetBSD)

iD8DBQFAHssbWz+3JHUci9cRAoG+AJ9XCXVtd5s9zJQvOtMp9H+tmiAOaACcDOd+
C/p2AaI2Jg3WE2Co0teXaA8=
=fBV5
-----END PGP SIGNATURE-----

--oyUTqETQ0mS9luUI--