karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject git commit: [KARAF-2623] Improve exit code for SSH/client
Date Mon, 07 Apr 2014 07:54:26 GMT
Repository: karaf
Updated Branches:
  refs/heads/karaf-2.3.x 52fdaae36 -> 1b0b1df28


[KARAF-2623] Improve exit code for SSH/client


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/1b0b1df2
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/1b0b1df2
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/1b0b1df2

Branch: refs/heads/karaf-2.3.x
Commit: 1b0b1df287c737b3f30ffe8a628c129dc1baf85d
Parents: 52fdaae
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Mon Apr 7 09:52:29 2014 +0200
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Mon Apr 7 09:53:57 2014 +0200

----------------------------------------------------------------------
 client/src/main/java/org/apache/karaf/client/Main.java        | 6 +++++-
 .../java/org/apache/karaf/shell/ssh/ShellCommandFactory.java  | 7 +++++--
 2 files changed, 10 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/1b0b1df2/client/src/main/java/org/apache/karaf/client/Main.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/karaf/client/Main.java b/client/src/main/java/org/apache/karaf/client/Main.java
index 3689ff1..bb7ee85 100644
--- a/client/src/main/java/org/apache/karaf/client/Main.java
+++ b/client/src/main/java/org/apache/karaf/client/Main.java
@@ -125,6 +125,7 @@ public class Main {
         SshClient client = null;
         Terminal terminal = null;
         SshAgent agent = null;
+        int exitStatus = 0;
         try {
             agent = startAgent(user);
             client = SshClient.setUpDefaultClient();
@@ -187,6 +188,9 @@ public class Main {
             channel.setErr(AnsiConsole.wrapOutputStream(System.err));
             channel.open();
             channel.waitFor(ClientChannel.CLOSED, 0);
+            if (channel.getExitStatus() != null) {
+                exitStatus = channel.getExitStatus();
+            }
         } catch (Throwable t) {
             if (level > 1) {
                 t.printStackTrace();
@@ -204,7 +208,7 @@ public class Main {
                 }
             } catch (Throwable t) { }
         }
-        System.exit(0);
+        System.exit(exitStatus);
     }
 
     protected static SshAgent startAgent(String user) {

http://git-wip-us.apache.org/repos/asf/karaf/blob/1b0b1df2/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellCommandFactory.java
----------------------------------------------------------------------
diff --git a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellCommandFactory.java b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellCommandFactory.java
index 2790731..3e0e50c 100644
--- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellCommandFactory.java
+++ b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellCommandFactory.java
@@ -90,6 +90,7 @@ public class ShellCommandFactory implements CommandFactory {
         }
 
         public void start(final Environment env) throws IOException {
+            int exitStatus = 0;
             try {
                 final CommandSession session = commandProcessor.createSession(in, new PrintStream(out),
new PrintStream(err));
                 session.put("SCOPE", "shell:osgi:*");
@@ -122,6 +123,7 @@ public class ShellCommandFactory implements CommandFactory {
                         session.getConsole().println(session.format(result, Converter.INSPECT));
                     }
                 } catch (Throwable t) {
+                    exitStatus = 1;
                     try {
                         if (t instanceof CommandNotFoundException) {
                             LOGGER.debug("Unknown command entered", t);
@@ -141,7 +143,7 @@ public class ShellCommandFactory implements CommandFactory {
                                     .fg(Ansi.Color.DEFAULT).toString();
                             session.getConsole().println(str);
                         }
-                        if ( getBoolean(session, Console.PRINT_STACK_TRACES)) {
+                        if (getBoolean(session, Console.PRINT_STACK_TRACES)) {
                             session.getConsole().print(Ansi.ansi().fg(Ansi.Color.RED).toString());
                             t.printStackTrace(session.getConsole());
                             session.getConsole().print(Ansi.ansi().fg(Ansi.Color.DEFAULT).toString());
@@ -158,10 +160,11 @@ public class ShellCommandFactory implements CommandFactory {
                     }
                 }
             } catch (Exception e) {
+                exitStatus = 1;
                 throw (IOException) new IOException("Unable to start shell").initCause(e);
             } finally {
                 close(in, out, err);
-                callback.onExit(0);
+                callback.onExit(exitStatus);
             }
         }
 


Mime
View raw message