From d6c0cc10692ddf61831ce2e4be4ccfc7b75e82d9 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 2 Jan 2010 18:43:34 -0800 Subject: [PATCH] Push Command.destroy down through DispatchCommand redirection When we redirect through a DispatchCommand to a different name we need to ensure the destroy event is pushed down too, in case the daemon terminates before the command is run. Change-Id: Idc4446f4a0426aadcbb03c48ff2321071cded25b Signed-off-by: Shawn O. Pearce --- .../com/google/gerrit/sshd/DispatchCommand.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/DispatchCommand.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/DispatchCommand.java index 2fcf7182ff..a5e0b776ac 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/DispatchCommand.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/DispatchCommand.java @@ -37,6 +37,7 @@ final class DispatchCommand extends BaseCommand { private final Provider currentUser; private final String prefix; private final Map> commands; + private Command cmd; @Inject DispatchCommand(final Provider cu, @Assisted final String pfx, @@ -74,6 +75,11 @@ final class DispatchCommand extends BaseCommand { final Provider p = commands.get(name); if (p != null) { final Command cmd = p.get(); + + synchronized (this) { + this.cmd = cmd; + } + if (cmd.getClass().getAnnotation(AdminCommand.class) != null) { final CurrentUser u = currentUser.get(); if (!u.isAdministrator()) { @@ -102,6 +108,16 @@ final class DispatchCommand extends BaseCommand { } } + @Override + public void destroy() { + synchronized (this) { + if (cmd != null) { + cmd.destroy(); + cmd = null; + } + } + } + private void usage() throws IOException, UnsupportedEncodingException { final StringBuilder usage = new StringBuilder(); if (prefix.indexOf(' ') < 0) {