Skip to content

Commit

Permalink
print caught signal desc in verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPulec committed Oct 26, 2023
1 parent b6bf6b6 commit 06956f0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,18 +1048,10 @@ void crash_signal_handler(int sig)
array<void *, 256> 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");
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
26 changes: 26 additions & 0 deletions src/utils/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
#include "config_win32.h"
#endif

#ifndef __APPLE__
#include <signal.h>
#endif
#include <string.h>

#include "debug.h"
Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions src/utils/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 06956f0

Please sign in to comment.