summaryrefslogtreecommitdiff
path: root/lib/log.c
diff options
context:
space:
mode:
authorPaul Jakma <paul.jakma@sun.com>2006-05-28 08:26:15 +0000
committerPaul Jakma <paul.jakma@sun.com>2006-05-28 08:26:15 +0000
commitfb66b29c6701129f0222275eaa206f7ac8ab30cc (patch)
treeb9a3d53d867ead2e9f8dbb8c1add9c2eb63b1943 /lib/log.c
parenta4b303038363185f60dfef7023cb02715a9a4315 (diff)
[lib] Add support for Sun libc printstack to zlog_backtrace_sigsafe
2006-05-28 Paul Jakma <paul.jakma@sun.com> * configure.ac: Check for Sun libc printstack(), add a general HAVE_STACK_TRACE define for lib/log.c, if any supported stack symbol dumping function is found (glibc backtrace/sun libc printstack). * log.c: (general) Add support for Sun libc printstack(). (hex_append) make the cpp conditional on general HAVE_STACK_TRACE define. (zlog_backtrace_sigsafe) Ditto. Add printstack() version of the the DUMP macro in this function.
Diffstat (limited to 'lib/log.c')
-rw-r--r--lib/log.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/lib/log.c b/lib/log.c
index d55ffb7f..3eb0bd52 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -1,5 +1,5 @@
/*
- * $Id: log.c,v 1.27 2006/05/15 16:56:51 paul Exp $
+ * $Id$
*
* Logging of zebra
* Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro
@@ -179,7 +179,7 @@ num_append(char *s, int len, u_long x)
return str_append(s,len,t);
}
-#if defined(SA_SIGINFO) || defined(HAVE_GLIBC_BACKTRACE)
+#if defined(SA_SIGINFO) || defined(HAVE_STACK_TRACE)
static char *
hex_append(char *s, int len, u_long x)
{
@@ -371,7 +371,7 @@ zlog_signal(int signo, const char *action
void
zlog_backtrace_sigsafe(int priority, void *program_counter)
{
-#ifdef HAVE_GLIBC_BACKTRACE
+#ifdef HAVE_STACK_TRACE
static const char pclabel[] = "Program counter: ";
void *array[20];
int size;
@@ -379,13 +379,10 @@ zlog_backtrace_sigsafe(int priority, void *program_counter)
char *s;
#define LOC s,buf+sizeof(buf)-s
+#ifdef HAVE_GLIBC_BACKTRACE
if (((size = backtrace(array,sizeof(array)/sizeof(array[0]))) <= 0) ||
((size_t)size > sizeof(array)/sizeof(array[0])))
return;
- s = buf;
- s = str_append(LOC,"Backtrace for ");
- s = num_append(LOC,size);
- s = str_append(LOC," stack frames:\n");
#define DUMP(FD) { \
if (program_counter) \
@@ -396,6 +393,19 @@ zlog_backtrace_sigsafe(int priority, void *program_counter)
write(FD, buf, s-buf); \
backtrace_symbols_fd(array, size, FD); \
}
+#elif defined(HAVE_PRINTSTACK)
+#define DUMP(FD) { \
+ if (program_counter) \
+ write((FD), pclabel, sizeof(pclabel)-1); \
+ write((FD), buf, s-buf); \
+ printstack((FD)); \
+}
+#endif /* HAVE_GLIBC_BACKTRACE, HAVE_PRINTSTACK */
+
+ s = buf;
+ s = str_append(LOC,"Backtrace for ");
+ s = num_append(LOC,size);
+ s = str_append(LOC," stack frames:\n");
if ((logfile_fd >= 0) || ((logfile_fd = open_crashlog()) >= 0))
DUMP(logfile_fd)
@@ -431,7 +441,7 @@ zlog_backtrace_sigsafe(int priority, void *program_counter)
}
#undef DUMP
#undef LOC
-#endif /* HAVE_GLIBC_BACKTRACE */
+#endif /* HAVE_STRACK_TRACE */
}
void