X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/900ab8fc7a38a1e2b94689f319df2c8e2a47f1e9..5d1b4fb6983f5acd9cfb6ee5f5715547688448d2:/src/redis.c diff --git a/src/redis.c b/src/redis.c index 73cd6dee..866ac360 100644 --- a/src/redis.c +++ b/src/redis.c @@ -859,7 +859,7 @@ void initServer() { signal(SIGHUP, SIG_IGN); signal(SIGPIPE, SIG_IGN); - setupSigSegvAction(); + setupSignalHandlers(); if (server.syslog_enabled) { openlog(server.syslog_ident, LOG_PID | LOG_NDELAY | LOG_NOWAIT, @@ -1664,7 +1664,7 @@ void usage() { } int main(int argc, char **argv) { - time_t start; + long long start; initServerConfig(); if (argc == 2) { @@ -1685,15 +1685,15 @@ int main(int argc, char **argv) { #ifdef __linux__ linuxOvercommitMemoryWarning(); #endif - start = time(NULL); + start = ustime(); if (server.ds_enabled) { redisLog(REDIS_NOTICE,"DB not loaded (running with disk back end)"); } else if (server.appendonly) { if (loadAppendOnlyFile(server.appendfilename) == REDIS_OK) - redisLog(REDIS_NOTICE,"DB loaded from append only file: %ld seconds",time(NULL)-start); + 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: %ld seconds",time(NULL)-start); + redisLog(REDIS_NOTICE,"DB loaded from disk: %.3f seconds",(float)(ustime()-start)/1000000); } if (server.ipfd > 0) redisLog(REDIS_NOTICE,"The server is now ready to accept connections on port %d", server.port); @@ -1705,10 +1705,8 @@ int main(int argc, char **argv) { return 0; } -/* ============================= Backtrace support ========================= */ - #ifdef HAVE_BACKTRACE -void *getMcontextEip(ucontext_t *uc) { +static void *getMcontextEip(ucontext_t *uc) { #if defined(__FreeBSD__) return (void*) uc->uc_mcontext.mc_eip; #elif defined(__dietlibc__) @@ -1736,7 +1734,7 @@ void *getMcontextEip(ucontext_t *uc) { #endif } -void segvHandler(int sig, siginfo_t *info, void *secret) { +static void sigsegvHandler(int sig, siginfo_t *info, void *secret) { void *trace[100]; char **messages = NULL; int i, trace_size = 0; @@ -1775,37 +1773,35 @@ void segvHandler(int sig, siginfo_t *info, void *secret) { sigaction (sig, &act, NULL); kill(getpid(),sig); } +#endif /* HAVE_BACKTRACE */ -void sigtermHandler(int sig) { +static void sigtermHandler(int sig) { REDIS_NOTUSED(sig); - redisLog(REDIS_WARNING,"SIGTERM received, scheduling shutting down..."); + redisLog(REDIS_WARNING,"Received SIGTERM, scheduling shutdown..."); server.shutdown_asap = 1; } -void setupSigSegvAction(void) { +void setupSignalHandlers(void) { struct sigaction act; - sigemptyset (&act.sa_mask); - /* When the SA_SIGINFO flag is set in sa_flags then sa_sigaction - * is used. Otherwise, sa_handler is used */ - act.sa_flags = SA_NODEFER | SA_ONSTACK | SA_RESETHAND | SA_SIGINFO; - act.sa_sigaction = segvHandler; - sigaction (SIGSEGV, &act, NULL); - sigaction (SIGBUS, &act, NULL); - sigaction (SIGFPE, &act, NULL); - sigaction (SIGILL, &act, NULL); - sigaction (SIGBUS, &act, NULL); - + /* When the SA_SIGINFO flag is set in sa_flags then sa_sigaction is used. + * Otherwise, sa_handler is used. */ + sigemptyset(&act.sa_mask); act.sa_flags = SA_NODEFER | SA_ONSTACK | SA_RESETHAND; act.sa_handler = sigtermHandler; - sigaction (SIGTERM, &act, NULL); - return; -} + sigaction(SIGTERM, &act, NULL); -#else /* HAVE_BACKTRACE */ -void setupSigSegvAction(void) { +#ifdef HAVE_BACKTRACE + sigemptyset(&act.sa_mask); + act.sa_flags = SA_NODEFER | SA_ONSTACK | SA_RESETHAND | SA_SIGINFO; + act.sa_sigaction = sigsegvHandler; + sigaction(SIGSEGV, &act, NULL); + sigaction(SIGBUS, &act, NULL); + sigaction(SIGFPE, &act, NULL); + sigaction(SIGILL, &act, NULL); +#endif + return; } -#endif /* HAVE_BACKTRACE */ /* The End */