]> Pileus Git - ~andy/fetchmail/commitdiff
Narrow the error() interface.
authorEric S. Raymond <esr@thyrsus.com>
Tue, 21 Oct 1997 00:30:10 +0000 (00:30 -0000)
committerEric S. Raymond <esr@thyrsus.com>
Tue, 21 Oct 1997 00:30:10 +0000 (00:30 -0000)
svn path=/trunk/; revision=1526

driver.c
fetchmail.c
fetchmail.h
options.c
rcfile_y.y
report.c

index 2c3b9a2cf92159d935c1200d1de8ef89e5989ebe..dbc97ab6bc5bfb68b88e347252176e0a0c5f4a1e 100644 (file)
--- 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);
index c6e3120bbdbbaecfe43732df35a77c920595da46..4fde4363841780fee77d9e085405f6610f22a8ef 100644 (file)
@@ -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
 
index ed43b94ac175e4371ca4ea430b6accf3931b4904..933a7cbe89f6b5dda1baecc3a12ace11f4bf0ab5 100644 (file)
@@ -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 */
index f2432ed3d140d55496dab02f7bc44c9af95f19ec..70f2584887c3b4216fc8b694aaeb6b9ebf45a087 100644 (file)
--- 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 '?':
index 13eb3d0de92779e1928eb0167bd2234e40045228..e7505cbba01e501b772d87a631ce61285a112955 100644 (file)
@@ -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;}
 
 /* 
index 9ad5cdf7b4f1bf5b2f45c7485832f7f544575873..393d69642e9c51d29f13da9eb9a3318c30e40b16 100644 (file)
--- 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)
 }
 \f
 /*
- * 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 */
+    }
 }
 \f
 /* 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);