From: wessels <> Date: Wed, 27 Jun 2001 03:07:09 +0000 (+0000) Subject: Bugzilla #177 X-Git-Tag: SQUID_3_0_PRE1~1485 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=811ef305e5ef84212224238bb254efc6f654e98e;p=thirdparty%2Fsquid.git Bugzilla #177 Joe Laffey points out that on LinuxPPC2000 (and probably QNX) calling something like vsnprintf() or similar leaves the "args" parameter unusable. Calling it again with the same "args" results in a coredump. We have code to get around this in QNX by making a copy of the args and calling va_start() twice. This patch tries to address the problem by splitting the _db_print() function into smaller parts, and passing the args as parameters to the separate _db_print_file, _db_print_stderr, and _db_print_syslog functions. --- diff --git a/src/debug.cc b/src/debug.cc index 649607df1a..379d91e61c 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -1,6 +1,6 @@ /* - * $Id: debug.cc,v 1.81 2001/02/07 18:56:52 hno Exp $ + * $Id: debug.cc,v 1.82 2001/06/26 21:07:09 wessels Exp $ * * DEBUG: section 0 Debug Routines * AUTHOR: Harvest Derived @@ -39,17 +39,18 @@ static char *debug_log_file = NULL; static int Ctx_Lock = 0; static const char *debugLogTime(time_t); static void ctx_print(void); +#if HAVE_SYSLOG +static void _db_print_syslog(const char *format, va_list args); +#endif +static void _db_print_stderr(const char *format, va_list args); +static void _db_print_file(const char *format, va_list args); -#if STDC_HEADERS void +#if STDC_HEADERS _db_print(const char *format,...) { -#if defined(__QNX__) - va_list eargs; -#endif va_list args; #else -void _db_print(va_alist) va_dcl { @@ -57,58 +58,62 @@ _db_print(va_alist) const char *format = NULL; #endif LOCAL_ARRAY(char, f, BUFSIZ); -#if HAVE_SYSLOG - LOCAL_ARRAY(char, tmpbuf, BUFSIZ); -#endif - #if STDC_HEADERS va_start(args, format); -#if defined(__QNX__) - va_start(eargs, format); -#endif #else - va_start(args); format = va_arg(args, const char *); #endif + snprintf(f, BUFSIZ, "%s| %s", + debugLogTime(squid_curtime), + format); + _db_print_file(f, args); + _db_print_stderr(f, args); +#if HAVE_SYSLOG + _db_print_syslog(format, args); +#endif + va_end(args); +} +static void +_db_print_file(const char *format, va_list args) +{ if (debug_log == NULL) return; /* give a chance to context-based debugging to print current context */ if (!Ctx_Lock) ctx_print(); - snprintf(f, BUFSIZ, "%s| %s", - debugLogTime(squid_curtime), - format); -#if HAVE_SYSLOG - /* level 0,1 go to syslog */ - if (_db_level <= 1 && opt_syslog_enable) { - tmpbuf[0] = '\0'; - vsnprintf(tmpbuf, BUFSIZ, format, args); - tmpbuf[BUFSIZ - 1] = '\0'; - syslog(_db_level == 0 ? LOG_WARNING : LOG_NOTICE, "%s", tmpbuf); - } -#endif /* HAVE_SYSLOG */ - /* write to log file */ -#if defined(__QNX__) - vfprintf(debug_log, f, eargs); -#else - vfprintf(debug_log, f, args); -#endif + vfprintf(debug_log, format, args); if (!Config.onoff.buffered_logs) fflush(debug_log); - if (opt_debug_stderr >= _db_level && debug_log != stderr) { -#if defined(__QNX__) - vfprintf(stderr, f, eargs); -#else - vfprintf(stderr, f, args); -#endif - } -#if defined(__QNX__) - va_end(eargs); -#endif - va_end(args); } +static void +_db_print_stderr(const char *format, va_list args) +{ + if (opt_debug_stderr < _db_level) + return; + if (debug_log == stderr) + return; + vfprintf(stderr, format, args); +} + +#if HAVE_SYSLOG +static void +_db_print_syslog(const char *format, va_list args) +{ + LOCAL_ARRAY(char, tmpbuf, BUFSIZ); + /* level 0,1 go to syslog */ + if (_db_level > 1) + return; + if (0 == opt_syslog_enable) + return; + tmpbuf[0] = '\0'; + vsnprintf(tmpbuf, BUFSIZ, format, args); + tmpbuf[BUFSIZ - 1] = '\0'; + syslog(_db_level == 0 ? LOG_WARNING : LOG_NOTICE, "%s", tmpbuf); +} +#endif /* HAVE_SYSLOG */ + static void debugArg(const char *arg) {