From dc26522a27f76cdb7ddb4fb765bd8895d20e40f9 Mon Sep 17 00:00:00 2001
From: Georgios Bitzes <georgios.bitzes@cern.ch>
Date: Wed, 19 Oct 2016 19:05:14 +0200
Subject: [PATCH] Add support for 'DEBUG SEGFAULT'

---
 src/Commands.cc   | 1 +
 src/Commands.hh   | 2 ++
 src/Dispatcher.cc | 8 ++++++++
 3 files changed, 11 insertions(+)

diff --git a/src/Commands.cc b/src/Commands.cc
index 7db76972..b07fe129 100644
--- a/src/Commands.cc
+++ b/src/Commands.cc
@@ -32,6 +32,7 @@ std::map<std::string,
 struct cmdMapInit {
   cmdMapInit() {
     redis_cmd_map["ping"] = {RedisCommand::PING, CommandType::CONTROL};
+    redis_cmd_map["debug"] = {RedisCommand::DEBUG, CommandType::CONTROL};
 
     redis_cmd_map["get"] = {RedisCommand::GET, CommandType::READ};
     redis_cmd_map["exists"] = {RedisCommand::EXISTS, CommandType::READ};
diff --git a/src/Commands.hh b/src/Commands.hh
index f2a0e363..16893769 100644
--- a/src/Commands.hh
+++ b/src/Commands.hh
@@ -30,6 +30,8 @@ namespace quarkdb {
 
 enum class RedisCommand {
   PING,
+  DEBUG,
+
   FLUSHALL,
 
   GET,
diff --git a/src/Dispatcher.cc b/src/Dispatcher.cc
index 9675f18b..a4fb6e50 100644
--- a/src/Dispatcher.cc
+++ b/src/Dispatcher.cc
@@ -45,6 +45,14 @@ LinkStatus RedisDispatcher::dispatch(Connection *conn, RedisRequest &request, Re
 
       return conn->string(request[1]);
     }
+    case RedisCommand::DEBUG: {
+      if(request.size() != 2) return conn->errArgs(request[0]);
+      if(request[1] == "segfault" || request[1] == "SEGFAULT") {
+        *( (int*) nullptr) = 5; // bye bye
+      }
+
+      return conn->err(SSTR("unknown argument '" << request[1] << "'"));
+    }
     case RedisCommand::FLUSHALL: {
       if(request.size() != 1) return conn->errArgs(request[0]);
       rocksdb::Status st = store.flushall();
-- 
GitLab