Author: gnodet
Date: Mon Dec 20 20:17:07 2010
New Revision: 1051274

URL: http://svn.apache.org/viewvc?rev=1051274&view=rev
Log:
[KARAF-331] Failure to execute script against karaf sshd

Modified:
    
karaf/branches/karaf-2.1.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java
    
karaf/branches/karaf-2.1.x/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellFactoryImpl.java
    
karaf/branches/karaf-2.1.x/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshTerminal.java

Modified: 
karaf/branches/karaf-2.1.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java
URL: 
http://svn.apache.org/viewvc/karaf/branches/karaf-2.1.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java?rev=1051274&r1=1051273&r2=1051274&view=diff
==============================================================================
--- 
karaf/branches/karaf-2.1.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java
 (original)
+++ 
karaf/branches/karaf-2.1.x/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java
 Mon Dec 20 20:17:07 2010
@@ -67,6 +67,7 @@ public class Console implements Runnable
     private boolean interrupt;
     private Thread pipe;
     volatile private boolean running;
+    volatile private boolean eof;
     private Runnable closeCallback;
     private Terminal terminal;
     private InputStream consoleInput;
@@ -319,6 +320,9 @@ public class Console implements Runnable
                 return -1;
             }
             checkInterrupt();
+            if (eof && queue.isEmpty()) {
+                return -1;
+            }
             Integer i;
             if (wait) {
                 try {
@@ -388,7 +392,6 @@ public class Console implements Runnable
                         }
                         if (c == -1)
                         {
-                            queue.put(c);
                             return;
                         }
                         else if (c == 4)
@@ -410,7 +413,14 @@ public class Console implements Runnable
             }
             finally
             {
-                close();
+                eof = true;
+                try
+                {
+                    queue.put(-1);
+                }
+                catch (InterruptedException e)
+                {
+                }
             }
         }
     }

Modified: 
karaf/branches/karaf-2.1.x/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellFactoryImpl.java
URL: 
http://svn.apache.org/viewvc/karaf/branches/karaf-2.1.x/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellFactoryImpl.java?rev=1051274&r1=1051273&r2=1051274&view=diff
==============================================================================
--- 
karaf/branches/karaf-2.1.x/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellFactoryImpl.java
 (original)
+++ 
karaf/branches/karaf-2.1.x/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellFactoryImpl.java
 Mon Dec 20 20:17:07 2010
@@ -125,6 +125,7 @@ public class ShellFactoryImpl implements
         public void destroy() {
             if (!closed) {
                 closed = true;
+                ShellFactoryImpl.flush(out, err);
                 ShellFactoryImpl.close(in, out, err);
                 callback.onExit(0);
             }
@@ -132,6 +133,16 @@ public class ShellFactoryImpl implements
 
     }
 
+    private static void flush(OutputStream... streams) {
+        for (OutputStream s : streams) {
+            try {
+                s.flush();
+            } catch (IOException e) {
+                // Ignore
+            }
+        }
+    }
+
     private static void close(Closeable... closeables) {
         for (Closeable c : closeables) {
             try {

Modified: 
karaf/branches/karaf-2.1.x/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshTerminal.java
URL: 
http://svn.apache.org/viewvc/karaf/branches/karaf-2.1.x/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshTerminal.java?rev=1051274&r1=1051273&r2=1051274&view=diff
==============================================================================
--- 
karaf/branches/karaf-2.1.x/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshTerminal.java
 (original)
+++ 
karaf/branches/karaf-2.1.x/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshTerminal.java
 Mon Dec 20 20:17:07 2010
@@ -74,11 +74,23 @@ public class SshTerminal extends Termina
     }
 
     public int getTerminalWidth() {
-        return 
Integer.valueOf(this.environment.getEnv().get(Environment.ENV_COLUMNS));
+        int width = 0;
+        try {
+            width = 
Integer.valueOf(this.environment.getEnv().get(Environment.ENV_COLUMNS));
+        } catch (Throwable t) {
+            // Ignore
+        }
+        return width > 0 ? width : 80;
     }
 
     public int getTerminalHeight() {
-        return 
Integer.valueOf(this.environment.getEnv().get(Environment.ENV_LINES));
+        int height = 0;
+        try {
+            height = 
Integer.valueOf(this.environment.getEnv().get(Environment.ENV_LINES));
+        } catch (Throwable t) {
+            // Ignore
+        }
+        return height > 0 ? height : 25;
     }
 
     public boolean isSupported() {


Reply via email to