You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.9 KiB

  1. From 03dbd6757d043581b5d250107b6f1cda6ae203a9 Mon Sep 17 00:00:00 2001
  2. From: Frederik Deweerdt <fdeweerdt@fastly.com>
  3. Date: Wed, 25 Oct 2017 13:52:28 -0700
  4. Subject: [PATCH] Autodetect backtrace and backtrace_symbols_fd
  5. ---
  6. CMakeLists.txt | 13 +++++++++++++
  7. src/main.c | 10 ++++++----
  8. 2 files changed, 19 insertions(+), 4 deletions(-)
  9. diff --git a/CMakeLists.txt b/CMakeLists.txt
  10. index abfab1f19..2a26fb98a 100644
  11. --- a/CMakeLists.txt
  12. +++ b/CMakeLists.txt
  13. @@ -58,6 +58,19 @@ __sync_add_and_fetch(&a, 1);
  14. return 0;
  15. }" ARCH_SUPPORTS_64BIT_ATOMICS)
  16. +CHECK_C_SOURCE_COMPILES("
  17. +#include <execinfo.h>
  18. +int main(void) {
  19. +void *p[10];
  20. +int ret = backtrace(p, 10);
  21. +backtrace_symbols_fd(p, ret, 2);
  22. +return 0;
  23. +}" LIBC_HAS_BACKTRACE)
  24. +
  25. +IF (LIBC_HAS_BACKTRACE)
  26. + ADD_DEFINITIONS("-DLIBC_HAS_BACKTRACE")
  27. +ENDIF ()
  28. +
  29. SET(WITH_BUNDLED_SSL_DEFAULT "ON")
  30. IF ((NOT UNIX) OR CYGWIN)
  31. SET(WITH_BUNDLED_SSL_DEFAULT "OFF")
  32. diff --git a/src/main.c b/src/main.c
  33. index 7c346af18..edc7d5eb3 100644
  34. --- a/src/main.c
  35. +++ b/src/main.c
  36. @@ -48,7 +48,7 @@
  37. #include <openssl/crypto.h>
  38. #include <openssl/err.h>
  39. #include <openssl/ssl.h>
  40. -#ifdef __GLIBC__
  41. +#ifdef LIBC_HAS_BACKTRACE
  42. #include <execinfo.h>
  43. #endif
  44. #if H2O_USE_PICOTLS
  45. @@ -1435,7 +1435,8 @@ static void on_sigterm(int signo)
  46. notify_all_threads();
  47. }
  48. -#ifdef __GLIBC__
  49. +#ifdef LIBC_HAS_BACKTRACE
  50. +
  51. static int popen_crash_handler(void)
  52. {
  53. char *cmd_fullpath = h2o_configurator_get_cmd_path(conf.crash_handler), *argv[] = {cmd_fullpath, NULL};
  54. @@ -1487,13 +1488,14 @@ static void on_sigfatal(int signo)
  55. raise(signo);
  56. }
  57. -#endif
  58. +
  59. +#endif /* LIBC_HAS_BACKTRACE */
  60. static void setup_signal_handlers(void)
  61. {
  62. h2o_set_signal_handler(SIGTERM, on_sigterm);
  63. h2o_set_signal_handler(SIGPIPE, SIG_IGN);
  64. -#ifdef __GLIBC__
  65. +#ifdef LIBC_HAS_BACKTRACE
  66. if ((crash_handler_fd = popen_crash_handler()) == -1)
  67. crash_handler_fd = 2;
  68. h2o_set_signal_handler(SIGABRT, on_sigfatal);