summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKen Raeburn <raeburn@mit.edu>2004-05-06 02:28:25 +0000
committerKen Raeburn <raeburn@mit.edu>2004-05-06 02:28:25 +0000
commit2e0cd9c3947738ed35e6d672ee4cdda5359163a0 (patch)
tree8880fe3de2c495b2392b23ef52bf617e905658cd /src
parent03feec0e60a84cbe1c1f77137eb23b2945fd2c44 (diff)
downloadkrb5-2e0cd9c3947738ed35e6d672ee4cdda5359163a0.tar.gz
krb5-2e0cd9c3947738ed35e6d672ee4cdda5359163a0.tar.xz
krb5-2e0cd9c3947738ed35e6d672ee4cdda5359163a0.zip
Start using our first bit of per-thread storage
* error_message.c (buffer): Static variable deleted. (com_err_initialize): Register cleanup support for com_err thread-specific data key. (error_message): Use a per-thread dynamically-allocated buffer instead of static storage, for the case where an unknown error code is given. If any errors occur allocating or tracking the buffer, return a fixed message. * t_com_err.c: Include stdlib.h. If TEST_THREADS is defined, include pthread.h. (run): Renamed from main, changed signature. (main): New function. Just call run, or if TEST_THREADS is defined, create a thread to call it. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16318 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src')
-rw-r--r--src/util/et/ChangeLog16
-rw-r--r--src/util/et/error_message.c31
-rw-r--r--src/util/et/t_com_err.c31
3 files changed, 70 insertions, 8 deletions
diff --git a/src/util/et/ChangeLog b/src/util/et/ChangeLog
index 1209177fa..4e99e206f 100644
--- a/src/util/et/ChangeLog
+++ b/src/util/et/ChangeLog
@@ -1,3 +1,19 @@
+2004-05-05 Ken Raeburn <raeburn@mit.edu>
+
+ * error_message.c (buffer): Static variable deleted.
+ (com_err_initialize): Register cleanup support for com_err
+ thread-specific data key.
+ (error_message): Use a per-thread dynamically-allocated buffer
+ instead of static storage, for the case where an unknown error
+ code is given. If any errors occur allocating or tracking the
+ buffer, return a fixed message.
+
+ * t_com_err.c: Include stdlib.h. If TEST_THREADS is defined,
+ include pthread.h.
+ (run): Renamed from main, changed signature.
+ (main): New function. Just call run, or if TEST_THREADS is
+ defined, create a thread to call it.
+
2004-05-04 Ken Raeburn <raeburn@mit.edu>
* configure.in: Invoke KRB5_BUILD_PROGRAM and KRB5_RUN_FLAGS.
diff --git a/src/util/et/error_message.c b/src/util/et/error_message.c
index 44a73b6c6..dd3c36fd0 100644
--- a/src/util/et/error_message.c
+++ b/src/util/et/error_message.c
@@ -38,8 +38,6 @@ extern char const * const sys_errlist[];
extern const int sys_nerr;
#endif
-static char buffer[ET_EBUFSIZ];
-
/*@null@*/ static struct et_list * _et_list = (struct et_list *) NULL;
/*@null@*//*@only@*/static struct dynamic_et_list * et_list_dynamic;
static k5_mutex_t et_list_lock = K5_MUTEX_PARTIAL_INITIALIZER;
@@ -49,7 +47,14 @@ MAKE_FINI_FUNCTION(com_err_terminate);
int com_err_initialize(void)
{
- return k5_mutex_finish_init(&et_list_lock);
+ int err;
+ err = k5_mutex_finish_init(&et_list_lock);
+ if (err)
+ return err;
+ err = k5_key_register(K5_KEY_COM_ERR, free);
+ if (err)
+ return err;
+ return 0;
}
void com_err_terminate(void)
@@ -81,7 +86,7 @@ error_message(long code)
unsigned long table_num;
int started = 0;
unsigned int divisor = 100;
- char *cp;
+ char *cp, *cp1;
const struct error_table *table;
int merr;
@@ -221,8 +226,20 @@ oops:
return (strerror (code));
}
#endif
-
- cp = buffer;
+
+ cp = k5_getspecific(K5_KEY_COM_ERR);
+ if (cp == NULL) {
+ cp = malloc(ET_EBUFSIZ);
+ if (cp == NULL) {
+ no_specific:
+ return "Unknown error code";
+ }
+ if (k5_setspecific(K5_KEY_COM_ERR, cp) != 0) {
+ free(cp);
+ goto no_specific;
+ }
+ }
+ cp1 = cp;
strcpy(cp, "Unknown code ");
cp += sizeof("Unknown code ") - 1;
if (table_num != 0L) {
@@ -241,7 +258,7 @@ oops:
}
*cp++ = '0' + offset;
*cp = '\0';
- return(buffer);
+ return(cp1);
}
/*@-incondefs@*/ /* _et_list is global on unix but not in header annotations */
diff --git a/src/util/et/t_com_err.c b/src/util/et/t_com_err.c
index c6095cfe1..2cba3cfdc 100644
--- a/src/util/et/t_com_err.c
+++ b/src/util/et/t_com_err.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
#include "com_err.h"
#include "et1.h"
#include "et2.h"
@@ -59,7 +60,7 @@ try_em_1 (int t1_known, int t2_known, int lineno)
}
#define try_em(A,B) try_em_1(A,B,__LINE__)
-int main (/*@unused@*/ int argc, /*@unused@*/ char *argv[])
+static void *run(/*@unused@*/ void *x)
{
try_em (0, 0);
(void) add_error_table (&et_et1_error_table);
@@ -110,5 +111,33 @@ int main (/*@unused@*/ int argc, /*@unused@*/ char *argv[])
(void) remove_error_table (&et_et2_error_table);
try_em (0, 0);
+ return 0;
+}
+
+#ifdef TEST_THREADS
+#include <pthread.h>
+#endif
+
+int main (/*@unused@*/ int argc, /*@unused@*/ char *argv[])
+{
+#ifdef TEST_THREADS
+ pthread_t t;
+ int err;
+ void *t_retval;
+
+ err = pthread_create(&t, 0, run, 0);
+ if (err) {
+ fprintf(stderr, "pthread_create error: %s\n", strerror(err));
+ exit(1);
+ }
+ err = pthread_join(t, &t_retval);
+ if (err) {
+ fprintf(stderr, "pthread_join error: %s\n", strerror(err));
+ exit(1);
+ }
+ return fail;
+#else
+ run(0);
return fail;
+#endif
}