Fix error logged for send failure
[exim.git] / src / src / debug.c
index e3d43641bf7f9851b9089a53265612a0f40c1a0f..8f9359b15837b9702a9e6616d3cd583bdd21e6d5 100644 (file)
@@ -1,10 +1,8 @@
-/* $Cambridge: exim/src/src/debug.c,v 1.3 2005/01/04 10:00:42 ph10 Exp $ */
-
 /*************************************************
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
-/* Copyright (c) University of Cambridge 1995 - 2005 */
+/* Copyright (c) University of Cambridge 1995 - 2015 */
 /* See the file NOTICE for conditions of use and distribution. */
 
 
@@ -32,7 +30,7 @@ static uschar tree_printline[tree_printlinesize];
 
 Arguments:
   p          tree node
-  pos        amount of indenting & vertical bars to pring
+  pos        amount of indenting & vertical bars to print
   barswitch  if TRUE print | at the pos value
 
 Returns:     nothing
@@ -77,7 +75,7 @@ Returns:     nothing
 */
 
 void
-debug_print_argv(uschar **argv)
+debug_print_argv(const uschar ** argv)
 {
 debug_printf("exec");
 while (*argv != NULL) debug_printf(" %.256s", *argv++);
@@ -145,10 +143,11 @@ If debug_pid is nonzero, print the pid at the start of each line. This is for
 tidier output when running parallel remote deliveries with debugging turned on.
 Must do the whole thing with a single printf and flush, as otherwise output may
 get interleaved. Since some calls to debug_printf() don't end with newline,
-we save up the text until we do get the newline. */
+we save up the text until we do get the newline.
+Take care to not disturb errno. */
 
 void
-debug_printf(char *format, ...)
+debug_printf(const char *format, ...)
 {
 va_list ap;
 va_start(ap, format);
@@ -157,18 +156,25 @@ va_end(ap);
 }
 
 void
-debug_vprintf(char *format, va_list ap)
+debug_vprintf(const char *format, va_list ap)
 {
-if (debug_file == NULL) return;
+int save_errno = errno;
+
+if (!debug_file) return;
 
-/* Various things can be inserted at the start of a line. */
+/* Various things can be inserted at the start of a line. Don't use the
+tod_stamp() function for the timestamp, because that will overwrite the
+timestamp buffer, which may contain something useful. (This was a bug fix: the
++memory debugging with +timestamp did cause a problem.) */
 
 if (debug_ptr == debug_buffer)
   {
   DEBUG(D_timestamp)
     {
-    uschar *ts = tod_stamp(tod_log_bare);
-    sprintf(CS debug_ptr, "%s ", ts + 11);
+    time_t now = time(NULL);
+    struct tm *t = timestamps_utc? gmtime(&now) : localtime(&now);
+    (void) sprintf(CS debug_ptr, "%02d:%02d:%02d ", t->tm_hour, t->tm_min,
+      t->tm_sec);
     while(*debug_ptr != 0) debug_ptr++;
     }
 
@@ -232,6 +238,7 @@ if (debug_ptr[-1] == '\n')
   debug_ptr = debug_buffer;
   debug_prefix_length = 0;
   }
+errno = save_errno;
 }
 
 /* End of debug.c */