Skip to content

Commit

Permalink
Added qmail-queue-custom-error.patch from Flavio Curti, et al.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jan 6, 2015
1 parent 6db4585 commit adae8a5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
8 changes: 8 additions & 0 deletions qmail-queue.8
Expand Up @@ -149,6 +149,14 @@ but communication failed.
.B 81
Internal bug; e.g., segmentation fault.
.TP
.B 82
Custom error (=bounce) messages. You have to write the error message to fd 4
and exit 82, in order to use the custom message. Format of the message:

Dthis is a custom fatal error message

Zthis is a custom temporary failure message
.TP
.B 91
Envelope format error.
.SH "SEE ALSO"
Expand Down
28 changes: 27 additions & 1 deletion qmail.c
Expand Up @@ -23,29 +23,40 @@ 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(4,pierr[1]) == -1) _exit(120);
if (chdir(auto_qmail) == -1) _exit(61);
execv(*binqqargs,binqqargs);
_exit(120);
}

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;
Expand Down Expand Up @@ -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)";
Expand Down Expand Up @@ -129,8 +152,11 @@ struct qmail *qq;
case 81: return "Zqq internal bug (#4.3.0)";
case 120: return "Zunable to exec qq (#4.3.0)";
default:
if (exitcode == 82 && len > 2){
return errstr;
}
if ((exitcode >= 11) && (exitcode <= 40))
return "Dqq permanent problem (#5.3.0)";
return "Dqq permanent problem (#5.3.0)";
return "Zqq temporary problem (#4.3.0)";
}
}
1 change: 1 addition & 0 deletions qmail.h
Expand Up @@ -8,6 +8,7 @@ struct qmail {
unsigned long pid;
int fdm;
int fde;
int fderr;
substdio ss;
char buf[1024];
} ;
Expand Down

0 comments on commit adae8a5

Please sign in to comment.