mirror of
https://github.com/fluencelabs/redis
synced 2025-03-18 16:40:50 +00:00
I like when main() is the last function in the file.
This commit is contained in:
parent
27acd7aa89
commit
39ca1713d7
94
src/redis.c
94
src/redis.c
@ -1878,53 +1878,6 @@ void redisAsciiArt(void) {
|
||||
zfree(buf);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
long long start;
|
||||
|
||||
zmalloc_enable_thread_safeness();
|
||||
initServerConfig();
|
||||
if (argc == 2) {
|
||||
if (strcmp(argv[1], "-v") == 0 ||
|
||||
strcmp(argv[1], "--version") == 0) version();
|
||||
if (strcmp(argv[1], "--help") == 0) usage();
|
||||
resetServerSaveParams();
|
||||
loadServerConfig(argv[1]);
|
||||
} else if ((argc > 2)) {
|
||||
usage();
|
||||
} else {
|
||||
redisLog(REDIS_WARNING,"Warning: no config file specified, using the default config. In order to specify a config file use 'redis-server /path/to/redis.conf'");
|
||||
}
|
||||
if (server.daemonize) daemonize();
|
||||
initServer();
|
||||
if (server.daemonize) createPidFile();
|
||||
redisAsciiArt();
|
||||
redisLog(REDIS_NOTICE,"Server started, Redis version " REDIS_VERSION);
|
||||
#ifdef __linux__
|
||||
linuxOvercommitMemoryWarning();
|
||||
#endif
|
||||
start = ustime();
|
||||
if (server.appendonly) {
|
||||
if (loadAppendOnlyFile(server.appendfilename) == REDIS_OK)
|
||||
redisLog(REDIS_NOTICE,"DB loaded from append only file: %.3f seconds",(float)(ustime()-start)/1000000);
|
||||
} else {
|
||||
if (rdbLoad(server.dbfilename) == REDIS_OK) {
|
||||
redisLog(REDIS_NOTICE,"DB loaded from disk: %.3f seconds",
|
||||
(float)(ustime()-start)/1000000);
|
||||
} else if (errno != ENOENT) {
|
||||
redisLog(REDIS_WARNING,"Fatal error loading the DB. Exiting.");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (server.ipfd > 0)
|
||||
redisLog(REDIS_NOTICE,"The server is now ready to accept connections on port %d", server.port);
|
||||
if (server.sofd > 0)
|
||||
redisLog(REDIS_NOTICE,"The server is now ready to accept connections at %s", server.unixsocket);
|
||||
aeSetBeforeSleepProc(server.el,beforeSleep);
|
||||
aeMain(server.el);
|
||||
aeDeleteEventLoop(server.el);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef HAVE_BACKTRACE
|
||||
static void *getMcontextEip(ucontext_t *uc) {
|
||||
#if defined(__FreeBSD__)
|
||||
@ -2050,4 +2003,51 @@ void setupSignalHandlers(void) {
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
long long start;
|
||||
|
||||
zmalloc_enable_thread_safeness();
|
||||
initServerConfig();
|
||||
if (argc == 2) {
|
||||
if (strcmp(argv[1], "-v") == 0 ||
|
||||
strcmp(argv[1], "--version") == 0) version();
|
||||
if (strcmp(argv[1], "--help") == 0) usage();
|
||||
resetServerSaveParams();
|
||||
loadServerConfig(argv[1]);
|
||||
} else if ((argc > 2)) {
|
||||
usage();
|
||||
} else {
|
||||
redisLog(REDIS_WARNING,"Warning: no config file specified, using the default config. In order to specify a config file use 'redis-server /path/to/redis.conf'");
|
||||
}
|
||||
if (server.daemonize) daemonize();
|
||||
initServer();
|
||||
if (server.daemonize) createPidFile();
|
||||
redisAsciiArt();
|
||||
redisLog(REDIS_NOTICE,"Server started, Redis version " REDIS_VERSION);
|
||||
#ifdef __linux__
|
||||
linuxOvercommitMemoryWarning();
|
||||
#endif
|
||||
start = ustime();
|
||||
if (server.appendonly) {
|
||||
if (loadAppendOnlyFile(server.appendfilename) == REDIS_OK)
|
||||
redisLog(REDIS_NOTICE,"DB loaded from append only file: %.3f seconds",(float)(ustime()-start)/1000000);
|
||||
} else {
|
||||
if (rdbLoad(server.dbfilename) == REDIS_OK) {
|
||||
redisLog(REDIS_NOTICE,"DB loaded from disk: %.3f seconds",
|
||||
(float)(ustime()-start)/1000000);
|
||||
} else if (errno != ENOENT) {
|
||||
redisLog(REDIS_WARNING,"Fatal error loading the DB. Exiting.");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (server.ipfd > 0)
|
||||
redisLog(REDIS_NOTICE,"The server is now ready to accept connections on port %d", server.port);
|
||||
if (server.sofd > 0)
|
||||
redisLog(REDIS_NOTICE,"The server is now ready to accept connections at %s", server.unixsocket);
|
||||
aeSetBeforeSleepProc(server.el,beforeSleep);
|
||||
aeMain(server.el);
|
||||
aeDeleteEventLoop(server.el);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* The End */
|
||||
|
Loading…
x
Reference in New Issue
Block a user