Use backtrace when --enable-debug=yes and avail.
I KNOW AUTOCONF.
This commit is contained in:
parent
24110a58dc
commit
b222196b18
14
configure.in
14
configure.in
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
23
src/util.c
23
src/util.c
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user