Skip to content

Instantly share code, notes, and snippets.

@noahd1
Created March 1, 2010 02:53
Show Gist options
  • Save noahd1/318038 to your computer and use it in GitHub Desktop.
Save noahd1/318038 to your computer and use it in GitHub Desktop.
static void segvHandler(int sig, siginfo_t *info, void *secret) {
void *trace[100];
char **messages = NULL;
int i, trace_size = 0;
unsigned long offset=0;
ucontext_t *uc = (ucontext_t*) secret;
sds infostring;
REDIS_NOTUSED(info);
redisLog(REDIS_WARNING,
"======= Ooops! Redis %s got signal: -%d- =======", REDIS_VERSION, sig);
infostring = genRedisInfoString();
redisLog(REDIS_WARNING, "%s",infostring);
/* It's not safe to sdsfree() the returned string under memory
* corruption conditions. Let it leak as we are going to abort */
trace_size = backtrace(trace, 100);
/* overwrite sigaction with caller's address */
if (getMcontextEip(uc) != NULL) {
trace[1] = getMcontextEip(uc);
}
messages = backtrace_symbols(trace, trace_size);
for (i=1; i<trace_size; ++i) {
char *fn = findFuncName(trace[i], &offset), *p;
p = strchr(messages[i],'+');
if (!fn || (p && ((unsigned long)strtol(p+1,NULL,10)) < offset)) {
redisLog(REDIS_WARNING,"%s", messages[i]);
} else {
redisLog(REDIS_WARNING,"%d redis-server %p %s + %d", i, trace[i], fn, (unsigned int)offset);
}
}
/* free(messages); Don't call free() with possibly corrupted memory. */
_exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment