From a02ccfaeb28ac0cd1d8f2020b238c4861e068666 Mon Sep 17 00:00:00 2001 From: Matthias Andree Date: Fri, 26 Feb 2010 00:24:06 +0100 Subject: BSMTP error reporting and stdout handling fixes * Do not close stdout when using mda and "bsmtp -" at the same time. * Log operating system errors when BSMTP writes fail. --- sink.c | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'sink.c') diff --git a/sink.c b/sink.c index c5160364..a7a2820e 100644 --- a/sink.c +++ b/sink.c @@ -784,7 +784,7 @@ static int open_bsmtp_sink(struct query *ctl, struct msgblk *msg, if (fflush(sinkfp) || ferror(sinkfp)) { - report(stderr, GT_("BSMTP preamble write failed.\n")); + report(stderr, GT_("BSMTP preamble write failed: %s.\n"), strerror(errno)); return(PS_BSMTP); } @@ -1347,8 +1347,29 @@ int close_sink(struct query *ctl, struct msgblk *msg, flag forward) /* perform end-of-message actions on the current output sink */ { int smtp_err; - if (ctl->mda) - { + + if (ctl->bsmtp && sinkfp) { + int error, oerrno; + + /* implicit disk-full check here... */ + fputs(".\r\n", sinkfp); + error = ferror(sinkfp); + oerrno = errno; + if (strcmp(ctl->bsmtp, "-")) + { + if (fclose(sinkfp) == EOF) { + error = 1; + oerrno = errno; + } + sinkfp = (FILE *)NULL; + } + if (error) + { + report(stderr, + GT_("Message termination or close of BSMTP file failed: %s\n"), strerror(oerrno)); + return(FALSE); + } + } else if (ctl->mda) { int rc = 0, e = 0, e2 = 0, err = 0; /* close the delivery pipe, we'll reopen before next message */ @@ -1388,25 +1409,6 @@ int close_sink(struct query *ctl, struct msgblk *msg, flag forward) return(FALSE); } } - else if (ctl->bsmtp && sinkfp) - { - int error; - - /* implicit disk-full check here... */ - fputs(".\r\n", sinkfp); - error = ferror(sinkfp); - if (strcmp(ctl->bsmtp, "-")) - { - if (fclose(sinkfp) == EOF) error = 1; - sinkfp = (FILE *)NULL; - } - if (error) - { - report(stderr, - GT_("Message termination or close of BSMTP file failed\n")); - return(FALSE); - } - } else if (forward) { /* write message terminator */ -- cgit v1.2.3