Carlos Quiroz wrote:
> On Friday 07 September 2001 09:02, Finn Bock wrote:
> > [Carlos Quiroz]
> Now everything is almost working but....
> The installer has several System.exit(o) calls, that kill my embedded
> application :-(
Well, one thing you can do is install a security manager that will ignore the System.exit() calls (see below). You can get lots fancier, and check the context of the call, etc., but this should prevent the exit from occurring. Unfortunately, it will throw a SecurityException in the thread that calls System.exit(). This is reasonable (you don't want the installer thread processing any code after it tried to call exit, do you?), but it means the code that calls the installer will have to handle the exception, and that if something between your code and the call to System.exit() hides the exception, you don't know what will happen.
I know some servlet containers, etc., make System.exit() a no-op, but I'm not sure how they manage that, and not sure you'd like that anyway:
from java.security import *
from java.lang import *
class SM( SecurityManager ):
def __init__( self, delegate ):
self.allowExit = 0
self.delegate = delegate
def checkExit( self, status ):
SecurityManager.checkExit( self, status )
raise SecurityException( "Not allowed to exit at this time" )
def checkPermission( self, perm, context=None ):
if self.delegate: #allow anything if we don't have a delegate
self.delegate.checkPermission( self, perm )
self.delegate.checkPermission( self, perm, context )
sec = System.getSecurityManager()
sm = SM( sec )
System.setSecurityManager( sm )
print "not allowed to exit"
print "Did not exit"
System.setSecurityManager( sec ) # replace original security manager, or could just set allowExit
print "Trying to exit again"
print "You won't see this"