aboutsummaryrefslogtreecommitdiff
path: root/butl/process.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-04-24 13:51:56 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-04-24 14:49:11 +0300
commitb8526f8f0cb24c457da8c88877e516943e3e1902 (patch)
treef63a266ab7710a21c3d1cbca132194b1c7ad5b5f /butl/process.cxx
parenteb4810893eb4c8379c3455f1e8a75ccd3b911aa6 (diff)
Make fdnull() to return auto_fd
Diffstat (limited to 'butl/process.cxx')
-rw-r--r--butl/process.cxx46
1 files changed, 36 insertions, 10 deletions
diff --git a/butl/process.cxx b/butl/process.cxx
index 850ba9b..c427aa8 100644
--- a/butl/process.cxx
+++ b/butl/process.cxx
@@ -286,13 +286,26 @@ namespace butl
}
};
- auto open_null = [&fail] () -> auto_fd
+ auto open_null = [] () -> auto_fd
{
- auto_fd fd (fdnull ());
- if (fd.get () == -1)
- fail (false);
+ try
+ {
+ return fdnull ();
+ }
+ catch (const ios_base::failure& e)
+ {
+ // Translate to process_error.
+ //
+ // For old versions of g++ (as of 4.9) ios_base::failure is not derived
+ // from system_error and so we cannot recover the errno value. Lets use
+ // EIO in this case. This is a temporary code after all.
+ //
+ const system_error* se (dynamic_cast<const system_error*> (&e));
- return fd;
+ throw process_error (se != nullptr
+ ? se->code ().value ()
+ : EIO);
+ }
};
// If we are asked to open null (-2) then open "half-pipe".
@@ -940,17 +953,30 @@ namespace butl
throw process_error (m == nullptr ? last_error_msg () : m);
};
- auto open_null = [&fail] () -> auto_fd
+ auto open_null = [] () -> auto_fd
{
// Note that we are using a faster, temporary file-based emulation of
// NUL since we have no way of making sure the child buffers things
// properly (and by default they seem no to).
//
- auto_fd fd (fdnull (true));
- if (fd.get () == -1)
- fail ();
+ try
+ {
+ return fdnull (true);
+ }
+ catch (const ios_base::failure& e)
+ {
+ // Translate to process_error.
+ //
+ // For old versions of g++ (as of 4.9) ios_base::failure is not derived
+ // from system_error and so we cannot recover the errno value. Lets use
+ // EIO in this case. This is a temporary code after all.
+ //
+ const system_error* se (dynamic_cast<const system_error*> (&e));
- return fd;
+ throw process_error (se != nullptr
+ ? se->code ().value ()
+ : EIO);
+ }
};
// If we are asked to open null (-2) then open "half-pipe".