diff --git a/src/host.cpp b/src/host.cpp index b5d6dc38a..23b99b41d 100644 --- a/src/host.cpp +++ b/src/host.cpp @@ -1048,18 +1048,10 @@ void crash_signal_handler(int sig) array addresses{}; int num_symbols = backtrace(addresses.data(), addresses.size()); backtrace_symbols_fd(addresses.data(), num_symbols, 2); +#endif // defined WIN32 + + append_sig_desc(&ptr, ptr_end, sig); -#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 32) - const char *sig_desc = sigdescr_np(sig); -#else - const char *sig_desc = sys_siglist[sig]; -#endif - if (sig_desc != NULL) { - strappend(&ptr, ptr_end, " ("); - strappend(&ptr, ptr_end, sig_desc); - strappend(&ptr, ptr_end, ")"); - } -#endif strappend(&ptr, ptr_end, ".\n\nPlease send a bug report to address " PACKAGE_BUGREPORT ".\n"); strappend(&ptr, ptr_end, "You may find some tips how to report bugs in file doc/REPORTING_BUGS.md distributed with " PACKAGE_NAME "\n"); strappend(&ptr, ptr_end, "(or available online at https://github.com/CESNET/UltraGrid/blob/master/doc/REPORTING-BUGS.md).\n"); diff --git a/src/main.cpp b/src/main.cpp index 6c0cbc63a..b7fa3b53e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -190,6 +190,7 @@ static void signal_handler(int signum) *ptr++ = (char) ('0' + signum / 10); } *ptr++ = (char) ('0' + signum % 10); + append_sig_desc(&ptr, ptr_end - 1, signum); *ptr++ = '\n'; write_all(ptr - buf, buf); } diff --git a/src/utils/string.c b/src/utils/string.c index a396513d3..b2de4b186 100644 --- a/src/utils/string.c +++ b/src/utils/string.c @@ -41,6 +41,9 @@ #include "config_win32.h" #endif +#ifndef __APPLE__ +#include +#endif #include #include "debug.h" @@ -137,3 +140,26 @@ void write_all(size_t len, const char *msg) { } while (len > 0); } +/** + * Appends signal number description to ptr and moves ptr to end of the + * appended string. The string is not NULL-terminated. + * + * This function is async-signal-safe. + */ +void +append_sig_desc(char **ptr, const char *ptr_end, int signum) +{ +#ifdef _WIN32 + (void) ptr, (void) ptr_end, (void) signum; +#else + strappend(ptr, ptr_end, " ("); +#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 32) + strappend(ptr, ptr_end, sigabbrev_np(signum)); + strappend(ptr, ptr_end, " - "); + strappend(ptr, ptr_end, sigdescr_np(signum)); +#else + strappend(ptr, ptr_end, sys_siglist[signum]); +#endif + strappend(ptr, ptr_end, ")"); +#endif // !defined _WIN32 +} diff --git a/src/utils/string.h b/src/utils/string.h index 770c7d024..577db499c 100644 --- a/src/utils/string.h +++ b/src/utils/string.h @@ -55,6 +55,7 @@ bool is_prefix_of(const char *haystack, const char *needle); /// same as strpbrk but finds in a reverse order (last occurence returned) char *strrpbrk(char *s, const char *accept); void strappend(char **ptr, const char *ptr_end, const char *src); +void append_sig_desc(char **ptr, const char *ptr_end, int signum); void write_all(size_t len, const char *msg); #ifdef __cplusplus