jacek-lewandowski commented on code in PR #2983:
URL: https://github.com/apache/cassandra/pull/2983#discussion_r1424901272
##########
src/java/org/apache/cassandra/utils/FBUtilities.java:
##########
@@ -1080,6 +1093,41 @@ public static void exec(ProcessBuilder pb) throws
IOException
}
}
+ public static String exec(Map<String, String> env, Duration timeout, int
outBufSize, int errBufSize, String... cmd) throws IOException,
TimeoutException, InterruptedException
+ {
+ ProcessBuilder processBuilder = new ProcessBuilder(cmd);
+ processBuilder.environment().putAll(env);
+ Process process = processBuilder.start();
+ try (DataOutputBuffer err = new DataOutputBuffer();
+ DataOutputBuffer out = new DataOutputBuffer();
+ OutputStream overflowSink = OutputStream.nullOutputStream())
+ {
+ boolean completed = process.waitFor(timeout.toMillis(),
TimeUnit.MILLISECONDS);
+
+ copy(process.getInputStream(), out, outBufSize);
+ long outOverflow =
process.getInputStream().transferTo(overflowSink);
+
+ copy(process.getErrorStream(), err, errBufSize);
+ long errOverflow =
process.getErrorStream().transferTo(overflowSink);
+
+ if (!completed)
+ {
+ process.destroyForcibly();
+ logger.warn("Command {} did not complete in {}, killed
forcibly:\noutput:\n{}\n(truncated {} bytes)\nerror:\n{}\n(truncated {} bytes)",
+ Arrays.toString(cmd), timeout, out.asString(),
outOverflow, err.asString(), errOverflow);
+ throw new TimeoutException("Command " + Arrays.toString(cmd) +
" did not complete in " + timeout);
+ }
+ int r = process.exitValue();
+ if (r != 0)
+ {
+ logger.warn("Command {} failed with exit code
{}:\noutput:\n{}\n(truncated {} bytes)\nerror:\n{}\n(truncated {} bytes)",
Review Comment:
indeed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]