X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/68d6345ddf6b0088e25d5f3b5ee93ad51833d5d1..29920dceb8e2b9806b2dcaf1dd134081e596633d:/src/redis.c diff --git a/src/redis.c b/src/redis.c index e59f3a73..84e5560e 100644 --- a/src/redis.c +++ b/src/redis.c @@ -192,24 +192,20 @@ struct redisCommand redisCommandTable[] = { /*============================ Utility functions ============================ */ -void redisLog(int level, const char *fmt, ...) { +/* Low level logging. To use only for very big messages, otherwise + * redisLog() is to prefer. */ +void redisLogRaw(int level, const char *msg) { const int syslogLevelMap[] = { LOG_DEBUG, LOG_INFO, LOG_NOTICE, LOG_WARNING }; const char *c = ".-*#"; time_t now = time(NULL); - va_list ap; FILE *fp; char buf[64]; - char msg[REDIS_MAX_LOGMSG_LEN]; if (level < server.verbosity) return; fp = (server.logfile == NULL) ? stdout : fopen(server.logfile,"a"); if (!fp) return; - va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); - va_end(ap); - strftime(buf,sizeof(buf),"%d %b %H:%M:%S",localtime(&now)); fprintf(fp,"[%d] %s %c %s\n",(int)getpid(),buf,c[level],msg); fflush(fp); @@ -219,6 +215,22 @@ void redisLog(int level, const char *fmt, ...) { if (server.syslog_enabled) syslog(syslogLevelMap[level], "%s", msg); } +/* Like redisLogRaw() but with printf-alike support. This is the funciton that + * is used across the code. The raw version is only used in order to dump + * the INFO output on crash. */ +void redisLog(int level, const char *fmt, ...) { + va_list ap; + char msg[REDIS_MAX_LOGMSG_LEN]; + + if (level < server.verbosity) return; + + va_start(ap, fmt); + vsnprintf(msg, sizeof(msg), fmt, ap); + va_end(ap); + + redisLogRaw(level,msg); +} + /* Redis generally does not try to recover from out of memory conditions * when allocating objects or strings, it is not clear if it will be possible * to report this condition to the client since the networking layer itself @@ -865,12 +877,12 @@ void initServer() { server.el = aeCreateEventLoop(); server.db = zmalloc(sizeof(redisDb)*server.dbnum); - if (server.port != 0) + if (server.port != 0) { server.ipfd = anetTcpServer(server.neterr,server.port,server.bindaddr); - - if (server.ipfd == ANET_ERR) { - redisLog(REDIS_WARNING, "Opening port: %s", server.neterr); - exit(1); + if (server.ipfd == ANET_ERR) { + redisLog(REDIS_WARNING, "Opening port: %s", server.neterr); + exit(1); + } } if (server.unixsocket != NULL) { unlink(server.unixsocket); /* don't care if this fails */ @@ -933,6 +945,7 @@ void initServer() { } if (server.ds_enabled) dsInit(); + srand(time(NULL)^getpid()); } /* Populates the Redis Command Table starting from the hard coded list @@ -1725,7 +1738,7 @@ void segvHandler(int sig, siginfo_t *info, void *secret) { redisLog(REDIS_WARNING, "======= Ooops! Redis %s got signal: -%d- =======", REDIS_VERSION, sig); infostring = genRedisInfoString("all"); - redisLog(REDIS_WARNING, "%s",infostring); + redisLogRaw(REDIS_WARNING, infostring); /* It's not safe to sdsfree() the returned string under memory * corruption conditions. Let it leak as we are going to abort */