You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by ms...@apache.org on 2004/02/16 13:02:04 UTC

svn commit: rev 6691 - incubator/spamassassin/trunk/spamc

Author: mss
Date: Mon Feb 16 04:02:02 2004
New Revision: 6691

Modified:
   incubator/spamassassin/trunk/spamc/qmail-spamc.c
Log:
Got rid of warnings, made it fail a bit more gracefully.


Modified: incubator/spamassassin/trunk/spamc/qmail-spamc.c
==============================================================================
--- incubator/spamassassin/trunk/spamc/qmail-spamc.c	(original)
+++ incubator/spamassassin/trunk/spamc/qmail-spamc.c	Mon Feb 16 04:02:02 2004
@@ -21,66 +21,72 @@
 
 #define MAXOPTS 16
 
-int main()
+#define TRY(exp) do {                                                         \
+          if ((exp) == -1) {                                                  \
+            printf("%s:%d: '%s' failed: ",                                    \
+              __FILE__,                                                       \
+              __LINE__,                                                       \
+              #exp                                                            \
+            ); perror(NULL);                                                  \
+            exit(81);                                                         \
+          }                                                                   \
+        } while(0)
+
+int main(int argc, char **argv)
 {
     int pfds[2];
-    int childpid;
-    char *socket = getenv("SPAMDSOCK");	/* Unix Domain Socket path  */
-    char *host = getenv("SPAMDHOST");	/* remote spamd host name   */
-    char *port = getenv("SPAMDPORT");	/* remote spamd host port   */
-    char *ssl = getenv("SPAMDSSL");	/* use ssl for spamc/spamd  */
-    char *limit = getenv("SPAMDLIMIT");	/* message size limit       */
-    char *user = getenv("SPAMDUSER");	/* spamc user configuration */
+    pid_t childpid;
+    char *socket = getenv("SPAMDSOCK");   /* Unix Domain Socket path  */
+    char *host = getenv("SPAMDHOST");     /* remote spamd host name   */
+    char *port = getenv("SPAMDPORT");     /* remote spamd host port   */
+    char *ssl = getenv("SPAMDSSL");       /* use ssl for spamc/spamd  */
+    char *limit = getenv("SPAMDLIMIT");   /* message size limit       */
+    char *user = getenv("SPAMDUSER");     /* spamc user configuration */
     char *options[MAXOPTS];
     int opt = 0;
 
     /* create the array of options */
-    options[opt++] = "spamc";	/* zeroth argument */
+    options[opt++] = "spamc";             /* set zeroth argument */
     if (socket) {
-	options[opt++] = "-U";
-	options[opt++] = socket;
+        options[opt++] = "-U";
+        options[opt++] = socket;
     }
     if (host) {
-	options[opt++] = "-d";
-	options[opt++] = host;
+        options[opt++] = "-d";
+        options[opt++] = host;
     }
     if (port) {
-	options[opt++] = "-p";
-	options[opt++] = port;
+        options[opt++] = "-p";
+        options[opt++] = port;
     }
     if (ssl) {
-	options[opt++] = "-S";
+        options[opt++] = "-S";
     }
     if (limit) {
-	options[opt++] = "-s";
-	options[opt++] = limit;
+        options[opt++] = "-s";
+        options[opt++] = limit;
     }
     if (user) {
-	options[opt++] = "-u";
-	options[opt++] = user;
+        options[opt++] = "-u";
+        options[opt++] = user;
     }
     options[opt] = NULL;
 
-    if (pipe(pfds) == -1) {
-	perror("Failed to create pipe; quitting\n");
-	exit(1);
-    }
-
-    if ((childpid = fork()) == -1) {
-	perror("Failed to fork; quitting\n");
-	exit(2);
-    }
-
-    if (childpid == 0) {
-	close(1);		/* close normal stdout */
-	dup(pfds[1]);		/* make stdout same as pfds[1] */
-	close(pfds[0]);		/* we don't need this */
-	execvp("spamc", options);
-    }
-    else {
-	close(0);		/* close normal stdin */
-	dup(pfds[0]);		/* make stdin same as pfds[0] */
-	close(pfds[1]);		/* we don't need this */
-	execlp("qmail-queue", "qmail-queue", NULL);
-    }
+    TRY(pipe(pfds));
+    TRY(childpid = fork());
+    if (childpid == 0) {                /* the child ... */
+        TRY(close(1));                    /* close normal stdout */
+        TRY(dup(pfds[1]));                /* make stdout same as pfds[1] */
+        TRY(close(pfds[0]));              /* we don't need this */
+        TRY(execvp("spamc", options));
+    }
+    else {                              /* the parent ... */
+        TRY(close(0));                    /* close normal stdin */
+        TRY(dup(pfds[0]));                /* make stdin same as pfds[0] */
+        TRY(close(pfds[1]));              /* we don't need this */
+        TRY(execlp("qmail-queue", "qmail-queue", NULL));
+    }
+    
+    /* never reached */
+    return 81;
 }