* 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
+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.
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;
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)
unsigned long table_num;
int started = 0;
unsigned int divisor = 100;
- char *cp;
+ char *cp, *cp1;
const struct error_table *table;
int merr;
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) {
}
*cp++ = '0' + offset;
*cp = '\0';
- return(buffer);
+ return(cp1);
}
/*@-incondefs@*/ /* _et_list is global on unix but not in header annotations */
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
#include "com_err.h"
#include "et1.h"
#include "et2.h"
}
#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);
(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
}