Subject: realpath() is not thread-safe
To: None <tech-smp@NetBSD.org>
From: Justin Lundy <jbl@subterrain.net>
List: tech-smp
Date: 01/15/2005 02:15:19
This is a multi-part message in MIME format.

--Boundary_(ID_3JhKo7h1gvvyzeBJ32P/Jg)
Content-type: text/plain; charset=ISO-8859-1; format=flowed
Content-transfer-encoding: 7BIT

I uncovered some strange behavior on a NetBSD 2.0/i386 SMP machine and 
asked the guys on the mysql-general list to explain it. Here is what 
they said. To quote Dan Nelson:

"On FreeBSD, this was due to realpath not being thread-safe.  It called
chdir() internally and didn't prevent other threads from calling
chdir() or getcwd() at the same time.  NetBSD's realpath looks almost
identical to the old FreeBSD code, so it should be easy to fix by just
merging the fix from FreeBSD.

http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/gen/getcwd.c
http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc/stdlib/realpath.c

The FreeBSD fix is in rev 1.14."

This occurs regularly on a mysql server which is handling a paltry 10 
mysql connections/sec and 150 mysql queries/sec. I have not seen this 
behavior when I boot the machine with the non SMP kernel. Has anyone 
scoped out adapting FreeBSD's thread-safe realpath() into NetBSD or 
shall I take a stab at it?

Regards,
-JBL

--Boundary_(ID_3JhKo7h1gvvyzeBJ32P/Jg)
Content-type: text/x-vcard; charset=utf-8; name=jbl.vcf
Content-transfer-encoding: 7BIT
Content-disposition: attachment; filename=jbl.vcf

begin:vcard
fn:Justin Lundy
n:Lundy;Justin
email;internet:jbl@subterrain.net
version:2.1
end:vcard


--Boundary_(ID_3JhKo7h1gvvyzeBJ32P/Jg)--