summaryrefslogtreecommitdiff
path: root/src/debug.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2017-01-18 17:05:10 +0100
committerantirez <antirez@gmail.com>2017-01-18 17:05:10 +0100
commit53b8bf2c89ac9607a8bede2868d60cf8b3cbddd6 (patch)
tree80e87c9ab2346583fd36a5ecc8c2eecba5e69eda /src/debug.c
parent2cd1ae736f7ace5d0620937e4783fd85e9ca7448 (diff)
downloadredis-53b8bf2c89ac9607a8bede2868d60cf8b3cbddd6.tar.gz
serverPanic(): allow printf() alike formatting.
This is of great interest because allows us to print debugging informations that could be of useful when debugging, like in the following example: serverPanic("Unexpected encoding for object %d, %d", obj->type, obj->encoding);
Diffstat (limited to 'src/debug.c')
-rw-r--r--src/debug.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/debug.c b/src/debug.c
index 0026594d3..a3190f636 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -266,6 +266,8 @@ void debugCommand(client *c) {
blen++; addReplyStatus(c,
"segfault -- Crash the server with sigsegv.");
blen++; addReplyStatus(c,
+ "panic -- Crash the server simulating a panic.");
+ blen++; addReplyStatus(c,
"restart -- Graceful restart: save config, db, restart.");
blen++; addReplyStatus(c,
"crash-and-recovery <milliseconds> -- Hard crash and restart after <milliseconds> delay.");
@@ -300,6 +302,8 @@ void debugCommand(client *c) {
setDeferredMultiBulkLength(c,blenp,blen);
} else if (!strcasecmp(c->argv[1]->ptr,"segfault")) {
*((char*)-1) = 'x';
+ } else if (!strcasecmp(c->argv[1]->ptr,"panic")) {
+ serverPanic("DEBUG PANIC called at Unix time %ld", time(NULL));
} else if (!strcasecmp(c->argv[1]->ptr,"restart") ||
!strcasecmp(c->argv[1]->ptr,"crash-and-recover"))
{
@@ -615,11 +619,17 @@ void _serverAssertWithInfo(const client *c, const robj *o, const char *estr, con
_serverAssert(estr,file,line);
}
-void _serverPanic(const char *msg, const char *file, int line) {
+void _serverPanic(const char *file, int line, const char *msg, ...) {
+ va_list ap;
+ va_start(ap,msg);
+ char fmtmsg[256];
+ vsnprintf(fmtmsg,sizeof(fmtmsg),msg,ap);
+ va_end(ap);
+
bugReportStart();
serverLog(LL_WARNING,"------------------------------------------------");
serverLog(LL_WARNING,"!!! Software Failure. Press left mouse button to continue");
- serverLog(LL_WARNING,"Guru Meditation: %s #%s:%d",msg,file,line);
+ serverLog(LL_WARNING,"Guru Meditation: %s #%s:%d",fmtmsg,file,line);
#ifdef HAVE_BACKTRACE
serverLog(LL_WARNING,"(forcing SIGSEGV in order to print the stack trace)");
#endif