#include <stdlib.h>#include <stdio.h>#include <unistd.h>Go to the source code of this file.
Defines | |
| #define | MAXOPTS 16 |
| #define | TRY(exp) |
Functions | |
| int | main (int argc, char **argv) |
|
|
Definition at line 24 of file qmail-spamc.c. Referenced by main(). |
|
|
Value: do { \ if ((exp) == -1) { \ fprintf(stderr, "%s:%d: '%s' failed: ", \ __FILE__, \ __LINE__, \ #exp \ ); perror(NULL); \ exit(81); \ } \ } while(0) Definition at line 26 of file qmail-spamc.c. Referenced by main(). |
|
||||||||||||
|
Definition at line 38 of file qmail-spamc.c. 00039 { 00040 char *options[MAXOPTS]; 00041 char *val = NULL; 00042 int opt = 0; 00043 00044 pid_t childpid; 00045 int pfds[2]; 00046 00047 00048 #ifdef HAVE_QMAIL_RELAYCLIENT 00049 /* 00050 * bug 2927: use standard qmail-queue if this is a RELAYCLIENT 00051 */ 00052 if (getenv("RELAYCLIENT")) { 00053 TRY(execlp("qmail-queue", "qmail-queue", NULL)); 00054 } 00055 #endif 00056 00057 00058 /* create the array of options */ 00059 options[opt++] = "spamc"; /* set zeroth argument */ 00060 if ((val = getenv("SPAMDSOCK")) != NULL) { /* Unix Domain Socket path */ 00061 options[opt++] = "-U"; 00062 options[opt++] = val; 00063 } 00064 if ((val = getenv("SPAMDHOST")) != NULL) { /* remote spamd host name */ 00065 options[opt++] = "-d"; 00066 options[opt++] = val; 00067 } 00068 if ((val = getenv("SPAMDPORT")) != NULL) { /* remote spamd port number */ 00069 options[opt++] = "-p"; 00070 options[opt++] = val; 00071 } 00072 if ((val = getenv("SPAMDSSL")) != NULL) { /* use ssl for spamc/spamd */ 00073 options[opt++] = "-S"; 00074 } 00075 if ((val = getenv("SPAMDLIMIT")) != NULL) { /* message size limit */ 00076 options[opt++] = "-s"; 00077 options[opt++] = val; 00078 } 00079 if ((val = getenv("SPAMDUSER")) != NULL) { /* spamc user configuration */ 00080 options[opt++] = "-u"; 00081 options[opt++] = val; 00082 } 00083 options[opt] = NULL; /* terminate argument list */ 00084 00085 00086 TRY(pipe(pfds)); 00087 TRY(childpid = fork()); 00088 if (childpid == 0) { /* the child ... */ 00089 TRY(close(1)); /* close normal stdout */ 00090 TRY(dup(pfds[1])); /* make stdout same as pfds[1] */ 00091 TRY(close(pfds[0])); /* we don't need this */ 00092 TRY(execvp("spamc", options)); 00093 } 00094 else { /* the parent ... */ 00095 TRY(close(0)); /* close normal stdin */ 00096 TRY(dup(pfds[0])); /* make stdin same as pfds[0] */ 00097 TRY(close(pfds[1])); /* we don't need this */ 00098 TRY(execlp("qmail-queue", "qmail-queue", NULL)); 00099 } 00100 00101 /* never reached */ 00102 return 81; 00103 }
|