Unverified Commit 0990dec3 authored by gms's avatar gms Committed by GitHub
Browse files

Fix SENTINEL DEBUG with wrong arguments (#10258)

There are two issues in SENTINEL DEBUG:
1. The error message should mention SENTINEL DEBUG
2. Add missing reuturn in args parse.

```
redis> sentinel debug INFO-PERIOD aaa
(error) ERR Invalid argument 'aaa' for SENTINEL SET 'INFO-PERIOD'

redis> sentinel debug a b c d
(error) ERR Unknown option or number of arguments for SENTINEL SET 'a'
redis> ping
(error) ERR Unknown option or number of arguments for SENTINEL SET 'b'
```

Introduced in #9291. Also do some cleanups in the code.
parent 34c288fe
...@@ -3454,7 +3454,6 @@ void addReplySentinelRedisInstance(client *c, sentinelRedisInstance *ri) { ...@@ -3454,7 +3454,6 @@ void addReplySentinelRedisInstance(client *c, sentinelRedisInstance *ri) {
} }
void sentinelSetDebugConfigParameters(client *c){ void sentinelSetDebugConfigParameters(client *c){
int j; int j;
int badarg = 0; /* Bad argument position for error reporting. */ int badarg = 0; /* Bad argument position for error reporting. */
char *option; char *option;
...@@ -3473,7 +3472,7 @@ void sentinelSetDebugConfigParameters(client *c){ ...@@ -3473,7 +3472,7 @@ void sentinelSetDebugConfigParameters(client *c){
goto badfmt; goto badfmt;
} }
sentinel_info_period = ll; sentinel_info_period = ll;
} else if (!strcasecmp(option,"ping-period") && moreargs > 0) { } else if (!strcasecmp(option,"ping-period") && moreargs > 0) {
/* ping-period <milliseconds> */ /* ping-period <milliseconds> */
robj *o = c->argv[++j]; robj *o = c->argv[++j];
...@@ -3482,7 +3481,7 @@ void sentinelSetDebugConfigParameters(client *c){ ...@@ -3482,7 +3481,7 @@ void sentinelSetDebugConfigParameters(client *c){
goto badfmt; goto badfmt;
} }
sentinel_ping_period = ll; sentinel_ping_period = ll;
} else if (!strcasecmp(option,"ask-period") && moreargs > 0) { } else if (!strcasecmp(option,"ask-period") && moreargs > 0) {
/* ask-period <milliseconds> */ /* ask-period <milliseconds> */
robj *o = c->argv[++j]; robj *o = c->argv[++j];
...@@ -3491,7 +3490,7 @@ void sentinelSetDebugConfigParameters(client *c){ ...@@ -3491,7 +3490,7 @@ void sentinelSetDebugConfigParameters(client *c){
goto badfmt; goto badfmt;
} }
sentinel_ask_period = ll; sentinel_ask_period = ll;
} else if (!strcasecmp(option,"publish-period") && moreargs > 0) { } else if (!strcasecmp(option,"publish-period") && moreargs > 0) {
/* publish-period <milliseconds> */ /* publish-period <milliseconds> */
robj *o = c->argv[++j]; robj *o = c->argv[++j];
...@@ -3500,8 +3499,8 @@ void sentinelSetDebugConfigParameters(client *c){ ...@@ -3500,8 +3499,8 @@ void sentinelSetDebugConfigParameters(client *c){
goto badfmt; goto badfmt;
} }
sentinel_publish_period = ll; sentinel_publish_period = ll;
}else if (!strcasecmp(option,"default-down-after") && moreargs > 0) { } else if (!strcasecmp(option,"default-down-after") && moreargs > 0) {
/* default-down-after <milliseconds> */ /* default-down-after <milliseconds> */
robj *o = c->argv[++j]; robj *o = c->argv[++j];
if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) { if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) {
...@@ -3509,7 +3508,7 @@ void sentinelSetDebugConfigParameters(client *c){ ...@@ -3509,7 +3508,7 @@ void sentinelSetDebugConfigParameters(client *c){
goto badfmt; goto badfmt;
} }
sentinel_default_down_after = ll; sentinel_default_down_after = ll;
} else if (!strcasecmp(option,"tilt-trigger") && moreargs > 0) { } else if (!strcasecmp(option,"tilt-trigger") && moreargs > 0) {
/* tilt-trigger <milliseconds> */ /* tilt-trigger <milliseconds> */
robj *o = c->argv[++j]; robj *o = c->argv[++j];
...@@ -3518,7 +3517,7 @@ void sentinelSetDebugConfigParameters(client *c){ ...@@ -3518,7 +3517,7 @@ void sentinelSetDebugConfigParameters(client *c){
goto badfmt; goto badfmt;
} }
sentinel_tilt_trigger = ll; sentinel_tilt_trigger = ll;
} else if (!strcasecmp(option,"tilt-period") && moreargs > 0) { } else if (!strcasecmp(option,"tilt-period") && moreargs > 0) {
/* tilt-period <milliseconds> */ /* tilt-period <milliseconds> */
robj *o = c->argv[++j]; robj *o = c->argv[++j];
...@@ -3527,7 +3526,7 @@ void sentinelSetDebugConfigParameters(client *c){ ...@@ -3527,7 +3526,7 @@ void sentinelSetDebugConfigParameters(client *c){
goto badfmt; goto badfmt;
} }
sentinel_tilt_period = ll; sentinel_tilt_period = ll;
} else if (!strcasecmp(option,"slave-reconf-timeout") && moreargs > 0) { } else if (!strcasecmp(option,"slave-reconf-timeout") && moreargs > 0) {
/* slave-reconf-timeout <milliseconds> */ /* slave-reconf-timeout <milliseconds> */
robj *o = c->argv[++j]; robj *o = c->argv[++j];
...@@ -3536,7 +3535,7 @@ void sentinelSetDebugConfigParameters(client *c){ ...@@ -3536,7 +3535,7 @@ void sentinelSetDebugConfigParameters(client *c){
goto badfmt; goto badfmt;
} }
sentinel_slave_reconf_timeout = ll; sentinel_slave_reconf_timeout = ll;
} else if (!strcasecmp(option,"min-link-reconnect-period") && moreargs > 0) { } else if (!strcasecmp(option,"min-link-reconnect-period") && moreargs > 0) {
/* min-link-reconnect-period <milliseconds> */ /* min-link-reconnect-period <milliseconds> */
robj *o = c->argv[++j]; robj *o = c->argv[++j];
...@@ -3545,7 +3544,7 @@ void sentinelSetDebugConfigParameters(client *c){ ...@@ -3545,7 +3544,7 @@ void sentinelSetDebugConfigParameters(client *c){
goto badfmt; goto badfmt;
} }
sentinel_min_link_reconnect_period = ll; sentinel_min_link_reconnect_period = ll;
} else if (!strcasecmp(option,"default-failover-timeout") && moreargs > 0) { } else if (!strcasecmp(option,"default-failover-timeout") && moreargs > 0) {
/* default-failover-timeout <milliseconds> */ /* default-failover-timeout <milliseconds> */
robj *o = c->argv[++j]; robj *o = c->argv[++j];
...@@ -3554,7 +3553,7 @@ void sentinelSetDebugConfigParameters(client *c){ ...@@ -3554,7 +3553,7 @@ void sentinelSetDebugConfigParameters(client *c){
goto badfmt; goto badfmt;
} }
sentinel_default_failover_timeout = ll; sentinel_default_failover_timeout = ll;
} else if (!strcasecmp(option,"election-timeout") && moreargs > 0) { } else if (!strcasecmp(option,"election-timeout") && moreargs > 0) {
/* election-timeout <milliseconds> */ /* election-timeout <milliseconds> */
robj *o = c->argv[++j]; robj *o = c->argv[++j];
...@@ -3563,7 +3562,7 @@ void sentinelSetDebugConfigParameters(client *c){ ...@@ -3563,7 +3562,7 @@ void sentinelSetDebugConfigParameters(client *c){
goto badfmt; goto badfmt;
} }
sentinel_election_timeout = ll; sentinel_election_timeout = ll;
} else if (!strcasecmp(option,"script-max-runtime") && moreargs > 0) { } else if (!strcasecmp(option,"script-max-runtime") && moreargs > 0) {
/* script-max-runtime <milliseconds> */ /* script-max-runtime <milliseconds> */
robj *o = c->argv[++j]; robj *o = c->argv[++j];
...@@ -3572,7 +3571,7 @@ void sentinelSetDebugConfigParameters(client *c){ ...@@ -3572,7 +3571,7 @@ void sentinelSetDebugConfigParameters(client *c){
goto badfmt; goto badfmt;
} }
sentinel_script_max_runtime = ll; sentinel_script_max_runtime = ll;
} else if (!strcasecmp(option,"script-retry-delay") && moreargs > 0) { } else if (!strcasecmp(option,"script-retry-delay") && moreargs > 0) {
/* script-retry-delay <milliseconds> */ /* script-retry-delay <milliseconds> */
robj *o = c->argv[++j]; robj *o = c->argv[++j];
...@@ -3581,27 +3580,25 @@ void sentinelSetDebugConfigParameters(client *c){ ...@@ -3581,27 +3580,25 @@ void sentinelSetDebugConfigParameters(client *c){
goto badfmt; goto badfmt;
} }
sentinel_script_retry_delay = ll; sentinel_script_retry_delay = ll;
} else { } else {
addReplyErrorFormat(c,"Unknown option or number of arguments for " addReplyErrorFormat(c,"Unknown option or number of arguments for "
"SENTINEL SET '%s'", option); "SENTINEL DEBUG '%s'", option);
return;
} }
} }
addReply(c,shared.ok); addReply(c,shared.ok);
return; return;
badfmt: /* Bad format errors */ badfmt: /* Bad format errors */
addReplyErrorFormat(c,"Invalid argument '%s' for SENTINEL SET '%s'", addReplyErrorFormat(c,"Invalid argument '%s' for SENTINEL DEBUG '%s'",
(char*)c->argv[badarg]->ptr,option); (char*)c->argv[badarg]->ptr,option);
return; return;
} }
void addReplySentinelDebugInfo(client *c) { void addReplySentinelDebugInfo(client *c) {
void *mbl; void *mbl;
int fields = 0; int fields = 0;
...@@ -3630,7 +3627,7 @@ void addReplySentinelDebugInfo(client *c) { ...@@ -3630,7 +3627,7 @@ void addReplySentinelDebugInfo(client *c) {
addReplyBulkCString(c,"DEFAULT-FAILOVER-TIMEOUT"); addReplyBulkCString(c,"DEFAULT-FAILOVER-TIMEOUT");
addReplyBulkLongLong(c,sentinel_default_failover_timeout); addReplyBulkLongLong(c,sentinel_default_failover_timeout);
fields++; fields++;
addReplyBulkCString(c,"TILT-TRIGGER"); addReplyBulkCString(c,"TILT-TRIGGER");
addReplyBulkLongLong(c,sentinel_tilt_trigger); addReplyBulkLongLong(c,sentinel_tilt_trigger);
fields++; fields++;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment