Index: /trunk/ChangeLog
===================================================================
--- /trunk/ChangeLog	(revision 647)
+++ /trunk/ChangeLog	(revision 648)
@@ -34,5 +34,6 @@
     Fixed by: Bas van der Vlies
 
-2.7.0
+  * report run_email2trac errors to syslog (LOG_MAIL facility) instead of printf
+    Author: Bas van der Vlies
 
 2.7.0
Index: /trunk/debian/changelog
===================================================================
--- /trunk/debian/changelog	(revision 647)
+++ /trunk/debian/changelog	(revision 648)
@@ -1,3 +1,3 @@
-email2trac (2.7.7-1) stable; urgency=low
+email2trac (2.8.0-1) stable; urgency=low
 
   * See Changelog
Index: /trunk/email2trac.spec
===================================================================
--- /trunk/email2trac.spec	(revision 647)
+++ /trunk/email2trac.spec	(revision 648)
@@ -1,5 +1,5 @@
 Summary: Utilities for converting emails to trac tickets
 Name: email2trac
-Version: 2.7.7
+Version: 2.8.0
 Release: 1
 License: Apache License 2.0
Index: /trunk/run_email2trac.c
===================================================================
--- /trunk/run_email2trac.c	(revision 647)
+++ /trunk/run_email2trac.c	(revision 648)
@@ -32,4 +32,6 @@
 #include <stdio.h>
 #include <limits.h>
+#include <syslog.h>
+
 #ifdef HAVE_INITGROUPS
 #include <grp.h>
