]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Mirror 1.1.x changes.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 25 Jul 2003 16:00:23 +0000 (16:00 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 25 Jul 2003 16:00:23 +0000 (16:00 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/branches/branch-1.2@3829 7a7537e8-13f0-0310-91df-b6672ffda945

scheduler/log.c

index cf85e816608f9a51bd0432343543d8ae08bc7dbd..efe2056190834c5bc58d5152a784c84809eef9e6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: log.c,v 1.19.2.13 2003/07/19 21:57:49 mike Exp $"
+ * "$Id: log.c,v 1.19.2.14 2003/07/25 16:00:23 mike Exp $"
  *
  *   Log file routines for the Common UNIX Printing System (CUPS).
  *
@@ -114,6 +114,7 @@ LogMessage(int        level,                /* I - Log level */
           ...)                         /* I - Additional args as needed */
 {
   int          len;                    /* Length of message */
+  char         *ptr;                   /* Pointer to message */
   va_list      ap;                     /* Argument pointer */
   static const char levels[] =         /* Log levels... */
                {
@@ -145,6 +146,7 @@ LogMessage(int        level,                /* I - Log level */
 #endif /* HAVE_VSYSLOG */
   static int   linesize = 0;           /* Size of line for output file */
   static char  *line = NULL;           /* Line for output file */
+  static char  sigbuf[1024];           /* Buffer for signal handlers */
 
 
  /*
@@ -194,50 +196,74 @@ LogMessage(int        level,              /* I - Log level */
   * Then the log message...
   */
 
-  va_start(ap, message);
-  len = vsnprintf(line, linesize, message, ap);
-  va_end(ap);
-
-  if (len >= linesize && !SignalCount)
+  if (SignalCount)
   {
-    len ++;
+   /*
+    * Processing a signal so use the static buffer...
+    */
 
-    if (len < 8192)
-      len = 8192;
-    else if (len > 65536)
-      len = 65536;
+    va_start(ap, message);
+    len = vsnprintf(sigbuf, sizeof(sigbuf), message, ap);
+    va_end(ap);
 
-    if (!linesize)
-      line = malloc(len);
-    else
-      line = realloc(line, len);
+    ptr = sigbuf;
 
-    if (line)
-      linesize = len;
-    else
+    if (len >= sizeof(sigbuf))
+      len = sizeof(sigbuf) - 1;
+  }
+  else
+  {
+   /*
+    * Not processing a signal so use the dynamic buffer...
+    */
+
+    va_start(ap, message);
+    len = vsnprintf(line, linesize, message, ap);
+    va_end(ap);
+
+    if (len >= linesize)
     {
-      cupsFilePrintf(ErrorFile,
-                     "ERROR: Unable to allocate memory for line - %s\n",
-                     strerror(errno));
-      cupsFileFlush(ErrorFile);
+      len ++;
 
-      ReleaseSignals();
+      if (len < 8192)
+       len = 8192;
+      else if (len > 65536)
+       len = 65536;
 
-      return (0);
+      if (!linesize)
+       line = malloc(len);
+      else
+       line = realloc(line, len);
+
+      if (line)
+       linesize = len;
+      else
+      {
+       cupsFilePrintf(ErrorFile,
+                       "ERROR: Unable to allocate memory for line - %s\n",
+                       strerror(errno));
+       cupsFileFlush(ErrorFile);
+
+       ReleaseSignals();
+
+       return (0);
+      }
+
+      va_start(ap, message);
+      len = vsnprintf(line, linesize, message, ap);
+      va_end(ap);
     }
 
-    va_start(ap, message);
-    len = vsnprintf(line, linesize, message, ap);
-    va_end(ap);
+    ptr = line;
+
+    if (len >= linesize)
+      len = linesize - 1;
   }
 
  /*
   * Then a newline...
   */
 
-  if (len >= linesize)
-    len = linesize - 1;
-
   cupsFilePuts(ErrorFile, line);
 
   if (len > 0 && line[len - 1] != '\n')
@@ -522,5 +548,5 @@ check_log_file(cups_file_t **log,   /* IO - Log file */
 
 
 /*
- * End of "$Id: log.c,v 1.19.2.13 2003/07/19 21:57:49 mike Exp $".
+ * End of "$Id: log.c,v 1.19.2.14 2003/07/25 16:00:23 mike Exp $".
  */