From 97af3b28e935b786e61d46df1a0d73fd4c9a4eba Mon Sep 17 00:00:00 2001
From: "Eric S. Raymond" <esr@thyrsus.com>
Date: Tue, 21 Oct 1997 00:30:10 +0000
Subject: Narrow the error() interface.

svn path=/trunk/; revision=1526
---
 driver.c    |  5 ++++-
 fetchmail.c |  4 ++--
 fetchmail.h |  2 +-
 options.c   |  2 +-
 rcfile_y.y  |  4 ++--
 report.c    | 50 ++++++++++++++++++++++++++++++++++++--------------
 6 files changed, 46 insertions(+), 21 deletions(-)

diff --git a/driver.c b/driver.c
index 2c3b9a2c..dbc97ab6 100644
--- a/driver.c
+++ b/driver.c
@@ -1448,7 +1448,10 @@ const struct method *proto;	/* protocol method table */
     tagnum = 0;
     tag[0] = '\0';	/* nuke any tag hanging out from previous query */
     ok = 0;
-    error_init(poll_interval == 0 && !logfile);
+    if (errors_to_syslog)
+	error_init(-1);
+    else
+	error_init(poll_interval == 0 && !logfile);
 
     /* set up the server-nonresponse timeout */
     sigsave = signal(SIGALRM, timeout_handler);
diff --git a/fetchmail.c b/fetchmail.c
index c6e3120b..4fde4363 100644
--- a/fetchmail.c
+++ b/fetchmail.c
@@ -167,7 +167,7 @@ int main (int argc, char **argv)
 	if (logfile)
 	    printf("Logfile is %s\n", logfile);
 #if defined(HAVE_SYSLOG)
-	if (use_syslog)
+	if (errors_to_syslog)
 	    printf("Progress messages will be logged via syslog\n");
 #endif
 	if (use_invisible)
@@ -321,7 +321,7 @@ int main (int argc, char **argv)
      * Maybe time to go to demon mode...
      */
 #if defined(HAVE_SYSLOG)
-    if (use_syslog)
+    if (errors_to_syslog)
     	openlog(program_name, LOG_PID, LOG_MAIL);
 #endif
 
diff --git a/fetchmail.h b/fetchmail.h
index ed43b94a..933a7cbe 100644
--- a/fetchmail.h
+++ b/fetchmail.h
@@ -208,7 +208,7 @@ extern int yydebug;		/* enable parse debugging */
 extern int poll_interval;	/* poll interval in seconds */
 extern flag nodetach;		/* if TRUE, don't detach daemon process */
 extern char *logfile;		/* log file for daemon mode */
-extern flag use_syslog;		/* if syslog was set */
+extern flag errors_to_syslog;	/* if syslog was set */
 extern flag use_invisible;	/* if invisible was set */
 extern flag quitmode;		/* if --quit was set */
 extern flag check_only;		/* if --check was set */
diff --git a/options.c b/options.c
index f2432ed3..70f25848 100644
--- a/options.c
+++ b/options.c
@@ -340,7 +340,7 @@ struct query *ctl;	/* option record to be initialized */
 	    break;
 
 	case LA_SYSLOG:
-	    use_syslog = TRUE;
+	    errors_to_syslog = TRUE;
 	    break;
 
 	case '?':
diff --git a/rcfile_y.y b/rcfile_y.y
index 13eb3d0d..e7505cbb 100644
--- a/rcfile_y.y
+++ b/rcfile_y.y
@@ -29,7 +29,7 @@ struct query cmd_opts;		/* where to put command-line info */
 /* parser sets these */
 int poll_interval;		/* poll interval in seconds */
 char *logfile;			/* log file for daemon mode */
-flag use_syslog;		/* if syslog was set */
+flag errors_to_syslog;		/* if syslog was set */
 flag use_invisible;		/* if invisible was set */
 struct query *querylist;	/* head of server list (globally visible) */
 
@@ -83,7 +83,7 @@ optmap		: MAP | /* EMPTY */;
 /* future global options should also have the form SET <name> optmap <value> */
 statement	: SET LOGFILE optmap STRING	{logfile = xstrdup($4);}
 		| SET DAEMON optmap NUMBER	{poll_interval = $4;}
