audit: Always call pthread_once in osi_audit_init 03/14403/4
authorAndrew Deason <adeason@sinenomine.net>
Mon, 19 Oct 2020 21:07:44 +0000 (16:07 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Sun, 1 Nov 2020 18:11:48 +0000 (13:11 -0500)
Currently, we skip the pthread_once call in osi_audit_init if
audit_lock_initialized is set. But this is somewhat pointless, since
pthread_once will effectively do this check itself, and better (it
will wait if osi_audit_init is actively running in another thread).

So just get rid of audit_lock_initialized, and replace the other
assert for audit_lock_initialized with another plain pthread_once
call.

Change-Id: I466c8ec2d1516edecaae23d4354892e7e3a88918
Reviewed-on: https://gerrit.openafs.org/14403
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/audit/audit.c

index 1f641f0..4459700 100644 (file)
@@ -461,14 +461,12 @@ printbuf(int rec, char *audEvent, char *afsName, afs_int32 hostId,
 
 #ifdef AFS_PTHREAD_ENV
 static pthread_mutex_t audit_lock;
-static volatile afs_int32   audit_lock_initialized = 0;
 static pthread_once_t audit_lock_once = PTHREAD_ONCE_INIT;
 
 static void
 osi_audit_init_lock(void)
 {
     MUTEX_INIT(&audit_lock, "audit", MUTEX_DEFAULT, 0);
-    audit_lock_initialized = 1;
 }
 #endif
 
@@ -476,9 +474,7 @@ void
 osi_audit_init(void)
 {
 #ifdef AFS_PTHREAD_ENV
-    if (!audit_lock_initialized) {
-       pthread_once(&audit_lock_once, osi_audit_init_lock);
-    }
+    pthread_once(&audit_lock_once, osi_audit_init_lock);
 #endif /* AFS_PTHREAD_ENV */
 }
 
@@ -501,9 +497,9 @@ osi_audit_internal(char *audEvent,  /* Event name (15 chars or less) */
 
 #ifdef AFS_PTHREAD_ENV
     /* i'm pretty sure all the server apps now call osi_audit_init(),
-     * but to be extra careful we'll leave this assert in here for a
+     * but to be extra careful we'll leave this in here for a
      * while to make sure */
-    opr_Assert(audit_lock_initialized);
+    pthread_once(&audit_lock_once, osi_audit_init_lock);
 #endif /* AFS_PTHREAD_ENV */
 
     if ((osi_audit_all < 0) || (osi_echo_trail < 0))