From 41d6e61e7a953d6ef5e77a3271208b1b6c4e4921 Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Wed, 29 Apr 2009 23:21:21 +0000 Subject: Add DEBUG_ERROR_LOCATIONS support If DEBUG_ERROR_LOCATIONS is defined, replace uses of krb5_set_error_message and krb5int_set_error with calls to the new _fl variants of those functions, and include filename and line number information in the calls. Requires C99-style variadic macros if defined. ticket: 6479 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@22291 dc483132-0cff-0310-8789-dd5450dbe970 --- src/util/support/errors.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'src/util/support/errors.c') diff --git a/src/util/support/errors.c b/src/util/support/errors.c index 4111ed478..8d523b98b 100644 --- a/src/util/support/errors.c +++ b/src/util/support/errors.c @@ -34,21 +34,40 @@ krb5int_err_init (void) #define lock() k5_mutex_lock(&krb5int_error_info_support_mutex) #define unlock() k5_mutex_unlock(&krb5int_error_info_support_mutex) +#undef krb5int_set_error void krb5int_set_error (struct errinfo *ep, long code, const char *fmt, ...) { va_list args; va_start (args, fmt); - krb5int_vset_error (ep, code, fmt, args); + krb5int_vset_error_fl (ep, code, NULL, 0, fmt, args); + va_end (args); +} + +void +krb5int_set_error_fl (struct errinfo *ep, long code, + const char *file, int line, const char *fmt, ...) +{ + va_list args; + va_start (args, fmt); + krb5int_vset_error_fl (ep, code, file, line, fmt, args); va_end (args); } void krb5int_vset_error (struct errinfo *ep, long code, const char *fmt, va_list args) +{ + krb5int_vset_error_fl(ep, code, NULL, 0, fmt, args); +} + +void +krb5int_vset_error_fl (struct errinfo *ep, long code, + const char *file, int line, + const char *fmt, va_list args) { va_list args2; - char *str = NULL; + char *str = NULL, *str2, *slash; const char *loc_fmt = NULL; #ifdef USE_KIM @@ -66,6 +85,17 @@ krb5int_vset_error (struct errinfo *ep, long code, str = NULL; } va_end(args2); + + if (str && line) { + /* Try to add file and line suffix. */ + slash = strrchr(file, '/'); + if (slash) + file = slash + 1; + if (asprintf(&str2, "%s (%s: %d)", str, file, line) > 0) { + free(str); + str = str2; + } + } /* If that failed, try using scratch_buf */ if (str == NULL) { -- cgit