From 8f13ac10b46de0c6f3cb9fd5c9e86824aa1e8355 Mon Sep 17 00:00:00 2001 From: Binbin Date: Tue, 6 Dec 2022 17:12:51 +0800 Subject: [PATCH] Fix command line startup --sentinel problem (#11591) There is a issue with --sentinel: ``` [root]# src/redis-server sentinel.conf --sentinel --loglevel verbose *** FATAL CONFIG FILE ERROR (Redis 255.255.255) *** Reading the configuration file, at line 352 >>> 'sentinel "--loglevel" "verbose"' Unrecognized sentinel configuration statement ``` This is because in #10660 (Redis 7.0.1), `--` prefix change break it. In this PR, we will handle `--sentinel` the same as we did for `--save` in #10866. i.e. it's a pseudo config option with no value. --- src/server.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/server.c b/src/server.c index 52ce3d4d7..7bc320795 100644 --- a/src/server.c +++ b/src/server.c @@ -7024,6 +7024,24 @@ int main(int argc, char **argv) { * so it will become `--save ""` and will follow the same reset thing. */ options = sdscat(options, "\"\""); } + else if ((j != argc-1) && argv[j+1][0] == '-' && argv[j+1][1] == '-' && + !strcasecmp(argv[j], "--sentinel")) + { + /* Special case: handle some things like `--sentinel --config value`. + * It is a pseudo config option with no value. In this case, if next + * argument starts with `--`, we will reset handled_last_config_arg flag. + * We are doing it to be compatible with pre 7.0 behavior (which we + * break it in #10660, 7.0.1). */ + options = sdscat(options, ""); + handled_last_config_arg = 1; + } + else if ((j == argc-1) && !strcasecmp(argv[j], "--sentinel")) { + /* Special case: when --sentinel is the last argument. + * It is a pseudo config option with no value. In this case, do nothing. + * We are doing it to be compatible with pre 7.0 behavior (which we + * break it in #10660, 7.0.1). */ + options = sdscat(options, ""); + } } else { /* Means that we are passing both config name and it's value in the same arg, * like "--port 6380", so we need to reset handled_last_config_arg flag. */