]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
STABLE14-audit-locking-20051113
authorJeffrey Altman <jaltman@secure-endpoints.com>
Mon, 13 Feb 2006 17:56:49 +0000 (17:56 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Mon, 13 Feb 2006 17:56:49 +0000 (17:56 +0000)
Add locks around writes to the audit log.  This ensures two writes
do not interleave.

(cherry picked from commit 6f82595a16750a3811526da9b4376a178e90bb49)

src/audit/audit.c
src/audit/audit.h

index 71c4dbbde5546a7db6878c13639a4a637de56938..aeea18567ffefa5e6d211aabc3c6ffb35ec1a6a7 100644 (file)
@@ -257,6 +257,19 @@ printbuf(FILE *out, int rec, char *audEvent, afs_int32 errCode, va_list vaList)
        fprintf(out, "\n");
 }
 
+static struct Lock audlock;
+static afs_int32   lock_init = 0;
+void
+osi_audit_init(void)
+{
+#ifdef AFS_PTHREAD_ENV
+    if ( !lock_init ) {
+       Lock_Init(&audlock);
+       lock_init = 1;
+    }
+#endif /* AFS_PTHREAD_ENV */
+}
+
 /* ************************************************************************** */
 /* The routine that acually does the audit call.
  * ************************************************************************** */
@@ -268,20 +281,18 @@ osi_audit(char *audEvent, /* Event name (15 chars or less) */
 #ifdef AFS_AIX32_ENV
     afs_int32 code;
     afs_int32 err;
+    static char BUFFER[32768];
 #endif
     int result;
-
     va_list vaList;
-#ifdef AFS_AIX32_ENV
-    static struct Lock audbuflock = { 0, 0, 0, 0,
+
 #ifdef AFS_PTHREAD_ENV
-       PTHREAD_MUTEX_INITIALIZER,
-       PTHREAD_COND_INITIALIZER,
-       PTHREAD_COND_INITIALIZER
+    /* This is not thread safe.   Lock initialization should 
+     * be done in a server initialization phase
+     */
+    if ( !lock_init )
+       osi_audit_init();
 #endif /* AFS_PTHREAD_ENV */
-    };
-    static char BUFFER[32768];
-#endif
 
     if ((osi_audit_all < 0) || (osi_echo_trail < 0))
        osi_audit_check();
@@ -312,8 +323,10 @@ osi_audit(char *audEvent,  /* Event name (15 chars or less) */
        break;
     }
 
+#ifdef AFS_PTHREAD_ENV
+    ObtainWriteLock(&audlock);
+#endif
 #ifdef AFS_AIX32_ENV
-    ObtainWriteLock(&audbuflock);
     bufferPtr = BUFFER;
 
     /* Put the error code into the buffer list */
@@ -340,7 +353,6 @@ osi_audit(char *audEvent,   /* Event name (15 chars or less) */
            printf("Error while writing audit entry: %d.\n", errno);
     }
 #endif /* notdef */
-    ReleaseWriteLock(&audbuflock);
 #else
     if (auditout) {
        va_start(vaList, errCode);
@@ -348,6 +360,9 @@ osi_audit(char *audEvent,   /* Event name (15 chars or less) */
        fflush(auditout);
     }
 #endif
+#ifdef AFS_PTHREAD_ENV
+    ReleaseWriteLock(&audlock);
+#endif
 
     return 0;
 }
index b02e80d6ac851d7f9503d65ab29048748e964c91..ba6f27741c71730185e4f78cfabb5c3782bd3b7e 100644 (file)
 int osi_audit(char *audEvent, afs_int32 errCode, ...);
 int osi_auditU(struct rx_call *call, char *audEvent, int errCode, ...);
 int osi_audit_file(FILE *out);
+void osi_audit_init(void);
+