PERFORCE change 87553 for review

Robert Watson rwatson at FreeBSD.org
Wed Nov 30 23:55:42 GMT 2005


http://perforce.freebsd.org/chv.cgi?CH=87553

Change 87553 by rwatson at rwatson_peppercorn on 2005/11/30 23:54:59

	Acquire mutex in entry API functions for BSM events, in order to
	improve atomicity between rewind of the event file and beginning
	iteration.

Affected files ...

.. //depot/projects/trustedbsd/openbsm/libbsm/bsm_event.c#5 edit

Differences ...

==== //depot/projects/trustedbsd/openbsm/libbsm/bsm_event.c#5 (text+ko) ====

@@ -135,13 +135,20 @@
 /*
  * Rewind the audit_event file.
  */
+static void
+setauevent_locked(void)
+{
+
+	if (fp != NULL)
+		fseek(fp, 0, SEEK_SET);
+}
+
 void
 setauevent(void)
 {
 
 	pthread_mutex_lock(&mutex);
-	if (fp != NULL)
-		fseek(fp, 0, SEEK_SET);
+	setauevent_locked();
 	pthread_mutex_unlock(&mutex);
 }
 
@@ -213,11 +220,11 @@
 	if (name == NULL)
 		return (NULL);
 
+	pthread_mutex_lock(&mutex);
+
 	/* Rewind to beginning of the file. */
-	setauevent();
+	setauevent_locked();
 
-	pthread_mutex_lock(&mutex);
-
 	if ((fp == NULL) && ((fp = fopen(AUDIT_EVENT_FILE, "r")) == NULL)) {
 		pthread_mutex_unlock(&mutex);
 		return (NULL);
@@ -242,8 +249,10 @@
 		}
 	}
 
+	pthread_mutex_unlock(&mutex);
+
 	free_au_event_ent(e);
-	pthread_mutex_unlock(&mutex);
+
 	return (NULL);
 }
 
@@ -255,11 +264,11 @@
 	struct au_event_ent *e;
 	char *nl;
 
+	pthread_mutex_lock(&mutex);
+
 	/* Rewind to beginning of the file. */
-	setauevent();
+	setauevent_locked();
 
-	pthread_mutex_lock(&mutex);
-
 	if ((fp == NULL) && ((fp = fopen(AUDIT_EVENT_FILE, "r")) == NULL)) {
 		pthread_mutex_unlock(&mutex);
 		return (NULL);
@@ -284,8 +293,8 @@
 		}
 	}
 
+	pthread_mutex_unlock(&mutex);
 	free_au_event_ent(e);
-	pthread_mutex_unlock(&mutex);
 	return (NULL);
 
 }


More information about the p4-projects mailing list