svn rev #22291: trunk/src/ include/ lib/krb5/ lib/krb5/krb/ util/support/

ghudson@MIT.EDU ghudson at MIT.EDU
Wed Apr 29 19:21:21 EDT 2009


http://src.mit.edu/fisheye/changelog/krb5/?cs=22291
Commit By: ghudson
Log Message:
ticket: 6479
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.



Changed Files:
U   trunk/src/include/k5-err.h
U   trunk/src/include/k5-int.h
U   trunk/src/lib/krb5/krb/kerrs.c
U   trunk/src/lib/krb5/libkrb5.exports
U   trunk/src/util/support/errors.c
U   trunk/src/util/support/libkrb5support-fixed.exports
Modified: trunk/src/include/k5-err.h
===================================================================
--- trunk/src/include/k5-err.h	2009-04-29 00:31:50 UTC (rev 22290)
+++ trunk/src/include/k5-err.h	2009-04-29 23:21:21 UTC (rev 22291)
@@ -65,6 +65,22 @@
     __attribute__((__format__(__printf__, 3, 0)))
 #endif
     ;
+void
+krb5int_set_error_fl (struct errinfo *ep, long code,
+		      const char *file, int line,
+		      const char *fmt, ...)
+#if !defined(__cplusplus) && (__GNUC__ > 2)
+    __attribute__((__format__(__printf__, 5, 6)))
+#endif
+    ;
+void
+krb5int_vset_error_fl (struct errinfo *ep, long code,
+		       const char *file, int line,
+		       const char *fmt, va_list args)
+#if !defined(__cplusplus) && (__GNUC__ > 2)
+    __attribute__((__format__(__printf__, 5, 0)))
+#endif
+    ;
 const char *
 krb5int_get_error (struct errinfo *ep, long code);
 void
@@ -74,4 +90,9 @@
 void
 krb5int_set_error_info_callout_fn (const char *(KRB5_CALLCONV *f)(long));
 
+#ifdef DEBUG_ERROR_LOCATIONS
+#define krb5int_set_error(ep, code, ...) \
+    krb5int_set_error_fl(ep, code, __FILE__, __LINE__, __VA_ARGS__)
+#endif
+
 #endif /* K5_ERR_H */

Modified: trunk/src/include/k5-int.h
===================================================================
--- trunk/src/include/k5-int.h	2009-04-29 00:31:50 UTC (rev 22290)
+++ trunk/src/include/k5-int.h	2009-04-29 23:21:21 UTC (rev 22291)
@@ -2797,4 +2797,9 @@
 		 const krb5_keyblock *privsvr_key,
 		 krb5_data *data);
 
+#ifdef DEBUG_ERROR_LOCATIONS
+#define krb5_set_error_message(ctx, code, ...) \
+    krb5_set_error_message_fl(ctx, code, __FILE__, __LINE__, __VA_ARGS__)
+#endif
+
 #endif /* _KRB5_INT_H */

Modified: trunk/src/lib/krb5/krb/kerrs.c
===================================================================
--- trunk/src/lib/krb5/krb/kerrs.c	2009-04-29 00:31:50 UTC (rev 22290)
+++ trunk/src/lib/krb5/krb/kerrs.c	2009-04-29 23:21:21 UTC (rev 22291)
@@ -35,6 +35,7 @@
 #endif
 #endif
 
+#undef krb5_set_error_message
 void KRB5_CALLCONV_C
 krb5_set_error_message (krb5_context ctx, krb5_error_code code,
 			const char *fmt, ...)
@@ -57,6 +58,28 @@
     va_end (args);
 }
 
+void KRB5_CALLCONV_C
+krb5_set_error_message_fl (krb5_context ctx, krb5_error_code code,
+			   const char *file, int line, const char *fmt, ...)
+{
+    va_list args;
+    if (ctx == NULL)
+	return;
+    va_start (args, fmt);
+#ifdef DEBUG
+    if (ERROR_MESSAGE_DEBUG())
+	fprintf(stderr,
+		"krb5_set_error_message(ctx=%p/err=%p, code=%ld, ...)\n",
+		ctx, &ctx->err, (long) code);
+#endif
+    krb5int_vset_error_fl (&ctx->err, code, file, line, fmt, args);
+#ifdef DEBUG
+    if (ERROR_MESSAGE_DEBUG())
+	fprintf(stderr, "->%s\n", ctx->err.msg);
+#endif
+    va_end (args);
+}
+
 void KRB5_CALLCONV
 krb5_vset_error_message (krb5_context ctx, krb5_error_code code,
 			 const char *fmt, va_list args)

Modified: trunk/src/lib/krb5/libkrb5.exports
===================================================================
--- trunk/src/lib/krb5/libkrb5.exports	2009-04-29 00:31:50 UTC (rev 22290)
+++ trunk/src/lib/krb5/libkrb5.exports	2009-04-29 23:21:21 UTC (rev 22291)
@@ -487,6 +487,7 @@
 krb5_set_default_tgs_enctypes
 krb5_set_default_tgs_ktypes
 krb5_set_error_message
+krb5_set_error_message_fl
 krb5_set_password
 krb5_set_password_using_ccache
 krb5_set_principal_realm

Modified: trunk/src/util/support/errors.c
===================================================================
--- trunk/src/util/support/errors.c	2009-04-29 00:31:50 UTC (rev 22290)
+++ trunk/src/util/support/errors.c	2009-04-29 23:21:21 UTC (rev 22291)
@@ -34,21 +34,40 @@
 #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 @@
 	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) {

Modified: trunk/src/util/support/libkrb5support-fixed.exports
===================================================================
--- trunk/src/util/support/libkrb5support-fixed.exports	2009-04-29 00:31:50 UTC (rev 22290)
+++ trunk/src/util/support/libkrb5support-fixed.exports	2009-04-29 23:21:21 UTC (rev 22291)
@@ -24,6 +24,8 @@
 krb5int_mutex_unlock
 krb5int_set_error
 krb5int_vset_error
+krb5int_set_error_fl
+krb5int_vset_error_fl
 krb5int_get_error
 krb5int_free_error
 krb5int_clear_error




More information about the cvs-krb5 mailing list