# The kernel won't generate coredumps after setgid() and setuid()
# unless prctl(PR_SET_DUMPABLE, 1) is called
--- sql/mysqld.cc
+++ sql/mysqld.cc
@@ -135,6 +135,10 @@
 #include <sys/mman.h>
 #endif
 
+#ifdef HAVE_LINUX_PRCTL
+#include <sys/prctl.h>
+#endif
+
 #ifdef __NETWARE__
 #define zVOLSTATE_ACTIVE 6
 #define zVOLSTATE_DEACTIVE 2
@@ -1339,7 +1343,13 @@
     sql_perror("setuid");
     unireg_abort(1);
   }
-#endif
+#ifdef HAVE_LINUX_PRCTL
+  if (test_flags & TEST_CORE_ON_SIGNAL)
+  {
+    prctl(PR_SET_DUMPABLE, 1);
+  }
+#endif   /* HAVE_LINUX_PRCTL */
+#endif /* !__WIN__ !OS2 !__NETWARE__ */
 }
 
 
--- configure.in
+++ configure.in
@@ -2199,6 +2199,19 @@
 fi
 AC_MSG_RESULT("$netinet_inc")
 
+# Check for Linux prctl() to get mysqld coredumps
+# IRIX reportedly has prctl() too, but it works different
+AC_MSG_CHECKING(for Linux prctl())
+AC_TRY_COMPILE(
+[#include <sys/prctl.h>],
+[prctl(PR_SET_DUMPABLE, 1);],
+linux_prctl=yes, linux_prctl=no)
+if test "$linux_prctl" = "yes"
+then
+  AC_DEFINE([HAVE_LINUX_PRCTL], [1], [prctl(PR_SET_DUMPABLE, 1) can be used])
+fi
+AC_MSG_RESULT($linux_prctl)
+
 # Only build client code?
 AC_ARG_WITH(server,
     [  --without-server        Only build the client.],
