Merge pull request #8503 from opensourcerouting/one-backtrace-is-enough

lib: 640k backtraces should be enough for everybody
This commit is contained in:
Donald Sharp 2021-04-20 06:11:13 -04:00 committed by GitHub
commit 117d216ba0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View File

@ -237,9 +237,12 @@ core_handler(int signo, siginfo_t *siginfo, void *context)
/* make sure we don't hang in here. default for SIGALRM is terminate.
* - if we're in backtrace for more than a second, abort. */
struct sigaction sa_default = {.sa_handler = SIG_DFL};
sigaction(SIGALRM, &sa_default, NULL);
sigaction(signo, &sa_default, NULL);
sigset_t sigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGALRM);
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
@ -252,7 +255,16 @@ core_handler(int signo, siginfo_t *siginfo, void *context)
log_memstats(stderr, "core_handler");
zlog_tls_buffer_fini();
abort();
/* give the kernel a chance to generate a coredump */
sigaddset(&sigset, signo);
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
raise(signo);
/* only chance to end up here is if the default action for signo is
* something other than kill or coredump the process
*/
_exit(128 + signo);
}
static void trap_default_signals(void)

View File

@ -142,6 +142,7 @@ struct zlog_msg {
struct zlog_tls {
char *mmbuf;
size_t bufpos;
bool do_unlink;
size_t nmsgs;
struct zlog_msg msgs[TLS_LOG_MAXMSG];
@ -266,13 +267,14 @@ void zlog_tls_buffer_init(void)
mmpath, strerror(errno));
goto out_anon_unlink;
}
zlog_tls->do_unlink = true;
close(mmfd);
zlog_tls_set(zlog_tls);
return;
out_anon_unlink:
unlink(mmpath);
unlinkat(zlog_tmpdirfd, mmpath, 0);
close(mmfd);
out_anon:
@ -296,14 +298,16 @@ out_anon:
void zlog_tls_buffer_fini(void)
{
char mmpath[MAXPATHLEN];
struct zlog_tls *zlog_tls = zlog_tls_get();
bool do_unlink = zlog_tls ? zlog_tls->do_unlink : false;
zlog_tls_buffer_flush();
zlog_tls_free(zlog_tls_get());
zlog_tls_free(zlog_tls);
zlog_tls_set(NULL);
snprintfrr(mmpath, sizeof(mmpath), "logbuf.%ld", zlog_gettid());
if (unlinkat(zlog_tmpdirfd, mmpath, 0))
if (do_unlink && unlinkat(zlog_tmpdirfd, mmpath, 0))
zlog_err("unlink logbuf: %s (%d)", strerror(errno), errno);
}