summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKen Raeburn <raeburn@mit.edu>2006-04-18 23:28:07 +0000
committerKen Raeburn <raeburn@mit.edu>2006-04-18 23:28:07 +0000
commit61f097e67c69e99e431c711ada5bbcd7cc81ae16 (patch)
tree929cdb5d95e1c5286bae5bdc1f632542583aa5ef /src
parentcc44f8e46fa0bf9dfbadd9928e3aa81dc9c01844 (diff)
downloadkrb5-61f097e67c69e99e431c711ada5bbcd7cc81ae16.tar.gz
krb5-61f097e67c69e99e431c711ada5bbcd7cc81ae16.tar.xz
krb5-61f097e67c69e99e431c711ada5bbcd7cc81ae16.zip
* error_table.h (ET_EBUFSIZ): Increase to 1k.
* error_message.c (get_thread_buffer): New function, split out from error_message. (error_message): Call it. Also try strerror_r with the per-thread buffer, if both are available, before trying strerror. ticket: 3620 status: open git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@17942 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src')
-rw-r--r--src/util/et/error_message.c79
-rw-r--r--src/util/et/error_table.h2
2 files changed, 39 insertions, 42 deletions
diff --git a/src/util/et/error_message.c b/src/util/et/error_message.c
index b7f8947d29..62be6a6e7f 100644
--- a/src/util/et/error_message.c
+++ b/src/util/et/error_message.c
@@ -91,6 +91,24 @@ void com_err_terminate(void)
#define dprintf(X) printf X
#endif
+static char *
+get_thread_buffer ()
+{
+ char *cp;
+ cp = k5_getspecific(K5_KEY_COM_ERR);
+ if (cp == NULL) {
+ cp = malloc(ET_EBUFSIZ);
+ if (cp == NULL) {
+ return NULL;
+ }
+ if (k5_setspecific(K5_KEY_COM_ERR, cp) != 0) {
+ free(cp);
+ return NULL;
+ }
+ }
+ return cp;
+}
+
const char * KRB5_CALLCONV
error_message(long code)
/*@modifies internalState@*/
@@ -109,39 +127,36 @@ error_message(long code)
l_offset = (unsigned long)code & ((1<<ERRCODE_RANGE)-1);
offset = l_offset;
table_num = ((unsigned long)code - l_offset) & ERRCODE_MAX;
- if (table_num == 0) {
+ if (table_num == 0
#ifdef __sgi
- system_error_code:
+ /* Irix 6.5 uses a much bigger table than other UNIX
+ systems I've looked at, but the table is sparse. The
+ sparse entries start around 500, but sys_nerr is only
+ 152. */
+ || (code > 0 && code <= 1600)
#endif
+ ) {
if (code == 0)
goto oops;
/* This could trip if int is 16 bits. */
if ((unsigned long)(int)code != code)
abort ();
+#ifdef HAVE_STRERROR_R
+ cp = get_thread_buffer();
+ if (cp && strerror_r((int) code, cp, ET_EBUFSIZ) == 0)
+ return cp;
+#endif
#ifdef HAVE_STRERROR
cp = strerror((int) code);
if (cp)
return cp;
- goto oops;
-#else
-#ifdef HAVE_SYS_ERRLIST
+#elif defined HAVE_SYS_ERRLIST
if (offset < sys_nerr)
return(sys_errlist[offset]);
- else
- goto oops;
-#else
+#endif
goto oops;
-#endif /* HAVE_SYS_ERRLIST */
-#endif /* HAVE_STRERROR */
}
-#ifdef __sgi
- /* Irix 6.5 uses a much bigger table than other UNIX systems
- I've looked at, but the table is sparse. The sparse
- entries start around 500, but sys_nerr is only 152. */
- if (code > 0 && code <= 1600)
- goto system_error_code;
-#endif
if (CALL_INIT_FUNCTION(com_err_initialize))
return 0;
@@ -221,18 +236,9 @@ error_message(long code)
goto oops;
} else {
char *buffer;
- cp = k5_getspecific(K5_KEY_COM_ERR);
- if (cp == NULL) {
- cp = malloc(ET_EBUFSIZ);
- if (cp == NULL) {
- win32_no_specific:
- return "Unknown error code";
- }
- if (k5_setspecific(K5_KEY_COM_ERR, cp) != 0) {
- free(cp);
- goto win32_no_specific;
- }
- }
+ cp = get_thread_buffer();
+ if (cp == NULL)
+ return "Unknown error code";
buffer = cp;
strncpy(buffer, msgbuf, ET_EBUFSIZ);
buffer[ET_EBUFSIZ-1] = '\0';
@@ -257,18 +263,9 @@ oops:
}
#endif
- 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;
- }
- }
+ cp = get_thread_buffer();
+ if (cp == NULL)
+ return "Unknown error code";
cp1 = cp;
strcpy(cp, "Unknown code ");
cp += sizeof("Unknown code ") - 1;
diff --git a/src/util/et/error_table.h b/src/util/et/error_table.h
index ea804cf005..b58502a588 100644
--- a/src/util/et/error_table.h
+++ b/src/util/et/error_table.h
@@ -9,7 +9,7 @@
#include <errno.h>
-#define ET_EBUFSIZ 64
+#define ET_EBUFSIZ 1024
struct et_list {
/*@dependent@*//*@null@*/ struct et_list *next;