0

In my application I have written the shut down hook. But some third party code is calling that shut down hook. This shut down hook should not be called by any third party code.

I have written the code to block shut down hook by third party but it did not help. (This code worked in my standalone test program. but did not worked in my application.)

Below are the code where something different behaviour is occurring:

    final SecurityManager securityManager = new SecurityManager() {
        public void checkPermission(Permission permission) {
            System.out.println("In checkPermission:{" + permission.getName() + "}");
            if ("exitVM.0".equals(permission.getName())) {
                throw new ExitTrappedException();
            }
        }
    };

When I execute this code in Test program then when shut down being called its giving me "In checkPermission:{exitVM.0}". So that it comes in if condition and my shut down hook gets blocked. Now when I tried same thing in my application then this "exitVM.0" is not getting printed and shut down hook is getting called.

Any suggestions? Is there any different permission.getName() which can call shutdown hook?

  • Have you *installed* this security manager in the application? The code above doesn't do that. – user207421 May 28 '15 at 06:48
  • Yes. I did the steps given in http://stackoverflow.com/questions/5401281/preventing-system-exit-from-api Here, I have just given suspicious code. In my application when shutdown hook is called then eexitVM.0 is not coming. There is something different call is calling shutdown hook – Vijay Patil May 28 '15 at 06:56

1 Answers1

0

It could be exitVM.1, exitVM.2, etc, since the number is just the shutdown code. The actual permission is called exitVM. (see http://docs.oracle.com/javase/7/docs/technotes/guides/security/permissions.html). So you could use permission.getName().startsWith("exitVM").

But what you're trying to do (prevent application being shut down) sounds like it might not be the best idea. What's the context?

artbristol
  • 32,010
  • 5
  • 70
  • 103
  • Thanks for reply.. I checked the code but its not exitVM. Even this exitVM is not coming. My usage: I have two programs. 1st program has shutdown hook in it. Now when I stop second program then somehow first programs shutdown hook is getting triggered. I have checked the permission.getName() but exitVM is got getting called. Here I want whenever second programs stop it does not trigger shutdown hook of first program. – Vijay Patil May 29 '15 at 03:11
  • Does program 2 start program 1? – artbristol May 30 '15 at 07:53