aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/script/run.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-11-23 08:57:45 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-11-23 08:57:45 +0200
commitc6b1d1dd870b3370d0a09fb4600e3a6b03326f35 (patch)
treef400b0d4a67bd1e067b545372e7742c5665f5caf /libbuild2/script/run.cxx
parentf19959de304afaff2b3d539c9bef1f493ede5fbd (diff)
Rework diag_buffer interface to facilitate correct destruction order
Diffstat (limited to 'libbuild2/script/run.cxx')
-rw-r--r--libbuild2/script/run.cxx42
1 files changed, 28 insertions, 14 deletions
diff --git a/libbuild2/script/run.cxx b/libbuild2/script/run.cxx
index cbd750f..550fdc1 100644
--- a/libbuild2/script/run.cxx
+++ b/libbuild2/script/run.cxx
@@ -2059,31 +2059,45 @@ namespace build2
{
case redirect_type::pass:
{
- if (dfd == 2) // stderr?
+ try
{
- // Deduce the args0 argument similar to cmd_path().
- //
- process::pipe ep (
+ if (dfd == 2) // stderr?
+ {
+ fdpipe p;
+ if (diag_buffer::pipe (env.context) == -1) // Are we buffering?
+ p = fdopen_pipe ();
+
+ // @@ TODO: perhaps this lambda should return process::pipe?
+ // (see the simple test rule implementatio for an
+ // example).
+ //
+ // Note that we must return non-owning fd to our end of the
+ // pipe (see the process class for details).
+ //
+ // process::pipe r (p.in.get (), move (p.out));
+
+ // Deduce the args0 argument similar to cmd_path().
+ //
+ // Note that we must open the diag buffer regardless of the
+ // diag_buffer::pipe() result.
+ //
pc.dbuf.open ((c.program.initial == nullptr
? c.program.recall.string ().c_str ()
: c.program.recall_string ()),
- false /* force */,
- fdstream_mode::non_blocking));
+ move (p.in),
+ fdstream_mode::non_blocking);
- if (ep.out != 2) // Are we buffering stderr?
- {
- ep.own_out = false;
- return auto_fd (ep.out);
+ if (p.out != nullfd)
+ return move (p.out);
+
+ // Fall through.
}
- }
- try
- {
return fddup (dfd);
}
catch (const io_error& e)
{
- fail (ll) << "unable to duplicate " << what << ": " << e;
+ fail (ll) << "unable to redirect " << what << ": " << e;
}
}