]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bugzilla #177
authorwessels <>
Wed, 27 Jun 2001 03:07:09 +0000 (03:07 +0000)
committerwessels <>
Wed, 27 Jun 2001 03:07:09 +0000 (03:07 +0000)
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.

src/debug.cc

index 649607df1aa583373a68e2ed9056a72ef8598aa8..379d91e61c32040bda2d31f0809ae9db630c16e7 100644 (file)
@@ -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)
 {