Use backtrace when --enable-debug=yes and avail.

I KNOW AUTOCONF.
This commit is contained in:
Arnaud Cornet 2008-12-28 15:47:43 +01:00
parent 24110a58dc
commit b222196b18
3 changed files with 37 additions and 3 deletions

View File

@ -11,7 +11,7 @@ AC_ARG_ENABLE(debug,
[ enable_debug=$enableval ],
[ enable_debug=no ])
AM_CONDITIONAL(DEBUG, test x$enable_debug = xtrue)
AM_CONDITIONAL(DEBUG, test x$enable_debug = xyes)
case $enable_debug in
yes)
@ -24,6 +24,18 @@ no)
AC_MSG_ERROR(bad value ${enable_debug} for --enable-debug)
esac
if test x$enable_debug = xyes ; then
AC_CHECK_FUNC(backtrace,
[
AC_CHECK_FUNC(backtrace_symbols,
[
AC_DEFINE(HAVE_BACKTRACE, [], [Use Glibcs backtrace function on fatal()])
LDFLAGS="-rdynamic $LDFLAGS"
]
)
])
fi
AC_ARG_ENABLE(oidentd,
[ --enable-oidentd Enable oidentd support (bip overwrites ~/.oidentd.conf with this on!)],
enable_oidentd=yes

View File

@ -1,5 +1,8 @@
/* src/config.h.in. Generated from configure.in by autoheader. */
/* Use Glibcs backtrace function on fatal() */
#undef HAVE_BACKTRACE
/* Define to 1 if you have the `crypto' library (-lcrypto). */
#undef HAVE_LIBCRYPTO

View File

@ -198,15 +198,34 @@ void mylog(int level, char *fmt, ...)
va_end(ap);
}
#ifdef HAVE_BACKTRACE
#include <execinfo.h>
void print_trace(void)
{
void *array[32];
size_t size;
size_t i;
size = backtrace(array, 32);
fflush(conf_global_log_file);
backtrace_symbols_fd(array, size, fileno(conf_global_log_file));
}
#endif
extern char *conf_pid_file;
void fatal(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
_mylog(LOG_FATAL, fmt, ap);
va_end(ap);
#ifdef HAVE_BACKTRACE
print_trace();
#endif
exit(200);
}