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.

70 lines
1.8 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. --- a/CMakeLists.txt
  10. +++ b/CMakeLists.txt
  11. @@ -58,6 +58,19 @@ __sync_add_and_fetch(&a, 1);
  12. return 0;
  13. }" ARCH_SUPPORTS_64BIT_ATOMICS)
  14. +CHECK_C_SOURCE_COMPILES("
  15. +#include <execinfo.h>
  16. +int main(void) {
  17. +void *p[10];
  18. +int ret = backtrace(p, 10);
  19. +backtrace_symbols_fd(p, ret, 2);
  20. +return 0;
  21. +}" LIBC_HAS_BACKTRACE)
  22. +
  23. +IF (LIBC_HAS_BACKTRACE)
  24. + ADD_DEFINITIONS("-DLIBC_HAS_BACKTRACE")
  25. +ENDIF ()
  26. +
  27. SET(WITH_BUNDLED_SSL_DEFAULT "ON")
  28. IF ((NOT UNIX) OR CYGWIN)
  29. SET(WITH_BUNDLED_SSL_DEFAULT "OFF")
  30. --- a/src/main.c
  31. +++ b/src/main.c
  32. @@ -48,7 +48,7 @@
  33. #include <openssl/crypto.h>
  34. #include <openssl/err.h>
  35. #include <openssl/ssl.h>
  36. -#ifdef __GLIBC__
  37. +#ifdef LIBC_HAS_BACKTRACE
  38. #include <execinfo.h>
  39. #endif
  40. #if H2O_USE_PICOTLS
  41. @@ -1436,7 +1436,8 @@ static void on_sigterm(int signo)
  42. notify_all_threads();
  43. }
  44. -#ifdef __GLIBC__
  45. +#ifdef LIBC_HAS_BACKTRACE
  46. +
  47. static int popen_crash_handler(void)
  48. {
  49. char *cmd_fullpath = h2o_configurator_get_cmd_path(conf.crash_handler), *argv[] = {cmd_fullpath, NULL};
  50. @@ -1488,13 +1489,14 @@ static void on_sigfatal(int signo)
  51. raise(signo);
  52. }
  53. -#endif
  54. +
  55. +#endif /* LIBC_HAS_BACKTRACE */
  56. static void setup_signal_handlers(void)
  57. {
  58. h2o_set_signal_handler(SIGTERM, on_sigterm);
  59. h2o_set_signal_handler(SIGPIPE, SIG_IGN);
  60. -#ifdef __GLIBC__
  61. +#ifdef LIBC_HAS_BACKTRACE
  62. if ((crash_handler_fd = popen_crash_handler()) == -1)
  63. crash_handler_fd = 2;
  64. h2o_set_signal_handler(SIGABRT, on_sigfatal);