summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKen Raeburn <raeburn@mit.edu>2004-03-18 03:07:22 +0000
committerKen Raeburn <raeburn@mit.edu>2004-03-18 03:07:22 +0000
commitf3d9bfd099e1a1a2a6fb324ae9c2bbd5617179d9 (patch)
tree88e3797bb65e2c7194da9885f519545bd9170cc9 /src
parente805b6cdbdfeda56e4a44f21ba0f15b68f8f88f6 (diff)
downloadkrb5-f3d9bfd099e1a1a2a6fb324ae9c2bbd5617179d9.tar.gz
krb5-f3d9bfd099e1a1a2a6fb324ae9c2bbd5617179d9.tar.xz
krb5-f3d9bfd099e1a1a2a6fb324ae9c2bbd5617179d9.zip
Thread-safe manipulation of registered error-table list
* error_message.c: Include k5-thread.h. (_et_list): Now always static. (et_list_lock): New mutex. (error_message): Lock it while manipulating the table lists. (add_error_table, remove_error_table): Likewise. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16183 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src')
-rw-r--r--src/util/et/ChangeLog8
-rw-r--r--src/util/et/Makefile.in2
-rw-r--r--src/util/et/error_message.c35
3 files changed, 34 insertions, 11 deletions
diff --git a/src/util/et/ChangeLog b/src/util/et/ChangeLog
index 1f43ce0318..197bef0a3b 100644
--- a/src/util/et/ChangeLog
+++ b/src/util/et/ChangeLog
@@ -1,3 +1,11 @@
+2004-03-17 Ken Raeburn <raeburn@mit.edu>
+
+ * error_message.c: Include k5-thread.h.
+ (_et_list): Now always static.
+ (et_list_lock): New mutex.
+ (error_message): Lock it while manipulating the table lists.
+ (add_error_table, remove_error_table): Likewise.
+
2003-07-04 Kenneth Raeburn <raeburn@mit.edu>
* test_et.c: Conditionalize sys_nerr declaration on
diff --git a/src/util/et/Makefile.in b/src/util/et/Makefile.in
index 8212ce06dd..ce2cec44d5 100644
--- a/src/util/et/Makefile.in
+++ b/src/util/et/Makefile.in
@@ -230,7 +230,7 @@ depend:: et_lex.lex.c
# the Makefile.in file
#
error_message.so error_message.po $(OUTPRE)error_message.$(OBJEXT): error_message.c com_err.h \
- error_table.h
+ error_table.h $(SRCTOP)/include/k5-thread.h $(BUILDTOP)/include/krb5/autoconf.h
et_name.so et_name.po $(OUTPRE)et_name.$(OBJEXT): et_name.c com_err.h error_table.h
init_et.so init_et.po $(OUTPRE)init_et.$(OBJEXT): init_et.c com_err.h error_table.h
com_err.so com_err.po $(OUTPRE)com_err.$(OBJEXT): com_err.c com_err.h error_table.h
diff --git a/src/util/et/error_message.c b/src/util/et/error_message.c
index d854850bd4..67b62ee668 100644
--- a/src/util/et/error_message.c
+++ b/src/util/et/error_message.c
@@ -1,5 +1,5 @@
/*
- * Copyright 1997,2000,2001 by Massachusetts Institute of Technology
+ * Copyright 1997,2000,2001,2004 by Massachusetts Institute of Technology
*
* Copyright 1987, 1988 by MIT Student Information Processing Board
*
@@ -26,6 +26,7 @@
#include <string.h>
#include "com_err.h"
#include "error_table.h"
+#include "k5-thread.h"
#if defined(_WIN32)
#define HAVE_STRERROR
@@ -38,14 +39,9 @@ extern const int sys_nerr;
static char buffer[ET_EBUFSIZ];
-#if (defined(_WIN32) || TARGET_OS_MAC)
/*@null@*/ static struct et_list * _et_list = (struct et_list *) NULL;
-#else
-/* Old interface compatibility */
-/*@null@*/ struct et_list * _et_list = (struct et_list *) NULL;
-#endif
-
/*@null@*//*@only@*/static struct dynamic_et_list * et_list_dynamic;
+static k5_mutex_t et_list_lock = K5_MUTEX_INITIALIZER;
#ifndef DEBUG_TABLE_LIST
#define dprintf(X)
@@ -66,6 +62,7 @@ error_message(long code)
unsigned int divisor = 100;
char *cp;
const struct error_table *table;
+ int merr;
l_offset = (unsigned long)code & ((1<<ERRCODE_RANGE)-1);
offset = l_offset;
@@ -104,6 +101,9 @@ error_message(long code)
goto system_error_code;
#endif
+ merr = k5_mutex_lock(&et_list_lock);
+ if (merr)
+ goto oops;
dprintf (("scanning static list for %x\n", table_num));
for (et = _et_list; et != NULL; et = et->next) {
if (et->table == NULL)
@@ -127,6 +127,7 @@ error_message(long code)
goto no_table_found;
found:
+ k5_mutex_unlock(&et_list_lock);
dprintf (("found it!\n"));
/* This is the right table */
@@ -140,6 +141,7 @@ error_message(long code)
return table->msgs[offset];
no_table_found:
+ k5_mutex_unlock(&et_list_lock);
#if defined(_WIN32)
/*
* WinSock errors exist in the 10000 and 11000 ranges
@@ -226,15 +228,22 @@ add_error_table(/*@dependent@*/ const struct error_table * et)
/*@=incondefs@*/
{
struct dynamic_et_list *del;
+ int merr;
del = (struct dynamic_et_list *)malloc(sizeof(struct dynamic_et_list));
if (del == NULL)
return errno;
del->table = et;
+
+ merr = k5_mutex_lock(&et_list_lock);
+ if (merr) {
+ free(del);
+ return merr;
+ }
del->next = et_list_dynamic;
et_list_dynamic = del;
- return 0;
+ return k5_mutex_unlock(&et_list_lock);
}
/*@-incondefs@*/ /* _et_list is global on unix but not in header annotations */
@@ -245,6 +254,11 @@ remove_error_table(const struct error_table * et)
{
struct dynamic_et_list **del;
struct et_list **el;
+ int merr;
+
+ merr = k5_mutex_lock(&et_list_lock);
+ if (merr)
+ return merr;
/* Remove the first occurrance we can find. Prefer dynamic
entries, but if there are none, check for a static one too. */
@@ -253,7 +267,7 @@ remove_error_table(const struct error_table * et)
/*@only@*/ struct dynamic_et_list *old = *del;
*del = old->next;
free (old);
- return 0;
+ return k5_mutex_unlock(&et_list_lock);
}
for (el = &_et_list; *el; el = &(*el)->next)
if ((*el)->table != NULL && (*el)->table->base == et->base) {
@@ -261,7 +275,8 @@ remove_error_table(const struct error_table * et)
*el = old->next;
old->next = NULL;
old->table = NULL;
- return 0;
+ return k5_mutex_unlock(&et_list_lock);
}
+ k5_mutex_unlock(&et_list_lock);
return ENOENT;
}