From 16e04ed9442ed31ab2ec01035047e8118c7511a5 Mon Sep 17 00:00:00 2001 From: Wang Yuan Date: Thu, 1 Jul 2021 13:05:18 +0800 Subject: [PATCH] Don't start in sentinel mode if only the folder name contains redis-sentinel (#9176) Before this commit, redis-server starts in sentinel mode if the first startup argument has the string redis-sentinel, so redis also starts in sentinel mode if the directory it was started from contains the string redis-sentinel. Now we check the executable name instead of directory. Some examples: 1. Execute ./redis-sentinel/redis/src/redis-sentinel, starts in sentinel mode. 2. Execute ./redis-sentinel/redis/src/redis-server, starts in server mode, but before, redis will start in sentinel mode. 3. Execute ./redis-sentinel/redis/src/redis-server --sentinel, of course, like before, starts in sentinel mode. --- src/server.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/server.c b/src/server.c index c19df1837..e73235747 100644 --- a/src/server.c +++ b/src/server.c @@ -5885,12 +5885,13 @@ void sendChildInfo(childInfoType info_type, size_t keys, char *pname) { void memtest(size_t megabytes, int passes); /* Returns 1 if there is --sentinel among the arguments or if - * argv[0] contains "redis-sentinel". */ + * executable name contains "redis-sentinel". */ int checkForSentinelMode(int argc, char **argv) { - int j; + char *exec_name = strrchr(argv[0], '/'); + if (exec_name == NULL) exec_name = argv[0]; + if (strstr(exec_name,"redis-sentinel") != NULL) return 1; - if (strstr(argv[0],"redis-sentinel") != NULL) return 1; - for (j = 1; j < argc; j++) + for (int j = 1; j < argc; j++) if (!strcmp(argv[j],"--sentinel")) return 1; return 0; }