I have an application server (JBoss, but this also happens in Tomcat) running as a service in Windows Server 2003. It is running with the -Xrs flag.
The Java application running under the application server calls a customizable interface written in C++ via JNI (meaning we can alter this code), referencing a third-party DLL file for processing images (Lincoln for converting PostScript).
When we log into the server via Remote Desktop Connection in either console (mstsc /console) or administrator (mstsc /admin) mode, when we logout, if the Lincoln DLL file has been loaded, the application server will acknowledge the logoff signal and the service process will immediately terminate without prejudice.
I believe the signal is CTRL_LOGOFF, but I could be incorrect.
After JavaJiggle Article on Signal Handling, apparently signal handlers are passed to the DLL file when the DLL file is processing. This means the third-party DLL file (Lincoln in this case) listens to and responds to the CTRL_LOGOFF signal by logging off.
I believe, I should be able to code a signal catcher in my C++ interface to the DLL to intercept the CTRL_LOGOFF before it reaches the DLL and if so, then we won’t constantly die when someone logs off of a console/admin RDP.
Here is what I need:
-
Am I correct that the signal that I am getting on console/admin logoff/logout is
CTRL_LOGOFF? -
Can I write a signal interceptor in the C++ interface?
-
How do I code that signal interceptor, or is there pre-existing code? I am using a 32-bit DLL.
I have found Microsoft article Registering a Control Handler Function, which may help answer this question.
I seem to have resolved it by adding an ignore handler to the stack every time the third-party DLL is called, but I fear each time I call my method, we keep adding handlers to the stack and obviously the third-party DLL does not remove its handlers. I do not know whether this is creating a memory leak.
Is there is a way to prevent a third-party handler from being placed in the first place? I have asked a follow-up question to answer this: How can I prevent my Console Control Handler from being overridden?.
Here is my custom JNI class method, which calls the third-party DLL file: