+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
/*
- * 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
*
#include <string.h>
#include "com_err.h"
#include "error_table.h"
+#include "k5-thread.h"
#if defined(_WIN32)
#define HAVE_STRERROR
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)
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;
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)
goto no_table_found;
found:
+ k5_mutex_unlock(&et_list_lock);
dprintf (("found it!\n"));
/* This is the right table */
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
/*@=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 */
{
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. */
/*@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) {
*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;
}