@@ -45,102 +47,129 @@
 {
   if ( strlen(name) > 30 ) {
-    	  if ( DEBUG ) printf("MTA_USERNAME is to large; %s\n", name);
-	  exit(-1);
+    openlog("run_email2trac", LOG_PID, LOG_MAIL); 
+    syslog(LOG_ERR, "MTA_USERNAME is to large; %s\n", name);
+    closelog();
+    exit(-1);
   }
+}
+
+void email2trac_log(char *message)
+{
+    openlog("run_email2trac", LOG_PID, LOG_MAIL); 
+    syslog(LOG_ERR, message);
+    closelog();
 }
 
 int main(int argc, char** argv) {
 
-  int i,j;
-  int caller = getuid();
-  int status;
+    int i,j;
+    int caller = getuid();
+    int status; 
+    
+    char   **trac_script_args;
+    char   *python_egg_cache = NULL; 
+    struct passwd *TRAC; 
+    struct passwd *MTA;
+    struct stat script_attrs;
+    const char *trac_script = TRAC_SCRIPT_PATH "/" TRAC_SCRIPT_NAME;
 
-  char   **trac_script_args;
-  char   *python_egg_cache = NULL;
-  struct passwd *TRAC; 
-  struct passwd *MTA;
-  struct stat script_attrs;
-  const char *trac_script = TRAC_SCRIPT_PATH "/" TRAC_SCRIPT_NAME;
+    char    error_msg[1024];
  
-  /*
-  printf("trac_script = %s\n", trac_script);
-  */
+    /*
+    printf("trac_script = %s\n", trac_script);
+    */
 
-  /* First copy arguments passed to the wrapper as scripts arguments
-     after filtering out some of the possible script options */
+    /* 
+    First copy arguments passed to the wrapper as scripts arguments
+    aft er filtering out some of the possible script options 
+    */
 
-  trac_script_args = (char**) malloc((argc+1)*sizeof(char*));
-  if (trac_script_args == NULL) {
-    if ( DEBUG ) printf("malloc failed\n");
-    return 1;
-  }
-  trac_script_args[0] = TRAC_SCRIPT_NAME;
-  for (i=j=1; i<argc; i++) {
-    if ( (strcmp(argv[i],"--file") == 0) || 
-	 (strcmp(argv[i],"-f") == 0) ) {
-      i++;
-      continue;
+    trac_script_args = (char**) malloc((argc+1)*sizeof(char*));
+    if (trac_script_args == NULL) {
+        snprintf(error_msg, sizeof(error_msg), "malloc failed");
+        email2trac_log(error_msg);
+        return 1; 
+    } 
+    
+    trac_script_args[0] = TRAC_SCRIPT_NAME;
+    for (i=j=1; i<argc; i++) {
+
+        if ( (strcmp(argv[i],"--file") == 0) || 
+             (strcmp(argv[i],"-f") == 0) ) {
+            i++;
+            continue;
+        }
+        else if ( (strcmp(argv[i],"--eggcache") == 0) ||
+                  (strcmp(argv[i],"-e") == 0) ) {
+            i++;
+            python_egg_cache = argv[i];
+            continue;
+        }
+    
+        trac_script_args[j] = argv[i];
+        j++;
     }
-    else if ( (strcmp(argv[i],"--eggcache") == 0) ||
-         (strcmp(argv[i],"-e") == 0) ) {
-      i++;
-      python_egg_cache = argv[i];
-      continue;
+
+    trac_script_args[j] = NULL;
+
+    /* check caller */
+    check_username(MTA_USER);
+    MTA = getpwnam(MTA_USER); 
+    
+    if ( MTA == NULL ) {
+        snprintf(error_msg, sizeof(error_msg), "Invalid MTA user (%s)", MTA_USER);
+        email2trac_log(error_msg);
+        return -3;     /* 253 : MTA user not found */
+    }
+
+    if ( caller !=  MTA->pw_uid ) {
+        snprintf(error_msg, sizeof(error_msg), "Invalid caller UID (%d)", caller);
+        email2trac_log(error_msg);
+        return -2;     /* 254 : Invalid caller */
+    }
+  
+    /* set UID/GID and supplementary groups to be Trac (or apache) user */
+    check_username(TRAC_USER);
+    if ( TRAC = getpwnam(TRAC_USER) ) {
+#ifdef HAVE_INITGROUPS
+        if (initgroups(TRAC_USER, TRAC->pw_gid)) {
+            snprintf(error_msg, sizeof(error_msg), "initgroups failed");
+            email2trac_log(error_msg);
+            return -7;    /* 249 : Can't set supplementary groups */
+        }
+#endif
+        if (setgid(TRAC->pw_gid) || setuid(TRAC->pw_uid)) {
+            snprintf(error_msg, sizeof(error_msg), "setgid or setuid failed");
+            email2trac_log(error_msg);
+            return -5;   /* 251: Can't set gid or uid */
+        }
+    } 
+    else {
+            snprintf(error_msg, sizeof(error_msg), "Invalid Trac user (%s)", TRAC_USER);
+            email2trac_log(error_msg);
+            return -6;     /* 250 : Trac user not found */
     }
     
-    trac_script_args[j] = argv[i];
-    j++;
-  }
-  trac_script_args[j] = NULL;
+    /* Check that script exists */
+    if ( stat(trac_script,&script_attrs) ) {
+        snprintf(error_msg, sizeof(error_msg), "Script not found (%s)", trac_script);
+        email2trac_log(error_msg);
+        return -4;    /* 252 : script not found */
+    }
+ 
+    /* Set PYTHON_EGG_CACHE env variable if we have been told to do so */
+    if ( python_egg_cache != NULL ) {
+        setenv("PYTHON_EGG_CACHE",python_egg_cache ,1);
+    }
 
-  /* Check caller */
-  check_username(MTA_USER);
-  MTA = getpwnam(MTA_USER);
-
-  if ( MTA == NULL ) {
-    if ( DEBUG ) printf("Invalid MTA user (%s)\n", MTA_USER);
-    return -3;     /* 253 : MTA user not found */
-  }
-
-  if ( caller !=  MTA->pw_uid ) {
-    if ( DEBUG ) printf("Invalid caller UID (%d)\n",caller);
-    return -2;     /* 254 : Invalid caller */
-  }
-  
-  /* set UID/GID and supplementary groups to be Trac (or apache) user */
-  check_username(TRAC_USER);
-  if ( TRAC = getpwnam(TRAC_USER) ) {
-#ifdef HAVE_INITGROUPS
-    if (initgroups(TRAC_USER, TRAC->pw_gid)) {
-      if ( DEBUG ) printf("initgroups failed\n");
-      return -7;    /* 249 : Can't set supplementary groups */
-    }
-#endif
-    if (setgid(TRAC->pw_gid) || setuid(TRAC->pw_uid)) {
-      if ( DEBUG ) printf("setgid or setuid failed\n");
-      return -5;   /* 251: Can't set gid or uid */
-    }
-  } else {
-    if ( DEBUG ) printf("Invalid Trac user (%s)\n",TRAC_USER);
-    return -6;     /* 250 : Trac user not found */
-  }
-	 
-  /* Check that script exists */
-  if ( stat(trac_script,&script_attrs) ) {
-    if ( DEBUG ) printf("Script not found (%s)\n",trac_script);
-    return -4;    /* 252 : script not found */
-  }
+    /* Execute script */
+    status = execv(trac_script, trac_script_args);
  
-  /* Set PYTHON_EGG_CACHE env variable if we have been told to do so */
-  if ( python_egg_cache != NULL ) {
-    setenv("PYTHON_EGG_CACHE",python_egg_cache ,1);
-  }
-
-  /* Execute script */
-  status = execv(trac_script, trac_script_args);
-  
-  if ( DEBUG ) printf("Script %s execution failure (error=%d). Check permission and interpreter path.\n",trac_script,status);
-  return -1;     /* 255 : should never reach this point */
-
+    /* should never reach this point */
+    snprintf(error_msg, sizeof(error_msg), 
+        "Script %s execution failure (error=%d). Check permission and interpreter path.", 
+        trac_script, status);
+    email2trac_log(error_msg);
+    return -1; 
 }
 
