]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] remove useless calls to gettimeofday()
authorWilly Tarreau <w@1wt.eu>
Sun, 15 Oct 2006 13:25:48 +0000 (15:25 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 15 Oct 2006 13:25:48 +0000 (15:25 +0200)
send_log(), Alert() and Warning() used gettimeofday() while using
<now> should have been preferred.

src/haproxy.c
src/log.c

index ef246e6eb5124046871b50109ebb0ca9e96084fd..92dc6264bce81eb602de207ad03260afcf21f9ec 100644 (file)
@@ -346,6 +346,7 @@ void init(int argc, char **argv)
 
        /* initialize the libc's localtime structures once for all so that we
         * won't be missing memory if we want to send alerts under OOM conditions.
+        * Also, the Alert() and Warning() functions need <now> to be initialized.
         */
        tv_now(&now);
        localtime(&now.tv_sec);
index e02a81f82d668035da21c2b27ebdd44e1953c4ca..6af34644ea89c5d6deb0dc4e6631cb6aabf9a948 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -67,14 +67,12 @@ void **pool_requri = NULL;
 void Alert(const char *fmt, ...)
 {
        va_list argp;
-       struct timeval tv;
        struct tm *tm;
 
        if (!(global.mode & MODE_QUIET) || (global.mode & (MODE_VERBOSE | MODE_STARTING))) {
                va_start(argp, fmt);
 
-               gettimeofday(&tv, NULL);
-               tm = localtime(&tv.tv_sec);
+               tm = localtime(&now.tv_sec);
                fprintf(stderr, "[ALERT] %03d/%02d%02d%02d (%d) : ",
                        tm->tm_yday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)getpid());
                vfprintf(stderr, fmt, argp);
@@ -90,14 +88,12 @@ void Alert(const char *fmt, ...)
 void Warning(const char *fmt, ...)
 {
        va_list argp;
-       struct timeval tv;
        struct tm *tm;
 
        if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) {
                va_start(argp, fmt);
 
-               gettimeofday(&tv, NULL);
-               tm = localtime(&tv.tv_sec);
+               tm = localtime(&now.tv_sec);
                fprintf(stderr, "[WARNING] %03d/%02d%02d%02d (%d) : ",
                        tm->tm_yday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)getpid());
                vfprintf(stderr, fmt, argp);
@@ -177,7 +173,6 @@ void send_log(struct proxy *p, int level, const char *message, ...)
 {
        static int logfd = -1;  /* syslog UDP socket */
        static long tvsec = -1; /* to force the string to be initialized */
-       struct timeval tv;
        va_list argp;
        static char logmsg[MAX_SYSLOG_LEN];
        static char *dataptr = NULL;
@@ -196,11 +191,10 @@ void send_log(struct proxy *p, int level, const char *message, ...)
        if (level < 0 || progname == NULL || message == NULL)
                return;
 
-       gettimeofday(&tv, NULL);
-       if (tv.tv_sec != tvsec || dataptr == NULL) {
+       if (now.tv_sec != tvsec || dataptr == NULL) {
                /* this string is rebuild only once a second */
-               struct tm *tm = localtime(&tv.tv_sec);
-               tvsec = tv.tv_sec;
+               struct tm *tm = localtime(&now.tv_sec);
+               tvsec = now.tv_sec;
 
                hdr_len = snprintf(logmsg, sizeof(logmsg),
                                   "<<<<>%s %2d %02d:%02d:%02d %s[%d]: ",