From: Ken Raeburn Date: Wed, 14 Mar 2007 00:26:57 +0000 (+0000) Subject: * sendto_kdc.c (default_debug_handler): If writing to a log file, keep X-Git-Tag: krb5-1.7-alpha1~1261 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=47c316a300fd057dd220552fa159d002ab98a3fe;p=krb5.git * sendto_kdc.c (default_debug_handler): If writing to a log file, keep it open and unbuffered instead of always opening and closing. When the format string has characters to be copied literally to the output, write them all at once instead of individually. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@19222 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/os/sendto_kdc.c b/src/lib/krb5/os/sendto_kdc.c index 764aafe18..78bb419bd 100644 --- a/src/lib/krb5/os/sendto_kdc.c +++ b/src/lib/krb5/os/sendto_kdc.c @@ -66,12 +66,14 @@ int krb5int_debug_sendto_kdc = 0; static void default_debug_handler (const void *data, size_t len) { #if 0 - FILE *logfile; - logfile = fopen("/tmp/sendto_kdc.log", "a"); - if (logfile == NULL) - return; + static FILE *logfile; + if (logfile == NULL) { + logfile = fopen("/tmp/sendto_kdc.log", "a"); + if (logfile == NULL) + return; + setbuf(logfile, NULL); + } fwrite(data, 1, len, logfile); - fclose(logfile); #else fwrite(data, 1, len, stderr); /* stderr is unbuffered */ @@ -124,9 +126,21 @@ krb5int_debug_fprint (const char *fmt, ...) for (; *fmt; fmt++) { if (*fmt != '%') { - /* Possible optimization: Look for % and print all chars - up to it in one call. */ - put(fmt, 1); + const char *fmt2; + size_t len; + for (fmt2 = fmt+1; *fmt2; fmt2++) + if (*fmt2 == '%') + break; + len = fmt2 - fmt; + if (0) { + FILE *f = fopen("/dev/pts/0", "w+"); + if (f) { + fprintf(f, "krb5int_debug_fprint: format <%s> fmt2 <%s> put %lu next <%s>\n", + fmt, fmt2, (unsigned long) len, fmt+len-1); + } + } + put(fmt, len); + fmt += len - 1; /* then fmt++ in loop header */ continue; } /* After this, always processing a '%' sequence. */