diff --git a/config.h.in b/config.h.in index 6af0a7450..9f06d9a5c 100644 --- a/config.h.in +++ b/config.h.in @@ -6,7 +6,7 @@ /* Define to 1 if you have the header file. */ #undef HAVE_DIRECT_H -/* Define to 1 if you have the header file. */ +/* The backtrace function is declared in execinfo.h and works */ #undef HAVE_EXECINFO_H /* Define to 1 if you have FreeType2. */ diff --git a/configure.ac b/configure.ac index 5fb16d007..fa75db95b 100644 --- a/configure.ac +++ b/configure.ac @@ -56,13 +56,27 @@ AM_CONDITIONAL(MACOSX, [test $osx = true]) # various used headers dnl the whitespace is there to prevent AC_INCLUDES_DEFAULT -AC_CHECK_HEADERS([stdint.h unistd.h poll.h sys/stat.h sys/types.h locale.h sys/socket.h signal.h langinfo.h execinfo.h sys/inotify.h sys/syscall.h], , , [[ ]]) +AC_CHECK_HEADERS([stdint.h unistd.h poll.h sys/stat.h sys/types.h locale.h sys/socket.h signal.h langinfo.h sys/inotify.h sys/syscall.h], , , [[ ]]) # Mingw does not ship with multimon.h AC_CHECK_HEADERS([multimon.h io.h direct.h share.h], [], [], [[#include ]]) # iconv AX_ICONV # vasprintf is a GNU extension AC_CHECK_FUNCS(vasprintf) +# so is execinfo.h - and some systems have the header despite the functions not being in the c library +AC_CHECK_HEADER(execinfo.h) +if test "x$ac_cv_header_execinfo_h" = xyes; then + AC_CHECK_FUNC(backtrace, [], [ + AC_CHECK_LIB(execinfo, backtrace, [ + CLONK_LIBS="-lexecinfo $CLONK_LIBS" + ], [ + ac_cv_header_execinfo_h=no + ]) + ]) +fi +if test "x$ac_cv_header_execinfo_h" = xyes; then + AC_DEFINE(HAVE_EXECINFO_H, 1, [The backtrace function is declared in execinfo.h and works]) +fi AC_ARG_ENABLE([debug], [AC_HELP_STRING([--enable-debug], [debugging options [default=no]])], diff --git a/src/C4WinMain.cpp b/src/C4WinMain.cpp index 8e70c7495..e6c2493d2 100644 --- a/src/C4WinMain.cpp +++ b/src/C4WinMain.cpp @@ -131,7 +131,6 @@ int main() #include #include -#include #ifdef HAVE_SYS_TYPES_H #include @@ -143,8 +142,11 @@ int main() # include #endif +#ifdef HAVE_SIGNAL_H +#include #ifdef HAVE_EXECINFO_H #include +#endif static void crash_handler(int signo) { @@ -170,6 +172,7 @@ static void crash_handler(int signo) else break; if (logfd < 0) break; } +#ifdef HAVE_EXECINFO_H // Get the backtrace void *stack[100]; int count = backtrace(stack, 100); @@ -178,10 +181,11 @@ static void crash_handler(int signo) // Also to the log file if (logfd >= 0) backtrace_symbols_fd (stack, count, logfd); +#endif // Bye. _exit(C4XRV_Failure); } -#endif +#endif // HAVE_SIGNAL_H #ifdef __APPLE__ void restart(char* args[]) { @@ -206,7 +210,7 @@ int main (int argc, char * argv[]) printf("Do not run %s as root!\n", argc ? argv[0] : "this program"); return C4XRV_Failure; } -#ifdef HAVE_EXECINFO_H +#ifdef HAVE_SIGNAL_H // Set up debugging facilities signal(SIGBUS, crash_handler); signal(SIGILL, crash_handler);