Commit 843566d8 843566d88f5b19bd8ad9bf81ebc6b9282b2a02f7 by Sergey Poznyakoff

(sendmail_send_message): Don't close the descriptor if it happens to make part of tunnel pipe.

1 parent 117abd5a
...@@ -166,6 +166,9 @@ sendmail_close (mailer_t mailer) ...@@ -166,6 +166,9 @@ sendmail_close (mailer_t mailer)
166 return 0; 166 return 0;
167 } 167 }
168 168
169 /* Close FD unless it is part of pipe P */
170 #define SCLOSE(fd,p) if (p[0]!=fd&&p[1]!=fd) close(fd)
171
169 static int 172 static int
170 sendmail_send_message (mailer_t mailer, message_t msg, address_t from, 173 sendmail_send_message (mailer_t mailer, message_t msg, address_t from,
171 address_t to) 174 address_t to)
...@@ -299,9 +302,9 @@ sendmail_send_message (mailer_t mailer, message_t msg, address_t from, ...@@ -299,9 +302,9 @@ sendmail_send_message (mailer_t mailer, message_t msg, address_t from,
299 sendmail->pid = vfork (); 302 sendmail->pid = vfork ();
300 if (sendmail->pid == 0) /* Child. */ 303 if (sendmail->pid == 0) /* Child. */
301 { 304 {
302 close (STDIN_FILENO); 305 SCLOSE (STDIN_FILENO, tunnel);
303 close (STDOUT_FILENO); 306 SCLOSE (STDOUT_FILENO, tunnel);
304 close (STDERR_FILENO); 307 SCLOSE (STDERR_FILENO, tunnel);
305 close (tunnel[1]); 308 close (tunnel[1]);
306 dup2 (tunnel[0], STDIN_FILENO); 309 dup2 (tunnel[0], STDIN_FILENO);
307 execv (sendmail->path, argvec); 310 execv (sendmail->path, argvec);
......