mturk 2004/09/19 01:48:28
Modified: daemon/src/native/nt/procrun/apps/prunsrv prunsrv.c
Log:
Add shutdown event so that stop thread is detached before worker
thread to enable clean shutdown from service.
Revision Changes Path
1.9 +15 -0
jakarta-commons/daemon/src/native/nt/procrun/apps/prunsrv/prunsrv.c
Index: prunsrv.c
===================================================================
RCS file:
/home/cvs/jakarta-commons/daemon/src/native/nt/procrun/apps/prunsrv/prunsrv.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- prunsrv.c 13 Sep 2004 17:51:38 -0000 1.8
+++ prunsrv.c 19 Sep 2004 08:48:28 -0000 1.9
@@ -191,6 +191,7 @@
static CHAR _jni_rclass[SIZ_RESLEN] = {'\0'}; /* Startup class */
static CHAR _jni_sclass[SIZ_RESLEN] = {'\0'}; /* Shutdown class */
+static HANDLE gShutdownEvent = NULL;
/* redirect console stdout/stderr to files
* so that java messages can get logged
* If stderrfile is not specified it will
@@ -750,6 +751,8 @@
_jni_rclass, _jni_classpath);
goto cleanup;
}
+ /* Create sutdown event */
+ gShutdownEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (!apxJavaStart(hWorker)) {
apxLogWrite(APXLOG_MARK_ERROR "Failed starting java");
rv = 3;
@@ -819,6 +822,7 @@
*/
if (!IS_INVALID_HANDLE(hWorker))
apxCloseHandle(hWorker);
+ SetEvent(gShutdownEvent);
if (timeout > 0x7FFFFFFF)
timeout = INFINITE; /* If the timeout was '-1' wait forewer */
if (wait_to_die && !timeout)
@@ -1109,7 +1113,15 @@
apxLogWrite(APXLOG_MARK_ERROR "ServiceStart returned %d", rc);
goto cleanup;
}
+ if (gShutdownEvent) {
+ /* Ensure that shutdown thread exits before us */
+ apxLogWrite(APXLOG_MARK_DEBUG "Waiting for ShutdownEvent");
+ WaitForSingleObject(gShutdownEvent, 60 * 1000);
+ apxLogWrite(APXLOG_MARK_DEBUG "ShutdownEvent signaled");
+ CloseHandle(gShutdownEvent);
+ }
reportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
+
return;
cleanup:
/* Cleanup */
@@ -1223,6 +1235,9 @@
apxLogWrite(APXLOG_MARK_INFO "Procrun finished.");
if (lpCmdline)
apxCmdlineFree(lpCmdline);
+ if (_service_status_handle)
+ CloseHandle(_service_status_handle);
+ _service_status_handle = NULL;
apxLogClose(NULL);
apxHandleManagerDestroy();
cleanupStdStreams(&gStdwrap);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]