summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Stancliff <matt@genges.com>2014-08-25 15:53:11 -0500
committerMatt Stancliff <matt@genges.com>2014-12-11 10:49:16 -0500
commit391fc9b6335329e513664c69bdc18865ab944beb (patch)
tree0825db8e468f48811d9fab7078508a72fa17b8ee
parent3cd36a4dd9b31b351c87f1084bc6166a44044315 (diff)
downloadredis-391fc9b6335329e513664c69bdc18865ab944beb.tar.gz
Sentinel: Improve INFO command behavior
Improvements: - Return empty string if asking for non-existing section (INFO foo) - Fix potential memory leak (caused by sdsempty() then returned if >2 args) - Clean up argument parsing - Allow "all" as valid section (same as "default" or zero args currently) - Move strcasecmp to end of evaluation chain in conditionals Also, since we're C99, I moved some variable declarations to be closer to where they are actually used (saves us from needing to free an empty info if detect argument errors up front). Closes #1915 Closes #1966
-rw-r--r--src/sentinel.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/sentinel.c b/src/sentinel.c
index 12f15ff3e..bd2d42ac2 100644
--- a/src/sentinel.c
+++ b/src/sentinel.c
@@ -2853,24 +2853,30 @@ numargserr:
/* SENTINEL INFO [section] */
void sentinelInfoCommand(redisClient *c) {
- char *section = c->argc == 2 ? c->argv[1]->ptr : "default";
- sds info = sdsempty();
- int defsections = !strcasecmp(section,"default");
- int sections = 0;
-
if (c->argc > 2) {
addReply(c,shared.syntaxerr);
return;
}
- if (!strcasecmp(section,"server") || defsections) {
+ int defsections = 0, allsections = 0;
+ char *section = c->argc == 2 ? c->argv[1]->ptr : NULL;
+ if (section) {
+ allsections = !strcasecmp(section,"all");
+ defsections = !strcasecmp(section,"default");
+ } else {
+ defsections = 1;
+ }
+
+ int sections = 0;
+ sds info = sdsempty();
+ if (defsections || allsections || !strcasecmp(section,"server")) {
if (sections++) info = sdscat(info,"\r\n");
sds serversection = genRedisInfoString("server");
info = sdscatlen(info,serversection,sdslen(serversection));
sdsfree(serversection);
}
- if (!strcasecmp(section,"sentinel") || defsections) {
+ if (defsections || allsections || !strcasecmp(section,"sentinel")) {
dictIterator *di;
dictEntry *de;
int master_id = 0;