aboutsummaryrefslogtreecommitdiff
path: root/build2/cli
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-07-22 12:47:21 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2016-07-23 20:13:21 +0300
commit2d9579da2144b2a8d67ea1d05fde96ec9d365944 (patch)
treeb4e033f0e8284309efeecd68ba1e9cd70dc75220 /build2/cli
parent3425432752d362341b8e39cd319d7f3c56aef169 (diff)
Adapt to fdstream extension
Diffstat (limited to 'build2/cli')
-rw-r--r--build2/cli/module.cxx50
1 files changed, 30 insertions, 20 deletions
diff --git a/build2/cli/module.cxx b/build2/cli/module.cxx
index e604bcf..a9bed86 100644
--- a/build2/cli/module.cxx
+++ b/build2/cli/module.cxx
@@ -102,34 +102,42 @@ namespace build2
if (verb >= 3)
print_process (args);
- string ver;
try
{
process pr (args, 0, -1); // Open pipe to stdout.
- ifdstream is (pr.in_ofd);
- // The version should be the last word on the first line.
- //
- getline (is, ver);
- auto p (ver.rfind (' '));
- if (p != string::npos)
- ver = string (ver, p + 1);
+ try
+ {
+ ifdstream is (pr.in_ofd, fdstream_mode::skip);
- // Skip until the end as cli doesn't handle writing to the closed
- // pipe very well (SIGPIPE).
- //
- if (is.good ())
- is.ignore (numeric_limits<streamsize>::max ());
+ // The version should be the last word on the first line.
+ //
+ string ver;
+ getline (is, ver);
+ auto p (ver.rfind (' '));
+ if (p != string::npos)
+ ver = string (ver, p + 1);
- is.close (); // Don't block the other end.
+ is.close (); // Don't block the other end.
- if (!pr.wait ()) // Presumably issued diagnostics.
- return string (); // Not found.
+ if (pr.wait ())
+ {
+ if (ver.empty ())
+ fail << "unexpected output from " << cli;
- if (ver.empty ())
- fail << "unexpected output from " << cli;
+ return ver;
+ }
- return ver;
+ // Presumably issued diagnostics. Fall through.
+ }
+ catch (const ifdstream::failure&)
+ {
+ pr.wait ();
+
+ // Fall through.
+ }
+
+ // Fall through.
}
catch (const process_error& e)
{
@@ -143,8 +151,10 @@ namespace build2
if (e.child ())
exit (1);
- return string (); // Not found.
+ // Fall through.
}
+
+ return string (); // Not found.
};
string ver; // Empty means unconfigured.