From: Kevin B. <kb...@ca...> - 2001-09-07 18:42:38
|
Carlos Quiroz wrote: > > On Friday 07 September 2001 09:02, Finn Bock wrote: > > [Carlos Quiroz] > > Hi > > 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: if beSafe: System.exit(1) doSomethingDangerous() :-) kb --- 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 ): if self.allowExit: SecurityManager.checkExit( self, status ) else: 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 if context: self.delegate.checkPermission( self, perm ) else: self.delegate.checkPermission( self, perm, context ) sec = System.getSecurityManager() sm = SM( sec ) System.setSecurityManager( sm ) try: System.exit(0) except: 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" System.exit(0) print "You won't see this" --- |