From d7fec350280da748be939e639fd5470a035842e3 Mon Sep 17 00:00:00 2001 From: Thomas Becker Date: Thu, 10 May 2012 17:04:47 +0200 Subject: [PATCH] 379116: start.jar fix to shutdown child processes with --exec. Remove finally block and replace with a shutdown hook in _exec if branch. Change-Id: I85af53090a2797f433aca22276b413762999a477 --- .../java/org/eclipse/jetty/start/Main.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index 70fbe1063f8..d4f503b45e2 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -550,22 +550,25 @@ public class Main if (_exec) { CommandLineBuilder cmd = buildCommandLine(classpath,configuredXmls); + ProcessBuilder pbuilder = new ProcessBuilder(cmd.getArgs()); final Process process = pbuilder.start(); + Runtime.getRuntime().addShutdownHook(new Thread() + { + @Override + public void run() + { + Config.debug("Destroying " + process); + process.destroy(); + } + }); + + copyInThread(process.getErrorStream(),System.err); + copyInThread(process.getInputStream(),System.out); + copyInThread(System.in,process.getOutputStream()); + monitor.setProcess(process); + process.waitFor(); - try - { - copyInThread(process.getErrorStream(),System.err); - copyInThread(process.getInputStream(),System.out); - copyInThread(System.in,process.getOutputStream()); - monitor.setProcess(process); - process.waitFor(); - } - finally - { - Config.debug("Destroying " + process); - process.destroy(); - } return; }