geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r573969 - in /geronimo/sandbox/gshell/trunk: gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/ gshell-core/src/main/java/org/apache/geronimo/gshell/
Date Sun, 09 Sep 2007 09:19:21 GMT
Author: jdillon
Date: Sun Sep  9 02:19:20 2007
New Revision: 573969

URL: http://svn.apache.org/viewvc?rev=573969&view=rev
Log:
Some clean up and comments

Modified:
    geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ExitNotification.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellSecurityManager.java

Modified: geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java?rev=573969&r1=573968&r2=573969&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-cli/src/main/java/org/apache/geronimo/gshell/cli/Main.java
Sun Sep  9 02:19:20 2007
@@ -415,7 +415,7 @@
             io.err.println("FATAL: " + t);
             t.printStackTrace(io.err);
             
-            code = 1;
+            code = ExitNotification.FATAL_CODE;
         }
 
         log.debug("Exiting with code: {}, after running for: {}", code, watch);
@@ -460,7 +460,7 @@
             io.out.println();
             io.out.flush();
 
-            System.exit(0);
+            System.exit(ExitNotification.DEFAULT_CODE);
         }
 
         if (version) {
@@ -468,34 +468,36 @@
             io.out.println();
             io.out.flush();
 
-            System.exit(0);
+            System.exit(ExitNotification.DEFAULT_CODE);
         }
 
-        final SecurityManager sm = System.getSecurityManager();
-        System.setSecurityManager(new ShellSecurityManager());
-
         final AtomicReference<Integer> codeRef = new AtomicReference<Integer>();
         int code;
 
-        try {
-            Runtime.getRuntime().addShutdownHook(new Thread("GShell Shutdown Hook") {
-                public void run() {
-                    if (codeRef.get() == null) {
-                        // Give the user a warning when the JVM shutdown abnormally, normal
shutdown
-                        // will set an exit code through the proper channels
-
-                        io.err.println();
-                        io.err.println("@|red WARNING:| Abnormal JVM shutdown detected");
-                    }
+        Runtime.getRuntime().addShutdownHook(new Thread("GShell Shutdown Hook") {
+            public void run() {
+                if (codeRef.get() == null) {
+                    // Give the user a warning when the JVM shutdown abnormally, normal shutdown
+                    // will set an exit code through the proper channels
 
-                    io.flush();
+                    io.err.println();
+                    io.err.println("@|red WARNING:| Abnormal JVM shutdown detected");
                 }
-            });
 
+                io.flush();
+            }
+        });
+
+        // Install the security, keep a hold on the old one
+        final SecurityManager sm = System.getSecurityManager();
+        System.setSecurityManager(new ShellSecurityManager());
+
+        try {
             code = execute(this.args.toArray(new String[this.args.size()]));
             codeRef.set(code);
         }
         finally {
+            // Reset the security so the below System.exit() won't puke
             System.setSecurityManager(sm);
         }
         

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ExitNotification.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ExitNotification.java?rev=573969&r1=573968&r2=573969&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ExitNotification.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ExitNotification.java
Sun Sep  9 02:19:20 2007
@@ -33,6 +33,10 @@
 
     public static final int DEFAULT_CODE = 0;
 
+    public static final int ERROR_CODE = 1;
+
+    public static final int FATAL_CODE = 2;
+
     public final int code;
 
     public ExitNotification(final int code) {

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellSecurityManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellSecurityManager.java?rev=573969&r1=573968&r2=573969&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellSecurityManager.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/ShellSecurityManager.java
Sun Sep  9 02:19:20 2007
@@ -22,7 +22,7 @@
 import java.security.Permission;
 
 /**
- * ???
+ * Custom security manager to prevent commands from doing bad things.
  *
  * @version $Rev$ $Date$
  */



Mime
View raw message