/**
* Starts a new priviledge-escalated environment, execute a closure, and shut it down.
*/
public static <V,T extends Throwable> V execute(TaskListener listener, String rootUsername, String rootPassword, final Callable<V, T> closure) throws T, IOException, InterruptedException {
VirtualChannel ch = start(listener, rootUsername, rootPassword);
try {
return ch.call(closure);
} finally {
ch.close();
ch.join(3000); // give some time for orderly shutdown, but don't block forever.
}
}