Merge branch 'debian' into hcoop_489
[hcoop/debian/exim4.git] / src / debug.c
index ebd932f..3cd6d0c 100644 (file)
@@ -2,7 +2,7 @@
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
-/* Copyright (c) University of Cambridge 1995 - 2009 */
+/* Copyright (c) University of Cambridge 1995 - 2015 */
 /* See the file NOTICE for conditions of use and distribution. */
 
 
@@ -30,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
@@ -75,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++);
@@ -137,13 +137,36 @@ debug_printf("%s uid=%ld gid=%ld euid=%ld egid=%ld\n", s,
 *************************************************/
 
 /* There are two entries, one for use when being called directly from a
-function with a variable argument list.
+function with a variable argument list, one for prepending an indent.
 
 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. */
+
+
+/* Debug printf indented by ACL nest depth */
+void
+debug_printf_indent(const char * format, ...)
+{
+va_list ap;
+unsigned depth = acl_level + expand_level, i;
+
+if (!debug_file) return;
+if (depth > 0)
+  {
+  for (i = depth >> 2; i > 0; i--)
+    fprintf(debug_file, "   .");
+  fprintf(debug_file, "%*s", depth & 3, "");
+  }
+
+va_start(ap, format);
+debug_vprintf(format, ap);
+va_end(ap);
+}
+
 
 void
 debug_printf(const char *format, ...)
@@ -157,7 +180,9 @@ va_end(ap);
 void
 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. Don't use the
 tod_stamp() function for the timestamp, because that will overwrite the
@@ -235,6 +260,7 @@ if (debug_ptr[-1] == '\n')
   debug_ptr = debug_buffer;
   debug_prefix_length = 0;
   }
+errno = save_errno;
 }
 
 /* End of debug.c */