diff --git a/.gitignore b/.gitignore index cdab2150e..3d346fbcf 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ dump.rdb redis-benchmark redis-check-aof redis-check-rdb +redis-check-dump redis-cli redis-sentinel redis-server diff --git a/src/redis-check-rdb.c b/src/redis-check-rdb.c index ff87f142f..21f72c222 100644 --- a/src/redis-check-rdb.c +++ b/src/redis-check-rdb.c @@ -696,3 +696,15 @@ int redis_check_rdb(char *rdbfilename) { close(fd); return 0; } + +/* RDB check main: called form redis.c when Redis is executed with the + * redis-check-rdb alias. */ +int redis_check_rdb_main(char **argv, int argc) { + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + redisLog(REDIS_WARNING, "Checking RDB file %s", argv[1]); + exit(redis_check_rdb(argv[1])); + return 0; +} diff --git a/src/redis.c b/src/redis.c index 24739cc3c..b2f9ffc68 100644 --- a/src/redis.c +++ b/src/redis.c @@ -3550,17 +3550,6 @@ int checkForSentinelMode(int argc, char **argv) { return 0; } -/* Returns 1 if there is --check-rdb among the arguments or if - * argv[0] is exactly "redis-check-rdb". */ -int checkForCheckRDBMode(int argc, char **argv) { - int j; - - if (strstr(argv[0],"redis-check-rdb") != NULL) return 1; - for (j = 1; j < argc; j++) - if (!strcmp(argv[j],"--check-rdb")) return 1; - return 0; -} - /* Function called at startup to load RDB or AOF file in memory. */ void loadDataFromDisk(void) { long long start = ustime(); @@ -3746,6 +3735,12 @@ int main(int argc, char **argv) { initSentinel(); } + /* Check if we need to start in redis-check-rdb mode. We just execute + * the program main. However the program is part of the Redis executable + * so that we can easily execute an RDB check on loading errors. */ + if (strstr(argv[0],"redis-check-rdb") != NULL) + exit(redis_check_rdb_main(argv,argc)); + if (argc >= 2) { int j = 1; /* First option to parse in argv[] */ sds options = sdsempty(); @@ -3807,13 +3802,6 @@ int main(int argc, char **argv) { redisLog(REDIS_WARNING, "Warning: no config file specified, using the default config. In order to specify a config file use %s /path/to/%s.conf", argv[0], server.sentinel_mode ? "sentinel" : "redis"); } - if (checkForCheckRDBMode(argc, argv)) { - redisLog(REDIS_WARNING, "Checking RDB file %s", server.rdb_filename); - redisLog(REDIS_WARNING, "To check different RDB file: " - "redis-check-rdb --dbfilename "); - exit(redis_check_rdb(server.rdb_filename)); - } - server.supervised = redisIsSupervised(server.supervised_mode); int background = server.daemonize && !server.supervised; if (background) daemonize(); diff --git a/src/redis.h b/src/redis.h index 87bb811b2..2170c5d29 100644 --- a/src/redis.h +++ b/src/redis.h @@ -1382,6 +1382,7 @@ void sentinelIsRunning(void); /* redis-check-rdb */ int redis_check_rdb(char *rdbfilename); +int redis_check_rdb_main(char **argv, int argc); /* Scripting */ void scriptingInit(void);