From 188e7a5693386f47a7c462bffe6d9f5ed8090b9e Mon Sep 17 00:00:00 2001 From: Kajaruban Surendran Date: Fri, 27 Nov 2020 21:42:08 +0000 Subject: [PATCH] Configurable option for MOTD Former-commit-id: 49a89d636ba698dbd0858d5059d3d6387c8c1fc7 --- keydb.conf | 3 +++ src/config.cpp | 1 + src/motd.cpp | 10 +++++++--- src/motd.h | 5 ++--- src/redis-cli.c | 3 ++- src/server.cpp | 2 +- src/server.h | 1 + tests/unit/introspection.tcl | 1 + 8 files changed, 18 insertions(+), 8 deletions(-) diff --git a/keydb.conf b/keydb.conf index 9015dd84a..349135f93 100644 --- a/keydb.conf +++ b/keydb.conf @@ -282,6 +282,9 @@ databases 16 # ASCII art logo in startup logs by setting the following option to yes. always-show-logo yes +# Retrieving "message of today" using CURL requests. +#enable-motd yes + ################################ SNAPSHOTTING ################################ # # Save the DB on disk: diff --git a/src/config.cpp b/src/config.cpp index bbc9cb68a..9aa1e0990 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -2344,6 +2344,7 @@ standardConfig configs[] = { createBoolConfig("daemonize", NULL, IMMUTABLE_CONFIG, cserver.daemonize, 0, NULL, NULL), createBoolConfig("lua-replicate-commands", NULL, MODIFIABLE_CONFIG, g_pserver->lua_always_replicate_commands, 1, NULL, NULL), createBoolConfig("always-show-logo", NULL, IMMUTABLE_CONFIG, g_pserver->always_show_logo, 0, NULL, NULL), + createBoolConfig("enable-motd", NULL, IMMUTABLE_CONFIG, cserver.enable_motd, 1, NULL, NULL), createBoolConfig("protected-mode", NULL, MODIFIABLE_CONFIG, g_pserver->protected_mode, 1, NULL, NULL), createBoolConfig("rdbcompression", NULL, MODIFIABLE_CONFIG, g_pserver->rdb_compression, 1, NULL, NULL), createBoolConfig("rdb-del-sync-files", NULL, MODIFIABLE_CONFIG, g_pserver->rdb_del_sync_files, 0, NULL, NULL), diff --git a/src/motd.cpp b/src/motd.cpp index 2fbef9526..e2f55673d 100644 --- a/src/motd.cpp +++ b/src/motd.cpp @@ -71,12 +71,16 @@ static void setMOTDCache(const char *sz) fclose(pf); } -extern "C" char *fetchMOTD(int cache) +extern "C" char *fetchMOTD(int cache, int enable_motd) { sds str; CURL *curl; CURLcode res; + /* Do not try the CURL if the motd is disabled*/ + if (!enable_motd) { + return NULL; + } /* First try and get the string from the cache */ if (cache) { str = fetchMOTDFromCache(); @@ -124,9 +128,9 @@ extern "C" char *fetchMOTD(int cache) #else -extern "C" char *fetchMOTD(int /* cache */) +extern "C" char *fetchMOTD(int /* cache */, int /* enable_motd */) { return NULL; } -#endif \ No newline at end of file +#endif diff --git a/src/motd.h b/src/motd.h index c57e63726..b6a91477b 100644 --- a/src/motd.h +++ b/src/motd.h @@ -6,9 +6,8 @@ extern const char *motd_cache_file; #ifdef __cplusplus extern "C" { #endif - -char *fetchMOTD(int fCache); +char *fetchMOTD(int fCache, int enable_motd); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/src/redis-cli.c b/src/redis-cli.c index 412760278..41242b313 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -7113,7 +7113,8 @@ int main(int argc, char **argv) { if (argc == 0 && !config.eval) { /* Show the message of the day if we are interactive */ if (config.output == OUTPUT_STANDARD && !config.disable_motd) { - char *szMotd = fetchMOTD(1 /* cache */); + /*enable_motd=1 will retrieve the message of today using CURL*/ + char *szMotd = fetchMOTD(1 /* cache */, 1 /* enable_motd */); if (szMotd != NULL) { printf("Message of the day:\n %s\n", szMotd); sdsfree(szMotd); diff --git a/src/server.cpp b/src/server.cpp index 277c9e39a..92241f02b 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -5136,7 +5136,7 @@ void redisAsciiArt(void) { mode, g_pserver->port ? g_pserver->port : g_pserver->tls_port ); } else { - sds motd = fetchMOTD(true); + sds motd = fetchMOTD(true, cserver.enable_motd); snprintf(buf,1024*16,ascii_logo, KEYDB_REAL_VERSION, redisGitSHA1(), diff --git a/src/server.h b/src/server.h index 0fc874b6a..32581fb00 100644 --- a/src/server.h +++ b/src/server.h @@ -1456,6 +1456,7 @@ struct redisServerConst { bool fUsePro = false; int thread_min_client_threshold = 50; int multimaster_no_forward; + int enable_motd; /* Flag to retrieve the Message of today using CURL request*/ }; struct redisServer { diff --git a/tests/unit/introspection.tcl b/tests/unit/introspection.tcl index ffad7405f..55f224e32 100644 --- a/tests/unit/introspection.tcl +++ b/tests/unit/introspection.tcl @@ -67,6 +67,7 @@ start_server {tags {"introspection"}} { io-threads-do-reads tcp-backlog always-show-logo + enable-motd syslog-enabled cluster-enabled aclfile