Hi,

I think I came across a bug in the LOG function.
I use logging to a file and lines like these are present:

22814: [12/03/2009 09:49:45] Unable to open file for writing: %s: %s

Here's a patch that seems to work for me (i.e. not really tested):

diff --git a/src/error.c b/src/error.c
index e58fe8d..55e2bfd 100644
--- a/src/error.c
+++ b/src/error.c
@@ -69,8 +69,9 @@ pthread_mutex_t  __syslog_lock;
 void
 LOG(int priority, const char *err, ... )
 {
-#ifdef USE_SYSLOG
+#if defined(USE_SYSLOG) || defined(LOGFILE)
   va_list ap;
+  va_start(ap, err);
 #endif
 #ifdef LOGFILE
   char date[128];
@@ -84,24 +85,29 @@ LOG(int priority, const char *err, ... )
 #endif
 
 #ifdef USE_SYSLOG
-  va_start (ap, err);
   openlog ("dspam", LOG_PID | LOG_CONS | LOG_NOWAIT, LOG_MAIL);
   vsyslog (priority, err, ap);
   closelog ();
-  va_end (ap);
 #endif
 
 #ifdef LOGFILE
+  char err_str[128];
+  vsnprintf(err_str, 128, err, ap);
+
   file = fopen(LOGFILE, "a");
   if (file) {
-    fprintf(file, "%ld: [%s] %s\n", (long) getpid(), format_date_r(date), err);
+    fprintf(file, "%ld: [%s] %s\n", (long) getpid(), format_date_r(date), 
err_str);
     fclose(file);
   } else {
     fprintf(stderr, "%s: %s", LOGFILE, strerror(errno));
-    fprintf(stderr, "%ld: [%s] %s\n", (long)getpid(), format_date_r(date), 
err);
+    fprintf(stderr, "%ld: [%s] %s\n", (long) getpid(), format_date_r(date), 
err_str);
   }
 #endif
 
+#if defined(USE_SYSLOG) || defined(LOGFILE)
+  va_end(ap);
+#endif
+
 #ifdef DAEMON 
 #if defined(USE_SYSLOG) && defined(LOGFILE)
   pthread_mutex_unlock(&__syslog_lock);


Jiri Novosad

------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing. 
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
Dspam-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dspam-user

Reply via email to