From 61f097e67c69e99e431c711ada5bbcd7cc81ae16 Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Tue, 18 Apr 2006 23:28:07 +0000 Subject: [PATCH] * 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 --- src/util/et/error_message.c | 79 ++++++++++++++++++------------------- src/util/et/error_table.h | 2 +- 2 files changed, 39 insertions(+), 42 deletions(-) diff --git a/src/util/et/error_message.c b/src/util/et/error_message.c index b7f8947d2..62be6a6e7 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< 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 ea804cf00..b58502a58 100644 --- a/src/util/et/error_table.h +++ b/src/util/et/error_table.h @@ -9,7 +9,7 @@ #include -#define ET_EBUFSIZ 64 +#define ET_EBUFSIZ 1024 struct et_list { /*@dependent@*//*@null@*/ struct et_list *next; -- 2.26.2