aboutsummaryrefslogtreecommitdiff
path: root/nailgun_launcher/TrapSecurityManager.java
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2016-09-15 12:18:00 +0100
committerChristopher Vogt <oss.nsp@cvogt.org>2016-09-15 12:18:00 +0100
commitd2e7fcfd0b71a53f22a7e8fbcf5c920c1c689a00 (patch)
treecf0983aae763e084fd05c0c75fceca32453e9ae8 /nailgun_launcher/TrapSecurityManager.java
parent32abe161b5454e2c9e9265bb5b95e8fad3c09bb3 (diff)
downloadcbt-d2e7fcfd0b71a53f22a7e8fbcf5c920c1c689a00.tar.gz
cbt-d2e7fcfd0b71a53f22a7e8fbcf5c920c1c689a00.tar.bz2
cbt-d2e7fcfd0b71a53f22a7e8fbcf5c920c1c689a00.zip
fix behavior of System.exit trapping
Installing one globally for the JVM live-time and make behavior dependent on a thread local variable seems safer than globally switching it out and having race conditions. Also now all other calls are forwarded to a potential Nailgun SecurityManager, which should fix some bugs.
Diffstat (limited to 'nailgun_launcher/TrapSecurityManager.java')
-rw-r--r--nailgun_launcher/TrapSecurityManager.java24
1 files changed, 22 insertions, 2 deletions
diff --git a/nailgun_launcher/TrapSecurityManager.java b/nailgun_launcher/TrapSecurityManager.java
index ed00582..fada878 100644
--- a/nailgun_launcher/TrapSecurityManager.java
+++ b/nailgun_launcher/TrapSecurityManager.java
@@ -1,19 +1,39 @@
package cbt;
import java.security.*;
-public class TrapSecurityManager extends SecurityManager{
+/*
+When enabled, this SecurityManager turns System.exit(...) calls into exceptions that can be caught and handled.
+Installing a SecurityManager is a global side-effect and thus needs extra care in a persistent
+background process like CBT's. The current approach is install it once during JVM-startup.
+When disabled this delegates to the SecurityManager installed before if any, which
+would be Nailgun's if running on Nailgun. If we do not delegate to Nailgun, it seems we
+could in some cases kill the server process
+*/
+public class TrapSecurityManager extends ProxySecurityManager{
+ public TrapSecurityManager(){
+ super(NailgunLauncher.initialSecurityManager);
+ }
+
public void checkPermission( Permission permission ){
/*
NOTE: is it actually ok, to just make these empty?
Calling .super leads to ClassNotFound exteption for a lambda.
Calling to the previous SecurityManager leads to a stack overflow
*/
+ if(!NailgunLauncher.trapExitCode.get()){
+ super.checkPermission(permission);
+ }
}
public void checkPermission( Permission permission, Object context ){
/* Does this methods need to be overidden? */
+ if(!NailgunLauncher.trapExitCode.get()){
+ super.checkPermission(permission, context);
+ }
}
@Override
public void checkExit( int status ){
+ if(NailgunLauncher.trapExitCode.get()){
+ throw new TrappedExitCode(status);
+ }
super.checkExit(status);
- throw new TrappedExitCode(status);
}
}