From 10740bbfefe68763b4f0d74b25a074e95a2e13e3 Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 30 Jan 2014 12:27:13 +0100 Subject: replace \r\n with \n in sendmail wrapper --- sendmail.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) (limited to 'sendmail.c') diff --git a/sendmail.c b/sendmail.c index 5fc991a..c82a536 100644 --- a/sendmail.c +++ b/sendmail.c @@ -6,6 +6,12 @@ #include "exit.h" #include "env.h" #include "str.h" +#include "stralloc.h" +#include "getln.h" +#include "readwrite.h" +#include "wait.h" +#include "fd.h" +#include "sig.h" void nomem() { @@ -158,7 +164,52 @@ char **argv; for (i = 0;i < argc;++i) *arg++ = argv[i]; *arg = 0; - execv(*qiargv,qiargv); - substdio_putsflush(subfderr,"sendmail: fatal: unable to run qmail-inject\n"); - _exit(111); + int child, pi[2]; + if (pipe(pi) == -1) { + substdio_putsflush(subfderr,"sendmail: fatal: unable to open pipe\n"); + _exit(100); + } + + switch(child = fork()) { + case -1: + substdio_putsflush(subfderr,"sendmail: fatal: unable to fork\n"); + _exit(100); + case 0: + close(pi[1]); + if (fd_copy(0,pi[0]) == -1) { + substdio_putsflush(subfderr,"sendmail: fatal: unable to fork\n"); + _exit(100); + } + sig_pipedefault(); + execv(*qiargv,qiargv); + substdio_putsflush(subfderr,"sendmail: fatal: unable to run qmail-inject\n"); + _exit(111); + } + close(pi[0]); + + char buf[256]; + static substdio ss; + int match; + static stralloc line = {0}; + substdio_fdbuf(&ss,write,pi[1],buf,sizeof buf); + for (;;) { + if (getln(subfdin,&line,&match,'\n') != 0) { + substdio_putsflush(subfderr,"sendmail: fatal: read error\n"); + _exit(111); + } + + if (!match && !line.len) break; + + if (match && line.len >= 2 && line.s[line.len - 2] == '\r') { + line.s[line.len - 2] = '\n'; + line.len--; + } + substdio_put(&ss, line.s, line.len); + } + substdio_flush(&ss); + close(pi[1]); + + int wstat; + if (wait_pid(&wstat,child) == -1) _exit(111); + _exit(wait_exitcode(wstat)); } -- cgit v1.2.3