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.
This commit is contained in:
Wang Yuan 2021-07-01 13:05:18 +08:00 committed by GitHub
parent 6476c8e856
commit 16e04ed944
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -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;
}