summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2015-07-27 18:47:13 +0200
committermanuel <manuel@mausz.at>2015-07-27 18:47:13 +0200
commit328b68e47ed505907d8bc9b3246bda99a83e6f42 (patch)
tree33311db36fe92e9e681ccb7f87d1c597e08fee52
parent6fc0d9657d169aea8e05874c7f953f47c82deb33 (diff)
downloadqmail-328b68e47ed505907d8bc9b3246bda99a83e6f42.tar.gz
qmail-328b68e47ed505907d8bc9b3246bda99a83e6f42.tar.bz2
qmail-328b68e47ed505907d8bc9b3246bda99a83e6f42.zip
[PATCH] qmail queue custom error patch
see google qmail-queue-custom-error-v2.patch
-rw-r--r--qmail.c26
-rw-r--r--qmail.h1
2 files changed, 26 insertions, 1 deletions
diff --git a/qmail.c b/qmail.c
index 186c092..e61260f 100644
--- a/qmail.c
+++ b/qmail.c
@@ -23,22 +23,32 @@ struct qmail *qq;
23{ 23{
24 int pim[2]; 24 int pim[2];
25 int pie[2]; 25 int pie[2];
26 int pierr[2];
26 27
27 setup_qqargs(); 28 setup_qqargs();
28 29
29 if (pipe(pim) == -1) return -1; 30 if (pipe(pim) == -1) return -1;
30 if (pipe(pie) == -1) { close(pim[0]); close(pim[1]); return -1; } 31 if (pipe(pie) == -1) { close(pim[0]); close(pim[1]); return -1; }
31 32 if (pipe(pierr) == -1) {
33 close(pim[0]); close(pim[1]);
34 close(pie[0]); close(pie[1]);
35 close(pierr[0]); close(pierr[1]);
36 return -1;
37 }
38
32 switch(qq->pid = vfork()) { 39 switch(qq->pid = vfork()) {
33 case -1: 40 case -1:
41 close(pierr[0]); close(pierr[1]);
34 close(pim[0]); close(pim[1]); 42 close(pim[0]); close(pim[1]);
35 close(pie[0]); close(pie[1]); 43 close(pie[0]); close(pie[1]);
36 return -1; 44 return -1;
37 case 0: 45 case 0:
38 close(pim[1]); 46 close(pim[1]);
39 close(pie[1]); 47 close(pie[1]);
48 close(pierr[0]); /* we want to receive data */
40 if (fd_move(0,pim[0]) == -1) _exit(120); 49 if (fd_move(0,pim[0]) == -1) _exit(120);
41 if (fd_move(1,pie[0]) == -1) _exit(120); 50 if (fd_move(1,pie[0]) == -1) _exit(120);
51 if (fd_move(6,pierr[1]) == -1) _exit(120);
42 if (chdir(auto_qmail) == -1) _exit(61); 52 if (chdir(auto_qmail) == -1) _exit(61);
43 execv(*binqqargs,binqqargs); 53 execv(*binqqargs,binqqargs);
44 _exit(120); 54 _exit(120);
@@ -46,6 +56,7 @@ struct qmail *qq;
46 56
47 qq->fdm = pim[1]; close(pim[0]); 57 qq->fdm = pim[1]; close(pim[0]);
48 qq->fde = pie[1]; close(pie[0]); 58 qq->fde = pie[1]; close(pie[0]);
59 qq->fderr = pierr[0]; close(pierr[1]);
49 substdio_fdbuf(&qq->ss,write,qq->fdm,qq->buf,sizeof(qq->buf)); 60 substdio_fdbuf(&qq->ss,write,qq->fdm,qq->buf,sizeof(qq->buf));
50 qq->flagerr = 0; 61 qq->flagerr = 0;
51 return 0; 62 return 0;
@@ -93,10 +104,22 @@ struct qmail *qq;
93{ 104{
94 int wstat; 105 int wstat;
95 int exitcode; 106 int exitcode;
107 int match;
108 char ch;
109 static char errstr[256];
110 int len = 0;
96 111
97 qmail_put(qq,"",1); 112 qmail_put(qq,"",1);
98 if (!qq->flagerr) if (substdio_flush(&qq->ss) == -1) qq->flagerr = 1; 113 if (!qq->flagerr) if (substdio_flush(&qq->ss) == -1) qq->flagerr = 1;
99 close(qq->fde); 114 close(qq->fde);
115 substdio_fdbuf(&qq->ss, read, qq->fderr, qq->buf, sizeof(qq->buf));
116 while(substdio_bget(&qq->ss, &ch, 1) && len < 255) {
117 errstr[len] = ch;
118 len++;
119 }
120 if (len > 0) errstr[len]='\0'; /* add str-term */
121
122 close(qq->fderr);
100 123
101 if (wait_pid(&wstat,qq->pid) != qq->pid) 124 if (wait_pid(&wstat,qq->pid) != qq->pid)
102 return "Zqq waitpid surprise (#4.3.0)"; 125 return "Zqq waitpid surprise (#4.3.0)";
@@ -127,6 +150,7 @@ struct qmail *qq;
127 case 74: return "Zcommunication with mail server failed (#4.4.2)"; 150 case 74: return "Zcommunication with mail server failed (#4.4.2)";
128 case 91: /* fall through */ 151 case 91: /* fall through */
129 case 81: return "Zqq internal bug (#4.3.0)"; 152 case 81: return "Zqq internal bug (#4.3.0)";
153 case 82: return (len > 2) ? errstr : "Zqq temporary spamfilter problem (#4.3.0)";
130 case 120: return "Zunable to exec qq (#4.3.0)"; 154 case 120: return "Zunable to exec qq (#4.3.0)";
131 default: 155 default:
132 if ((exitcode >= 11) && (exitcode <= 40)) 156 if ((exitcode >= 11) && (exitcode <= 40))
diff --git a/qmail.h b/qmail.h
index 7fa13e2..7babebf 100644
--- a/qmail.h
+++ b/qmail.h
@@ -8,6 +8,7 @@ struct qmail {
8 unsigned long pid; 8 unsigned long pid;
9 int fdm; 9 int fdm;
10 int fde; 10 int fde;
11 int fderr;
11 substdio ss; 12 substdio ss;
12 char buf[1024]; 13 char buf[1024];
13} ; 14} ;