Skip to content

Commit

Permalink
Backported fix for CORE-1558: Help people get core files in case of a…
Browse files Browse the repository at this point in the history
…bort() on BUGCHECK
  • Loading branch information
AlexPeshkoff committed Nov 2, 2007
1 parent 39fd59d commit c59d5b9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
3 changes: 2 additions & 1 deletion configure.in
Expand Up @@ -435,7 +435,7 @@ AC_CHECK_HEADERS(aio.h)
AC_CHECK_HEADERS(mntent.h mnttab.h sys/mntent.h sys/mnttab.h)
AC_CHECK_HEADERS(sys/ipc.h sys/file.h)
AC_CHECK_HEADERS(socket.h sys/socket.h sys/sockio.h winsock2.h)

AC_CHECK_HEADERS(sys/resource.h)

dnl Check for libraries
AC_CHECK_LIB(dl, main)
Expand Down Expand Up @@ -513,6 +513,7 @@ if test "$ac_cv_func_getmntent" = "yes"; then
AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no)])
fi
AC_CHECK_FUNCS(setrlimit getrlimit)
AC_CHECK_FUNCS(tcgetattr strdup)
AC_CHECK_FUNCS(mkstemp)
AC_CHECK_FUNCS(pthread_keycreate pthread_key_create)
Expand Down
31 changes: 31 additions & 0 deletions src/jrd/err.cpp
Expand Up @@ -33,6 +33,7 @@
#include <stdarg.h>
#include "gen/iberror.h"
#include "../jrd/iberr.h"
#include <errno.h>

#if ( !defined( REQUESTER) && !defined( SUPERCLIENT))
#include "../jrd/jrd.h"
Expand All @@ -54,6 +55,10 @@
#include "../common/config/config.h"
#include "../common/utils_proto.h"

#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif

using namespace Jrd;

//#define JRD_FAILURE_SPACE 2048
Expand Down Expand Up @@ -553,7 +558,33 @@ void ERR_punt(void)
tdbb->tdbb_attachment->att_filename.c_str() : "Database unknown in ERR_punt on bugcheck",
tdbb->tdbb_status_vector);
if (Config::getBugcheckAbort())
{
#if defined(UNIX) && defined(HAVE_SETRLIMIT) && defined(HAVE_GETRLIMIT)
// try to force core files creation
struct rlimit core;
if (getrlimit(RLIMIT_CORE, &core) == 0)
{
core.rlim_cur = core.rlim_max;
if (setrlimit(RLIMIT_CORE, &core) != 0)
{
gds__log("setrlimit() failed, errno=%d", errno);
}
}
else
{
gds__log("getrlimit() failed, errno=%d", errno);
}

// we need some writable directory for core file
// on any unix /tmp seems to be the best place
if (chdir("/tmp") != 0)
{
gds__log("chdir(/tmp) failed, errno=%d", errno);
}
#endif

abort();
}
}

Firebird::status_exception::raise(tdbb->tdbb_status_vector);
Expand Down
2 changes: 1 addition & 1 deletion src/remote/inet_server.cpp
Expand Up @@ -280,7 +280,7 @@ int CLIB_ROUTINE server_main( int argc, char** argv)
set_signal(SIGUSR2, signal_handler);
#endif

#if defined(UNIX) && defined(DEV_BUILD)
#if defined(UNIX) && defined(DEV_BUILD) && defined(HAVE_SETRLIMIT) && defined(HAVE_GETRLIMIT)
{
// try to force core files creation for DEV_BUILD
struct rlimit core;
Expand Down

0 comments on commit c59d5b9

Please sign in to comment.