Commit 2ecbb7fa authored by Romain Reuillon's avatar Romain Reuillon

Separate output and error stream, kill all subprocesses

parent 9b198da9
......@@ -61,7 +61,8 @@ object Docker {
bind: Seq[(String, String)] = Vector.empty,
workDirectory: Option[String] = None,
environmentVariables: Seq[(String, String)] = Vector.empty,
logger: PrintStream = tool.outputLogger) = {
output: PrintStream = tool.outputLogger,
error: PrintStream = tool.outputLogger) = {
import better.files._
val id = UUID.randomUUID().toString
......@@ -83,8 +84,8 @@ object Docker {
ProcessUtil.execute(
Seq(dockerCommand, "build", "-t", id, buildDirectory.toJava.getAbsolutePath),
logger,
logger
output,
error
)
def variables =
......@@ -114,8 +115,8 @@ object Docker {
id,
) ++ workDirectoryValue ++ volumes ++ variables ++ Seq(id, "/bin/sh", s"/$runFile")
try ProcessUtil.execute(run, logger, logger)
finally ProcessUtil.execute(Seq("docker", "rmi", id), logger, logger)
try ProcessUtil.execute(run, output, error)
finally ProcessUtil.execute(Seq("docker", "rmi", id), output, error)
} finally buildDirectory.delete()
}
......
......@@ -30,7 +30,10 @@ object ProcessUtil {
try process.waitFor
catch {
case e: Throwable
process.destroyForcibly()
def kill(p: ProcessHandle) = p.destroyForcibly()
process.descendants().forEach(kill)
kill(process.toHandle)
throw e
} finally {
pump.stop
......
......@@ -306,7 +306,8 @@ object Proot {
bind: Seq[(String, String)] = Vector.empty,
workDirectory: Option[String] = None,
environmentVariables: Seq[(String, String)] = Vector.empty,
logger: PrintStream = tool.outputLogger,
output: PrintStream = tool.outputLogger,
error: PrintStream = tool.outputLogger,
noSeccomp: Boolean = false,
kernel: Option[String] = None): Int = {
......@@ -332,7 +333,7 @@ object Proot {
noSeccomp = noSeccomp,
kernel = kernel)
try ProcessUtil.execute(Seq(script.getCanonicalPath), logger, logger)
try ProcessUtil.execute(Seq(script.getCanonicalPath), output, error)
finally script.delete()
}
......
......@@ -101,7 +101,8 @@ object Singularity {
bind: Seq[(String, String)] = Vector.empty,
workDirectory: Option[String] = None,
environmentVariables: Seq[(String, String)] = Vector.empty,
logger: PrintStream = tool.outputLogger) = {
output: PrintStream = tool.outputLogger,
error: PrintStream = tool.outputLogger) = {
import better.files._
val id = UUID.randomUUID().toString
......@@ -144,8 +145,8 @@ object Singularity {
"-B", s"$absoluteRootFS/var/tmp:/var/tmp") ++ bind.flatMap { case (f, t) => Seq("-B", s"$f:$t") } ++
Seq("-B", s"${(buildDirectory / runFile).toJava.getAbsolutePath}:/$runFile") ++
Seq(absoluteRootFS, "sh", s"/$runFile"),
logger,
logger,
output,
error,
variables.map { case (n, v) => s"$n=$v" })
// TODO copy new directories at the root in the sandbox back to rootfs ?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment