From 4408607c51a7c6e293adae41403b21d4a2c9a429 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 13 Apr 2017 21:47:11 +0300 Subject: Make sendmail ctor to close pipe's reading end explicitly --- butl/base64 | 2 +- butl/const-ptr | 2 +- butl/sendmail | 2 +- butl/sendmail.ixx | 31 +++++++++++++++++-------------- butl/sha256 | 2 +- butl/target-triplet | 2 +- butl/timestamp | 2 +- 7 files changed, 23 insertions(+), 20 deletions(-) (limited to 'butl') diff --git a/butl/base64 b/butl/base64 index b3e335a..1ba2fa1 100644 --- a/butl/base64 +++ b/butl/base64 @@ -45,6 +45,6 @@ namespace butl LIBBUTL_EXPORT std::vector base64_decode (const std::string&); -}; +} #endif // BUTL_BASE64 diff --git a/butl/const-ptr b/butl/const-ptr index 971e929..2790253 100644 --- a/butl/const-ptr +++ b/butl/const-ptr @@ -75,6 +75,6 @@ namespace butl private: T* p_; }; -}; +} #endif // BUTL_CONST_PTR diff --git a/butl/sendmail b/butl/sendmail index 5a380e7..706f110 100644 --- a/butl/sendmail +++ b/butl/sendmail @@ -32,7 +32,7 @@ namespace butl // // sm.out << "Test body" << endl; // - // sm.close (); + // sm.out.close (); // // if (!sm.wait ()) // ... // sendmail returned non-zero status. diff --git a/butl/sendmail.ixx b/butl/sendmail.ixx index 3f6597d..2e982c1 100644 --- a/butl/sendmail.ixx +++ b/butl/sendmail.ixx @@ -37,22 +37,25 @@ namespace butl const recipients_type& bcc, O&&... options) { - { - fdpipe pipe (fdopen_pipe ()); // Text mode seems appropriate. + fdpipe pipe (fdopen_pipe ()); // Text mode seems appropriate. - process& p (*this); - p = process_start (cmdc, - pipe.in, - 2, // No output expected so redirect to stderr. - std::forward (err), - dir_path (), - "sendmail", - "-i", // Don't treat '.' as the end of input. - "-t", // Read recipients from headers. - std::forward (options)...); + process& p (*this); + p = process_start (cmdc, + pipe.in, + 2, // No output expected so redirect to stderr. + std::forward (err), + dir_path (), + "sendmail", + "-i", // Don't treat '.' as the end of input. + "-t", // Read recipients from headers. + std::forward (options)...); - out.open (std::move (pipe.out)); - } // Close pipe.in. + // Close the reading end of the pipe not to block on writing if sendmail + // terminates before that. + // + pipe.in.close (); + + out.open (std::move (pipe.out)); // Write headers. // diff --git a/butl/sha256 b/butl/sha256 index c6b2754..1c20a57 100644 --- a/butl/sha256 +++ b/butl/sha256 @@ -96,6 +96,6 @@ namespace butl // LIBBUTL_EXPORT std::string fingerprint_to_sha256 (const std::string&); -}; +} #endif // BUTL_SHA256 diff --git a/butl/target-triplet b/butl/target-triplet index fe5e728..284b47f 100644 --- a/butl/target-triplet +++ b/butl/target-triplet @@ -150,6 +150,6 @@ namespace butl { return o << x.string (); } -}; +} #endif // BUTL_TARGET_TRIPLET diff --git a/butl/timestamp b/butl/timestamp index 550aa68..fde789f 100644 --- a/butl/timestamp +++ b/butl/timestamp @@ -141,6 +141,6 @@ namespace butl const char* format, bool local, const char** end = nullptr); -}; +} #endif // BUTL_TIMESTAMP -- cgit v1.1