From 328b68e47ed505907d8bc9b3246bda99a83e6f42 Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 27 Jul 2015 18:47:13 +0200 Subject: [PATCH] qmail queue custom error patch see google qmail-queue-custom-error-v2.patch --- qmail.c | 26 +++++++++++++++++++++++++- qmail.h | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) 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; { int pim[2]; int pie[2]; + int pierr[2]; setup_qqargs(); if (pipe(pim) == -1) return -1; if (pipe(pie) == -1) { close(pim[0]); close(pim[1]); return -1; } - + if (pipe(pierr) == -1) { + close(pim[0]); close(pim[1]); + close(pie[0]); close(pie[1]); + close(pierr[0]); close(pierr[1]); + return -1; + } + switch(qq->pid = vfork()) { case -1: + close(pierr[0]); close(pierr[1]); close(pim[0]); close(pim[1]); close(pie[0]); close(pie[1]); return -1; case 0: close(pim[1]); close(pie[1]); + close(pierr[0]); /* we want to receive data */ if (fd_move(0,pim[0]) == -1) _exit(120); if (fd_move(1,pie[0]) == -1) _exit(120); + if (fd_move(6,pierr[1]) == -1) _exit(120); if (chdir(auto_qmail) == -1) _exit(61); execv(*binqqargs,binqqargs); _exit(120); @@ -46,6 +56,7 @@ struct qmail *qq; qq->fdm = pim[1]; close(pim[0]); qq->fde = pie[1]; close(pie[0]); + qq->fderr = pierr[0]; close(pierr[1]); substdio_fdbuf(&qq->ss,write,qq->fdm,qq->buf,sizeof(qq->buf)); qq->flagerr = 0; return 0; @@ -93,10 +104,22 @@ struct qmail *qq; { int wstat; int exitcode; + int match; + char ch; + static char errstr[256]; + int len = 0; qmail_put(qq,"",1); if (!qq->flagerr) if (substdio_flush(&qq->ss) == -1) qq->flagerr = 1; close(qq->fde); + substdio_fdbuf(&qq->ss, read, qq->fderr, qq->buf, sizeof(qq->buf)); + while(substdio_bget(&qq->ss, &ch, 1) && len < 255) { + errstr[len] = ch; + len++; + } + if (len > 0) errstr[len]='\0'; /* add str-term */ + + close(qq->fderr); if (wait_pid(&wstat,qq->pid) != qq->pid) return "Zqq waitpid surprise (#4.3.0)"; @@ -127,6 +150,7 @@ struct qmail *qq; case 74: return "Zcommunication with mail server failed (#4.4.2)"; case 91: /* fall through */ case 81: return "Zqq internal bug (#4.3.0)"; + case 82: return (len > 2) ? errstr : "Zqq temporary spamfilter problem (#4.3.0)"; case 120: return "Zunable to exec qq (#4.3.0)"; default: 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 { unsigned long pid; int fdm; int fde; + int fderr; substdio ss; char buf[1024]; } ; -- cgit v1.2.3