summaryrefslogtreecommitdiffstats
path: root/lib/log.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2013-11-18 23:52:02 +0100
committerDavid Lamparter <equinox@opensourcerouting.org>2014-09-15 18:38:56 +0200
commit615f9f18fc025757a255f936748fc1e86e922783 (patch)
treeb9cd79ef71984932f4eb5f73437f9593ad2a2604 /lib/log.c
parent3493b7731b750cbc62f00be94b624a08ccccf0b2 (diff)
downloadquagga-615f9f18fc025757a255f936748fc1e86e922783.tar.bz2
quagga-615f9f18fc025757a255f936748fc1e86e922783.tar.xz
lib: include thread information in backtraces
now that we know what thread we're currently executing, let's add that information to SEGV / assert backtraces. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/log.c')
-rw-r--r--lib/log.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/log.c b/lib/log.c
index 1058844b..04f8fab6 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -425,6 +425,40 @@ zlog_signal(int signo, const char *action
NULL
#endif
);
+
+ s = buf;
+ if (!thread_current)
+ s = str_append (LOC, "no thread information available\n");
+ else
+ {
+ s = str_append (LOC, "in thread ");
+ s = str_append (LOC, thread_current->funcname);
+ s = str_append (LOC, " scheduled from ");
+ s = str_append (LOC, thread_current->schedfrom);
+ s = str_append (LOC, ":");
+ s = num_append (LOC, thread_current->schedfrom_line);
+ s = str_append (LOC, "\n");
+ }
+
+#define DUMP(FD) write(FD, buf, s-buf);
+ /* If no file logging configured, try to write to fallback log file. */
+ if (logfile_fd >= 0)
+ DUMP(logfile_fd)
+ if (!zlog_default)
+ DUMP(STDERR_FILENO)
+ else
+ {
+ if (PRI <= zlog_default->maxlvl[ZLOG_DEST_STDOUT])
+ DUMP(STDOUT_FILENO)
+ /* Remove trailing '\n' for monitor and syslog */
+ *--s = '\0';
+ if (PRI <= zlog_default->maxlvl[ZLOG_DEST_MONITOR])
+ vty_log_fixed(buf,s-buf);
+ if (PRI <= zlog_default->maxlvl[ZLOG_DEST_SYSLOG])
+ syslog_sigsafe(PRI|zlog_default->facility,msgstart,s-msgstart);
+ }
+#undef DUMP
+
#undef PRI
#undef LOC
}
@@ -604,6 +638,16 @@ PLOG_FUNC(plog_debug, LOG_DEBUG)
#undef PLOG_FUNC
+void zlog_thread_info (int log_level)
+{
+ if (thread_current)
+ zlog(NULL, log_level, "Current thread function %s, scheduled from "
+ "file %s, line %u", thread_current->funcname,
+ thread_current->schedfrom, thread_current->schedfrom_line);
+ else
+ zlog(NULL, log_level, "Current thread not known/applicable");
+}
+
void
_zlog_assert_failed (const char *assertion, const char *file,
unsigned int line, const char *function)
@@ -616,6 +660,7 @@ _zlog_assert_failed (const char *assertion, const char *file,
zlog(NULL, LOG_CRIT, "Assertion `%s' failed in file %s, line %u, function %s",
assertion,file,line,(function ? function : "?"));
zlog_backtrace(LOG_CRIT);
+ zlog_thread_info(LOG_CRIT);
abort();
}