-		| SET SYSLOG			{use_syslog = TRUE;}
+		| SET SYSLOG			{errors_to_syslog = TRUE;}
 		| SET INVISIBLE			{use_invisible = TRUE;}
 
 /* 
diff --git a/report.c b/report.c
index 9ad5cdf7..393d6964 100644
--- a/report.c
+++ b/report.c
@@ -59,12 +59,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 void exit ();
 #endif
 
-#include "fetchmail.h"
-
 #ifndef _
 # define _(String) String
 #endif
 
+#include "fetchmail.h"
+#define MALLOC(n)	xmalloc(n)	
+#define REALLOC(n,s)	xrealloc(n,s)	
+
 /* If NULL, error will flush stdout, then print on stderr the program
    name, a colon and a space.  Otherwise, error will call this
    function without parameters instead.  */
@@ -79,10 +81,12 @@ static unsigned int partial_message_size = 0;
 static unsigned int partial_message_size_used = 0;
 static char *partial_message;
 static unsigned use_stderr;
+static unsigned int use_syslog;
 
 /* This variable is incremented each time `error' is called.  */
 unsigned int error_message_count;
 
+
 #ifdef _LIBC
 /* In the GNU C library, there is a predefined variable for this.  */
 
@@ -246,14 +250,32 @@ error (status, errnum, message, va_alist)
 }
 
 /*
- * Calling error_init(TRUE) causes error_build and error_complete to write
+ * Calling error_init(1) causes error_build and error_complete to write
  * to stderr without buffering.  This is needed for the ticker dots to
  * work correctly.
  */
-void error_init(foreground)
-int foreground;
+void error_init(int mode)
 {
-    use_stderr = foreground;
+    switch(mode)
+    {
+    case 0:			/* stderr, buffered */
+    default:
+	use_stderr = 0;
+	use_syslog = 0;
+	break;
+
+    case 1:			/* stderr, unbuffered */
+	use_stderr = 1;
+	use_syslog = 0;
+	break;
+
+#ifdef HAVE_SYSLOG
+    case -1:			/* syslogd */
+	use_stderr = 0;
+	use_syslog = 1;
+	break;
+#endif /* HAVE_SYSLOG */
+    }
 }
 
 /* Build an error message by appending MESSAGE, which is a printf-style
@@ -285,13 +307,13 @@ error_build (message, va_alist)
     {
       partial_message_size_used = 0;
       partial_message_size = 2048;
-      partial_message = xmalloc (partial_message_size);
+      partial_message = MALLOC (partial_message_size);
     }
   else
     if (partial_message_size - partial_message_size_used < 1024)
       {
         partial_message_size += 2048;
-        partial_message = xrealloc (partial_message, partial_message_size);
+        partial_message = REALLOC (partial_message, partial_message_size);
       }
 
 #if defined(VA_START)
@@ -310,7 +332,7 @@ error_build (message, va_alist)
 	}
 
       partial_message_size += 2048;
-      partial_message = xrealloc (partial_message, partial_message_size);
+      partial_message = REALLOC (partial_message, partial_message_size);
     }
 #else
   vsprintf (partial_message + partial_message_size_used, message, args);
@@ -339,7 +361,7 @@ error_build (message, va_alist)
 	}
 
       partial_message_size += 2048;
-      partial_message = xrealloc (partial_message, partial_message_size);
+      partial_message = REALLOC (partial_message, partial_message_size);
     }
 #else
   sprintf (partial_message + partial_message_size_used, message, a1, a2, a3, a4, a5, a6, a7, a8);
@@ -387,13 +409,13 @@ error_complete (status, errnum, message, va_alist)
     {
       partial_message_size_used = 0;
       partial_message_size = 2048;
-      partial_message = xmalloc (partial_message_size);
+      partial_message = MALLOC (partial_message_size);
     }
   else
     if (partial_message_size - partial_message_size_used < 1024)
       {
         partial_message_size += 2048;
-        partial_message = xrealloc (partial_message, partial_message_size);
+        partial_message = REALLOC (partial_message, partial_message_size);
       }
 
 #if defined(VA_START)
@@ -412,7 +434,7 @@ error_complete (status, errnum, message, va_alist)
 	}
 
       partial_message_size += 2048;
-      partial_message = xrealloc (partial_message, partial_message_size);
+      partial_message = REALLOC (partial_message, partial_message_size);
     }
 #else
   vsprintf (partial_message + partial_message_size_used, message, args);
@@ -441,7 +463,7 @@ error_complete (status, errnum, message, va_alist)
 	}
 
       partial_message_size += 2048;
-      partial_message = xrealloc (partial_message, partial_message_size);
+      partial_message = REALLOC (partial_message, partial_message_size);
     }
 #else
   sprintf (partial_message + partial_message_size_used, message, a1, a2, a3, a4, a5, a6, a7, a8);
-- 
cgit v1.2.3