From 0ea11771d82f47bcef891544b76c81f94838a30d Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 24 Nov 2022 14:15:37 +0300 Subject: Fix skipping potential input for exit, etc script pseudo-builtins --- libbuild2/script/run.cxx | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'libbuild2') diff --git a/libbuild2/script/run.cxx b/libbuild2/script/run.cxx index 7b08898..f486138 100644 --- a/libbuild2/script/run.cxx +++ b/libbuild2/script/run.cxx @@ -1738,14 +1738,29 @@ namespace build2 // content), to make sure that the command doesn't print any unwanted // diagnostics about IO operation failure. // - // Note though, that doing so would be a bad idea if the deadline is - // specified, since we can block on read and miss the deadline. - // - if (!dl) - { - // Note that dtor will ignore any errors (which is what we want). + if (ifd != nullfd) + { + // Note that we can't use ifdstream dtor in the skip mode here since + // it turns the stream into the blocking mode and we won't be able + // to read out the potentially buffered stderr for the + // pipeline. Using read() is also not ideal since it performs + // parsing and allocations needlessly. This, however, is probably ok + // for such an uncommon case. // - ifdstream (move (ifd), fdstream_mode::skip); + //ifdstream (move (ifd), fdstream_mode::skip); + + // Let's try to minimize the allocation size splitting the input + // data at whitespaces. + // + read (move (ifd), + true /* whitespace */, + false /* newline */, + false /* exact */, + [] (string&&) {}, // Just drop the string. + prev_cmd, + dl, + ll, + program.c_str ()); } if (!first || !last) -- cgit v1.1