From a09bbc23a60802f6ddc7ee390e541c89f558775b Mon Sep 17 00:00:00 2001 From: Paulo Cesar Pereira de Andrade Date: Sat, 1 Mar 2008 21:23:06 -0300 Subject: [PATCH] Rewrite commented out out code for audit message compression. Just always print the "audit" message at the first request, and flush the repeat counter message when a new message (with different data) arrives, as well as when doing the "cleanup" by calling FreeAuditTimer(). --- os/log.c | 84 +++++++++++++++++--------------------------------------------- 1 files changed, 23 insertions(+), 61 deletions(-) diff --git a/os/log.c b/os/log.c index 0860847..6687a65 100644 --- a/os/log.c +++ b/os/log.c @@ -98,6 +98,7 @@ OR PERFORMANCE OF THIS SOFTWARE. #define getpid(x) _getpid(x) #endif +static void AuditFlush(void); #ifdef DDXOSVERRORF void (*OsVendorVErrorFProc)(const char *, va_list args) = NULL; @@ -413,23 +414,16 @@ AbortServer(void) #ifndef AUDIT_PREFIX #define AUDIT_PREFIX "AUDIT: %s: %ld %s: " #endif -#ifndef AUDIT_TIMEOUT -#define AUDIT_TIMEOUT ((CARD32)(120 * 1000)) /* 2 mn */ -#endif -static int nrepeat = 0; -static int oldlen = -1; -static OsTimerPtr auditTimer = NULL; +static int audit_nrepeat = 0; +static int audit_oldlen = -1; +static char audit_prefix[128]; void FreeAuditTimer(void) { - if (auditTimer != NULL) { - /* Force output of pending messages */ - TimerForce(auditTimer); - TimerFree(auditTimer); - auditTimer = NULL; - } + AuditFlush(); + audit_oldlen = -1; } static char * @@ -437,8 +431,6 @@ AuditPrefix(void) { time_t tm; char *autime, *s; - char *tmpBuf; - int len; time(&tm); autime = ctime(&tm); @@ -448,12 +440,10 @@ AuditPrefix(void) s++; else s = argvGlobal[0]; - len = strlen(AUDIT_PREFIX) + strlen(autime) + 10 + strlen(s) + 1; - tmpBuf = malloc(len); - if (!tmpBuf) - return NULL; - snprintf(tmpBuf, len, AUDIT_PREFIX, autime, (unsigned long)getpid(), s); - return tmpBuf; + snprintf(audit_prefix, sizeof(audit_prefix), + AUDIT_PREFIX, autime, (unsigned long)getpid(), s); + + return (audit_prefix); } void @@ -467,62 +457,34 @@ AuditF(const char * f, ...) va_end(args); } -static CARD32 -AuditFlush(OsTimerPtr timer, CARD32 now, pointer arg) +static void +AuditFlush(void) { - char *prefix; - - if (nrepeat > 0) { - prefix = AuditPrefix(); + if (audit_nrepeat > 1) { ErrorF("%slast message repeated %d times\n", - prefix != NULL ? prefix : "", nrepeat); - nrepeat = 0; - if (prefix != NULL) - free(prefix); - return AUDIT_TIMEOUT; - } else { - /* if the timer expires without anything to print, flush the message */ - oldlen = -1; - return 0; + AuditPrefix(), audit_nrepeat); + audit_nrepeat = 0; } } void VAuditF(const char *f, va_list args) { - char *prefix; char buf[1024]; int len; - static char oldbuf[1024]; + static char audit_oldbuf[1024]; - prefix = AuditPrefix(); len = vsnprintf(buf, sizeof(buf), f, args); -#if 1 - /* XXX Compressing duplicated messages is temporarily disabled to - * work around bugzilla 964: - * https://freedesktop.org/bugzilla/show_bug.cgi?id=964 - */ - ErrorF("%s%s", prefix != NULL ? prefix : "", buf); - oldlen = -1; - nrepeat = 0; -#else - if (len == oldlen && strcmp(buf, oldbuf) == 0) { + if (audit_nrepeat && len == audit_oldlen && strcmp(buf, audit_oldbuf) == 0) /* Message already seen */ - nrepeat++; - } else { - /* new message */ - if (auditTimer != NULL) - TimerForce(auditTimer); - ErrorF("%s%s", prefix != NULL ? prefix : "", buf); - strlcpy(oldbuf, buf, sizeof(oldbuf)); - oldlen = len; - nrepeat = 0; - auditTimer = TimerSet(auditTimer, 0, AUDIT_TIMEOUT, AuditFlush, NULL); + audit_nrepeat++; + else { + AuditFlush(); + ErrorF("%s%s", AuditPrefix(), buf); + audit_nrepeat = 1; + audit_oldlen = len; } -#endif - if (prefix != NULL) - free(prefix); } _X_EXPORT void -- 1.5.3.2