PERFORCE change 87550 for review
Robert Watson
rwatson at FreeBSD.org
Wed Nov 30 23:38:18 GMT 2005
http://perforce.freebsd.org/chv.cgi?CH=87550
Change 87550 by rwatson at rwatson_peppercorn on 2005/11/30 23:37:24
Rework locking in BSM control code -- acquire mutex in the entry API
calls, resulting in atomicity across each full function call (i.e.,
between tests for fp being non-NULL and calling into lookup
functions, etc).
Affected files ...
.. //depot/projects/trustedbsd/openbsm/libbsm/bsm_control.c#8 edit
Differences ...
==== //depot/projects/trustedbsd/openbsm/libbsm/bsm_control.c#8 (text+ko) ====
@@ -50,9 +50,11 @@
/*
* Returns the string value corresponding to the given label from the
* configuration file.
+ *
+ * Must be called with mutex held.
*/
static int
-getstrfromtype(char *name, char **str)
+getstrfromtype_locked(char *name, char **str)
{
char *type, *nl;
char *tokptr;
@@ -60,17 +62,11 @@
*str = NULL;
- pthread_mutex_lock(&mutex);
-
- if ((fp == NULL) && ((fp = fopen(AUDIT_CONTROL_FILE, "r")) ==
- NULL)) {
- pthread_mutex_unlock(&mutex);
+ if ((fp == NULL) && ((fp = fopen(AUDIT_CONTROL_FILE, "r")) == NULL))
return (-1); /* Error */
- }
while (1) {
if (fgets(linestr, AU_LINE_MAX, fp) == NULL) {
- pthread_mutex_unlock(&mutex);
if (ferror(fp))
return (-1);
return (0); /* EOF */
@@ -89,7 +85,6 @@
if (strcmp(name, type) == 0) {
/* Found matching name. */
*str = strtok_r(NULL, delim, &last);
- pthread_mutex_unlock(&mutex);
if (*str == NULL) {
errno = EINVAL;
return (-1); /* Parse error in file */
@@ -99,7 +94,6 @@
}
}
- pthread_mutex_unlock(&mutex);
return (0); /* EOF */
}
@@ -160,11 +154,14 @@
ret = 2;
}
- pthread_mutex_unlock(&mutex);
- if (getstrfromtype(DIR_CONTROL_ENTRY, &dir) < 0)
+ if (getstrfromtype_locked(DIR_CONTROL_ENTRY, &dir) < 0) {
+ pthread_mutex_unlock(&mutex);
return (-2);
+ }
+ pthread_mutex_unlock(&mutex);
+
if (dir == NULL)
return (-1);
@@ -191,9 +188,15 @@
return (-2);
}
- if (getstrfromtype(MINFREE_CONTROL_ENTRY, &min) < 0)
+ pthread_mutex_lock(&mutex);
+
+ if (getstrfromtype_locked(MINFREE_CONTROL_ENTRY, &min) < 0) {
+ pthread_mutex_unlock(&mutex);
return (-2);
+ }
+ pthread_mutex_unlock(&mutex);
+
if (min == NULL)
return (1);
@@ -217,8 +220,14 @@
return (-2);
}
- if (getstrfromtype(FLAGS_CONTROL_ENTRY, &str) < 0)
+ pthread_mutex_lock(&mutex);
+
+ if (getstrfromtype_locked(FLAGS_CONTROL_ENTRY, &str) < 0) {
+ pthread_mutex_unlock(&mutex);
return (-2);
+ }
+
+ pthread_mutex_unlock(&mutex);
if (str == NULL)
return (1);
@@ -246,8 +255,13 @@
return (-2);
}
- if (getstrfromtype(NA_CONTROL_ENTRY, &str) < 0)
+ pthread_mutex_lock(&mutex);
+
+ if (getstrfromtype_locked(NA_CONTROL_ENTRY, &str) < 0) {
+ pthread_mutex_unlock(&mutex);
return (-2);
+ }
+ pthread_mutex_unlock(&mutex);
if (str == NULL)
return (1);
To Unsubscribe: send mail to majordomo at trustedbsd.org
with "unsubscribe trustedbsd-cvs" in the body of the message
More information about the trustedbsd-cvs
mailing list