Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 30 Nov 2005 23:55:40 GMT
From:      Robert Watson <rwatson@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 87553 for review
Message-ID:  <200511302355.jAUNteig080193@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=87553

Change 87553 by rwatson@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);
 
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200511302355.jAUNteig080193>