[dovecot-cvs] dovecot/src/lib Makefile.am, 1.62.2.2, 1.62.2.3 backtrace-string.c, NONE, 1.1.2.1 backtrace-string.h, NONE, 1.1.2.1 failures.c, 1.27.2.2, 1.27.2.3
tss at dovecot.org
tss at dovecot.org
Sun Nov 19 13:30:37 UTC 2006
Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv27177/src/lib
Modified Files:
Tag: branch_1_0
Makefile.am failures.c
Added Files:
Tag: branch_1_0
backtrace-string.c backtrace-string.h
Log Message:
Since getting core dumps can be sometimes difficult, if we now do abort()
ourself, we first log the backtrace. This works at least with Linux and
Solaris.
Index: Makefile.am
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/Makefile.am,v
retrieving revision 1.62.2.2
retrieving revision 1.62.2.3
diff -u -d -r1.62.2.2 -r1.62.2.3
--- Makefile.am 16 Aug 2006 15:54:56 -0000 1.62.2.2
+++ Makefile.am 19 Nov 2006 13:30:35 -0000 1.62.2.3
@@ -1,6 +1,7 @@
noinst_LIBRARIES = liblib.a
liblib_a_SOURCES = \
+ backtrace-string.c \
base64.c \
bsearch-insert-pos.c \
buffer.c \
@@ -87,6 +88,7 @@
noinst_HEADERS = \
array.h \
array-decl.h \
+ backtrace-string.h \
base64.h \
bsearch-insert-pos.h \
buffer.h \
--- NEW FILE: backtrace-string.c ---
/* Copyright (c) 2006 Timo Sirainen */
#include "lib.h"
#include "str.h"
#include "backtrace-string.h"
#define MAX_STACK_SIZE 30
#define STACK_SKIP_COUNT 2
#if defined(HAVE_BACKTRACE_SYMBOLS) && defined(HAVE_EXECINFO_H)
/* Linux */
#include <execinfo.h>
#include <stdlib.h>
int backtrace_append(string_t *str)
{
void *stack[MAX_STACK_SIZE];
char **strings;
int ret, i;
ret = backtrace(stack, sizeof(stack)/sizeof(stack[0]));
if (ret <= STACK_SKIP_COUNT)
return -1;
strings = backtrace_symbols(stack, ret);
for (i = STACK_SKIP_COUNT; i < ret; i++) {
if (i > STACK_SKIP_COUNT)
str_append(str, " -> ");
str_append(str, strings[i]);
}
free(strings);
return 0;
}
#elif defined(HAVE_WALKCONTEXT) && defined(HAVE_UCONTEXT_H)
/* Solaris */
#include <ucontext.h>
struct walk_context {
string_t *str;
unsigned int pos;
};
static int walk_callback(uintptr_t ptr, int signo __attr_unused__,
void *context)
{
struct walk_context *ctx = context;
if (ctx->pos >= STACK_SKIP_COUNT) {
if (ctx->pos > STACK_SKIP_COUNT)
str_append(ctx->str, " -> ");
str_printfa(ctx->str, "0x%p", (void *)ptr);
}
ctx->pos++;
return 0;
}
int backtrace_append(string_t *str)
{
ucontext_t uc;
struct walk_context ctx;
if (getcontext(&uc) < 0)
return -1;
ctx.str = str;
ctx.pos = 0;
walkcontext(&uc, walk_callback, &ctx);
return 0;
}
#else
int backtrace_append(string_t *str __attr_unused__)
{
return -1;
}
#endif
int backtrace_get(const char **backtrace_r)
{
string_t *str;
str = t_str_new(512);
if (backtrace_append(str) < 0)
return -1;
*backtrace_r = str_c(str);
return 0;
}
--- NEW FILE: backtrace-string.h ---
#ifndef __BACKTRACE_STRING_H
#define __BACKTRACE_STRING_H
/* Returns 0 if ok, -1 if failure. */
int backtrace_append(string_t *str);
int backtrace_get(const char **backtrace_r);
#endif
Index: failures.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/failures.c,v
retrieving revision 1.27.2.2
retrieving revision 1.27.2.3
diff -u -d -r1.27.2.2 -r1.27.2.3
--- failures.c 1 Nov 2006 18:50:14 -0000 1.27.2.2
+++ failures.c 19 Nov 2006 13:30:35 -0000 1.27.2.3
@@ -2,6 +2,7 @@
#include "lib.h"
#include "str.h"
+#include "backtrace-string.h"
#include "write-full.h"
#include "fd-close-on-exec.h"
#include "printf-upper-bound.h"
@@ -119,7 +120,11 @@
static void default_panic_handler(const char *format, va_list args)
{
+ const char *backtrace;
+
(void)default_handler("Panic: ", log_fd, format, args);
+ if (backtrace_get(&backtrace) == 0)
+ i_error("Backtrace: %s", backtrace);
abort();
}
@@ -284,8 +289,12 @@
void i_syslog_panic_handler(const char *fmt, va_list args)
{
+ const char *backtrace;
+
(void)syslog_handler(LOG_CRIT, fmt, args);
- abort();
+ if (backtrace_get(&backtrace) == 0)
+ i_error("Backtrace: %s", backtrace);
+ abort();
}
void i_syslog_fatal_handler(int status, const char *fmt, va_list args)
@@ -378,7 +387,11 @@
__attr_noreturn__;
static void i_internal_panic_handler(const char *fmt, va_list args)
{
+ const char *backtrace;
+
(void)internal_handler('F', fmt, args);
+ if (backtrace_get(&backtrace) == 0)
+ i_error("Backtrace: %s", backtrace);
abort();
}
More information about the dovecot-cvs
mailing list