diff options
| author | manuel <manuel@mausz.at> | 2014-01-30 12:27:13 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2014-01-30 12:27:13 +0100 |
| commit | 10740bbfefe68763b4f0d74b25a074e95a2e13e3 (patch) | |
| tree | 658661065dcd43641e2b60bb9a59724c61dd989e /sendmail.c | |
| parent | 0ee64f201ca34603c94f615497cc309317cc6361 (diff) | |
| download | qmail-10740bbfefe68763b4f0d74b25a074e95a2e13e3.tar.gz qmail-10740bbfefe68763b4f0d74b25a074e95a2e13e3.tar.bz2 qmail-10740bbfefe68763b4f0d74b25a074e95a2e13e3.zip | |
replace \r\n with \n in sendmail wrapper
Diffstat (limited to 'sendmail.c')
| -rw-r--r-- | sendmail.c | 57 |
1 files changed, 54 insertions, 3 deletions
| @@ -6,6 +6,12 @@ | |||
| 6 | #include "exit.h" | 6 | #include "exit.h" |
| 7 | #include "env.h" | 7 | #include "env.h" |
| 8 | #include "str.h" | 8 | #include "str.h" |
| 9 | #include "stralloc.h" | ||
| 10 | #include "getln.h" | ||
| 11 | #include "readwrite.h" | ||
| 12 | #include "wait.h" | ||
| 13 | #include "fd.h" | ||
| 14 | #include "sig.h" | ||
| 9 | 15 | ||
| 10 | void nomem() | 16 | void nomem() |
| 11 | { | 17 | { |
| @@ -158,7 +164,52 @@ char **argv; | |||
| 158 | for (i = 0;i < argc;++i) *arg++ = argv[i]; | 164 | for (i = 0;i < argc;++i) *arg++ = argv[i]; |
| 159 | *arg = 0; | 165 | *arg = 0; |
| 160 | 166 | ||
| 161 | execv(*qiargv,qiargv); | 167 | int child, pi[2]; |
| 162 | substdio_putsflush(subfderr,"sendmail: fatal: unable to run qmail-inject\n"); | 168 | if (pipe(pi) == -1) { |
| 163 | _exit(111); | 169 | substdio_putsflush(subfderr,"sendmail: fatal: unable to open pipe\n"); |
| 170 | _exit(100); | ||
| 171 | } | ||
| 172 | |||
| 173 | switch(child = fork()) { | ||
| 174 | case -1: | ||
| 175 | substdio_putsflush(subfderr,"sendmail: fatal: unable to fork\n"); | ||
| 176 | _exit(100); | ||
| 177 | case 0: | ||
| 178 | close(pi[1]); | ||
| 179 | if (fd_copy(0,pi[0]) == -1) { | ||
| 180 | substdio_putsflush(subfderr,"sendmail: fatal: unable to fork\n"); | ||
| 181 | _exit(100); | ||
| 182 | } | ||
| 183 | sig_pipedefault(); | ||
| 184 | execv(*qiargv,qiargv); | ||
| 185 | substdio_putsflush(subfderr,"sendmail: fatal: unable to run qmail-inject\n"); | ||
| 186 | _exit(111); | ||
| 187 | } | ||
| 188 | close(pi[0]); | ||
| 189 | |||
| 190 | char buf[256]; | ||
| 191 | static substdio ss; | ||
| 192 | int match; | ||
| 193 | static stralloc line = {0}; | ||
| 194 | substdio_fdbuf(&ss,write,pi[1],buf,sizeof buf); | ||
| 195 | for (;;) { | ||
| 196 | if (getln(subfdin,&line,&match,'\n') != 0) { | ||
| 197 | substdio_putsflush(subfderr,"sendmail: fatal: read error\n"); | ||
| 198 | _exit(111); | ||
| 199 | } | ||
| 200 | |||
| 201 | if (!match && !line.len) break; | ||
| 202 | |||
| 203 | if (match && line.len >= 2 && line.s[line.len - 2] == '\r') { | ||
| 204 | line.s[line.len - 2] = '\n'; | ||
| 205 | line.len--; | ||
| 206 | } | ||
| 207 | substdio_put(&ss, line.s, line.len); | ||
| 208 | } | ||
| 209 | substdio_flush(&ss); | ||
| 210 | close(pi[1]); | ||
| 211 | |||
| 212 | int wstat; | ||
| 213 | if (wait_pid(&wstat,child) == -1) _exit(111); | ||
| 214 | _exit(wait_exitcode(wstat)); | ||
| 164 | } | 215 | } |
