diff --git a/src/modules/system/acconfig.h b/src/modules/system/acconfig.h
index f58bd99d23a5474ad64ca93d4bded19c4600f49e..3f3e99d09fd8aca49bd6550bce37e454ece9881c 100644
--- a/src/modules/system/acconfig.h
+++ b/src/modules/system/acconfig.h
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: acconfig.h,v 1.14 2003/04/22 15:15:50 marcus Exp $
+|| $Id: acconfig.h,v 1.15 2003/05/20 15:12:39 mast Exp $
 */
 
 /*
@@ -65,4 +65,7 @@
 /* Define if you have the RDTSC instruction */
 #undef HAVE_RDTSC
 
+/* Define if syslog() might have races which makes it unsafe to run unlocked. */
+#undef MIGHT_HAVE_SYSLOG_RACES
+
 #endif /* SYSTEM_MACHINE_H */
diff --git a/src/modules/system/configure.in b/src/modules/system/configure.in
index 286bb9f96df8ac2172c59c1cd96fe9f6220f5016..eaeb9e85a6f3ae0f237a2857d30ba033427a9294 100644
--- a/src/modules/system/configure.in
+++ b/src/modules/system/configure.in
@@ -1,4 +1,4 @@
-# $Id: configure.in,v 1.62 2003/05/06 11:14:16 grubba Exp $
+# $Id: configure.in,v 1.63 2003/05/20 15:12:39 mast Exp $
 AC_INIT(system.c)
 AC_CONFIG_HEADER(system_machine.h)
 
@@ -301,6 +301,21 @@ else
   AC_MSG_RESULT(no)
 fi
 
+AC_MSG_CHECKING(for GNU libc)
+AC_CACHE_VAL(pike_cv_glibc, [
+  AC_EGREP_CPP(no_glibc, [
+#include <features.h>
+#ifndef __GLIBC__
+no_glibc
+#endif
+  ], pike_cv_glibc=no, pike_cv_glibc=yes)
+])
+if test "$pike_cv_glibc" = yes; then
+  AC_MSG_RESULT(yes - disabling unlocked syslog calls)
+  AC_DEFINE(MIGHT_HAVE_SYSLOG_RACES)
+else
+  AC_MSG_RESULT(no)
+fi
 
 
 AC_MSG_CHECKING(setrlimit syntax)
diff --git a/src/modules/system/syslog.c b/src/modules/system/syslog.c
index e80f8a07ba62ce29358db47f714f17e1c8c86a71..1b14a5f6441a44c51f99f64f8400b874ba6195b8 100644
--- a/src/modules/system/syslog.c
+++ b/src/modules/system/syslog.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: syslog.c,v 1.19 2003/01/05 13:08:37 nilsson Exp $
+|| $Id: syslog.c,v 1.20 2003/05/20 15:12:40 mast Exp $
 */
 
 /*
@@ -22,7 +22,7 @@
 
 #ifdef HAVE_SYSLOG
 
-RCSID("$Id: syslog.c,v 1.19 2003/01/05 13:08:37 nilsson Exp $");
+RCSID("$Id: syslog.c,v 1.20 2003/05/20 15:12:40 mast Exp $");
 
 #include "interpret.h"
 #include "svalue.h"
@@ -247,12 +247,26 @@ void f_syslog(INT32 args)
   if(i & (1<<5)) pri |= LOG_NOTICE;
   if(i & (1<<6)) pri |= LOG_INFO;
   if(i & (1<<6)) pri |= LOG_DEBUG;
-  
+
+#ifndef MIGHT_HAVE_SYSLOG_RACES
+  /* glibc/linuxthreads has a race in syslog(2) that can make write,
+   * writev etc crash with the instruction pointer set to 0x1 when
+   * signals are delivered. Not releasing the interpreter lock here
+   * avoids that race most of the time but it's still not a 100%
+   * solution.
+   *
+   * C.f. the report "bug in thread support" filed by Balazs Scheidler
+   * in Oct 22, 2001 (http://sources.redhat.com/ml/libc-hacker/
+   * 2001-10/msg00020.html). It's verified to still exist in glibc
+   * 2.2.93 (RedHat 8.0) and 2.3.2 (RedHat 9). */
   THREADS_ALLOW();
- 
+#endif
+
   syslog(pri, "%s", s->str);
 
+#ifndef MIGHT_HAVE_SYSLOG_RACES
   THREADS_DISALLOW();
+#endif
 
   pop_n_elems(args);
 }