commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1400773 - in /commons/proper/daemon/branches/1.0.x/src/native/windows: apps/prunsrv/prunsrv.c include/javajni.h src/javajni.c src/log.c src/rprocess.c
Date Mon, 22 Oct 2012 06:38:03 GMT
Author: mturk
Date: Mon Oct 22 06:38:03 2012
New Revision: 1400773

URL: http://svn.apache.org/viewvc?rev=1400773&view=rev
Log:
Apply DAEMON-244 patch

Modified:
    commons/proper/daemon/branches/1.0.x/src/native/windows/apps/prunsrv/prunsrv.c
    commons/proper/daemon/branches/1.0.x/src/native/windows/include/javajni.h
    commons/proper/daemon/branches/1.0.x/src/native/windows/src/javajni.c
    commons/proper/daemon/branches/1.0.x/src/native/windows/src/log.c
    commons/proper/daemon/branches/1.0.x/src/native/windows/src/rprocess.c

Modified: commons/proper/daemon/branches/1.0.x/src/native/windows/apps/prunsrv/prunsrv.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/branches/1.0.x/src/native/windows/apps/prunsrv/prunsrv.c?rev=1400773&r1=1400772&r2=1400773&view=diff
==============================================================================
--- commons/proper/daemon/branches/1.0.x/src/native/windows/apps/prunsrv/prunsrv.c (original)
+++ commons/proper/daemon/branches/1.0.x/src/native/windows/apps/prunsrv/prunsrv.c Mon Oct
22 06:38:03 2012
@@ -826,15 +826,19 @@ static BOOL docmdUpdateService(LPAPXCMDL
 }
 
 
-/* Report the service status to the SCM
+/* Report the service status to the SCM, including service specific exit code
  */
-int reportServiceStatus(DWORD dwCurrentState,
+int reportServiceStatusE(DWORD dwCurrentState,
                         DWORD dwWin32ExitCode,
-                        DWORD dwWaitHint)
+                         DWORD dwWaitHint,
+                         DWORD dwServiceSpecificExitCode)
 {
    static DWORD dwCheckPoint = 1;
    BOOL fResult = TRUE;
 
+   apxLogWrite(APXLOG_MARK_DEBUG "reportServiceStatus: %d, %d, %d, %d", 
+               dwCurrentState, dwWin32ExitCode, dwWaitHint, dwServiceSpecificExitCode);
+
    if (_service_mode && _service_status_handle) {
        if (dwCurrentState == SERVICE_START_PENDING)
             _service_status.dwControlsAccepted = 0;
@@ -844,6 +848,7 @@ int reportServiceStatus(DWORD dwCurrentS
        _service_status.dwCurrentState  = dwCurrentState;
        _service_status.dwWin32ExitCode = dwWin32ExitCode;
        _service_status.dwWaitHint      = dwWaitHint;
+       _service_status.dwServiceSpecificExitCode = dwServiceSpecificExitCode;
 
        if ((dwCurrentState == SERVICE_RUNNING) ||
            (dwCurrentState == SERVICE_STOPPED))
@@ -858,6 +863,22 @@ int reportServiceStatus(DWORD dwCurrentS
    return fResult;
 }
 
+/* Report the service status to the SCM
+ */
+int reportServiceStatus(DWORD dwCurrentState,
+                        DWORD dwWin32ExitCode,
+                        DWORD dwWaitHint)
+{
+    return reportServiceStatusE(dwCurrentState, dwWin32ExitCode, dwWaitHint, 0);
+}
+
+int reportServiceStatusStopped(DWORD exitCode) {
+    if(exitCode) {
+        return reportServiceStatusE(SERVICE_STOPPED, ERROR_SERVICE_SPECIFIC_ERROR, 0, exitCode);
+    } else {
+        return reportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
+    }
+}
 
 BOOL child_callback(APXHANDLE hObject, UINT uMsg,
                     WPARAM wParam, LPARAM lParam)
@@ -889,7 +910,8 @@ static int onExitStart(void)
 {
     if (_service_mode) {
         apxLogWrite(APXLOG_MARK_DEBUG "Start exit hook called ...");
-        reportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
+        apxLogWrite(APXLOG_MARK_DEBUG "VM exit code: %d", apxGetVmExitCode());
+        reportServiceStatusStopped(apxGetVmExitCode());
     }
     return 0;
 }
@@ -1526,12 +1548,12 @@ void WINAPI serviceMain(DWORD argc, LPTS
         reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
     }
     apxLogWrite(APXLOG_MARK_DEBUG "JVM destroyed.");
-    reportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
+    reportServiceStatusStopped(apxGetVmExitCode());
 
     return;
 cleanup:
     /* Cleanup */
-    reportServiceStatus(SERVICE_STOPPED, ERROR_SERVICE_SPECIFIC_ERROR, rc);
+    reportServiceStatusStopped(rc);
     gExitval = rc;
     return;
 }

Modified: commons/proper/daemon/branches/1.0.x/src/native/windows/include/javajni.h
URL: http://svn.apache.org/viewvc/commons/proper/daemon/branches/1.0.x/src/native/windows/include/javajni.h?rev=1400773&r1=1400772&r2=1400773&view=diff
==============================================================================
--- commons/proper/daemon/branches/1.0.x/src/native/windows/include/javajni.h (original)
+++ commons/proper/daemon/branches/1.0.x/src/native/windows/include/javajni.h Mon Oct 22 06:38:03
2012
@@ -63,6 +63,9 @@ DWORD       apxJavaSetOptions(APXHANDLE 
 
 BOOL        apxDestroyJvm(DWORD dwTimeout);
 
+DWORD        apxGetVmExitCode();
+
+void        apxSetVmExitCode(DWORD exitCode);
 
 __APXEND_DECLS
 

Modified: commons/proper/daemon/branches/1.0.x/src/native/windows/src/javajni.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/branches/1.0.x/src/native/windows/src/javajni.c?rev=1400773&r1=1400772&r2=1400773&view=diff
==============================================================================
--- commons/proper/daemon/branches/1.0.x/src/native/windows/src/javajni.c (original)
+++ commons/proper/daemon/branches/1.0.x/src/native/windows/src/javajni.c Mon Oct 22 06:38:03
2012
@@ -139,6 +139,8 @@ typedef struct APX_JDK1_1InitArgs {
 #define JAVA_CLASSSTRING    "java/lang/String"
 #define MSVCRT71_DLLNAME    L"\\msvcrt71.dll"
 
+static DWORD vmExitCode = 0;
+
 static __inline BOOL __apxJvmAttach(LPAPXJAVAVM lpJava)
 {
     jint _iStatus;
@@ -438,6 +440,13 @@ static jint JNICALL __apxJniVfprintf(FIL
     return rv;
 }
 
+static void JNICALL __apxJniExit(jint exitCode)
+{
+    apxLogWrite(APXLOG_MARK_DEBUG "Exit hook with exit code %d", exitCode);
+    vmExitCode = exitCode;
+    return;
+}
+
 static LPSTR __apxStrIndexA(LPCSTR szStr, int nCh)
 {
     LPSTR pStr;
@@ -624,6 +633,9 @@ apxJavaInitialize(APXHANDLE hJava, LPCST
             ++sOptions;
         if (szClassPath && *szClassPath)
             ++sOptions;
+
+        sOptions++; /* unconditionally set for extraInfo exit */
+
         nOptions = __apxMultiSzToJvmOptions(hJava->hPool, lpOptions,
                                             &lpJvmOptions, sOptions);
         if (szClassPath && *szClassPath) {
@@ -641,6 +653,12 @@ apxJavaInitialize(APXHANDLE hJava, LPCST
             lpJvmOptions[nOptions - sOptions].extraInfo    = __apxJniVfprintf;
             --sOptions;
         }
+
+        /* unconditionally add hook for System.exit() in order to store exit code */
+        lpJvmOptions[nOptions - sOptions].optionString = "exit";
+        lpJvmOptions[nOptions - sOptions].extraInfo    = __apxJniExit;
+        --sOptions; 
+
         if (dwMs) {
             wsprintfA(iB[0], "-Xms%dm", dwMs);
             lpJvmOptions[nOptions - sOptions].optionString = iB[0];
@@ -903,6 +921,10 @@ static DWORD WINAPI __apxJavaWorkerThrea
               lpJava->clWorker.jMethod,
               lpJava->clWorker.jArgs);
     if (JVM_EXCEPTION_CHECK(lpJava)) {
+        apxLogWrite(APXLOG_MARK_DEBUG "Exception has been thrown");
+        vmExitCode = 1;
+        (*((lpJava)->lpEnv))->ExceptionDescribe((lpJava)->lpEnv);
+        __apxJvmDetach(lpJava);
         WORKER_EXIT(6);
     }
     else {
@@ -1215,3 +1237,12 @@ apxJavaSetOut(APXHANDLE hJava, BOOL setE
 
 }
 
+DWORD apxGetVmExitCode(void) {
+    return vmExitCode;
+}
+
+void apxSetVmExitCode(DWORD exitCode) {
+    vmExitCode = exitCode;
+    return;
+}
+

Modified: commons/proper/daemon/branches/1.0.x/src/native/windows/src/log.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/branches/1.0.x/src/native/windows/src/log.c?rev=1400773&r1=1400772&r2=1400773&view=diff
==============================================================================
--- commons/proper/daemon/branches/1.0.x/src/native/windows/src/log.c (original)
+++ commons/proper/daemon/branches/1.0.x/src/native/windows/src/log.c Mon Oct 22 06:38:03
2012
@@ -363,6 +363,11 @@ apxLogWrite(
                 wsprintfA(sb, "(%10s:%-4d) ", f, dwLine);
                 WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
             }
+
+            /* add thread ID to log output */
+            wsprintfA(sb, "[%5d] ", GetCurrentThreadId());
+            WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
+
             if (len)
                 WriteFile(lf->hFile, buffer, len, &wr, NULL);
 

Modified: commons/proper/daemon/branches/1.0.x/src/native/windows/src/rprocess.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/branches/1.0.x/src/native/windows/src/rprocess.c?rev=1400773&r1=1400772&r2=1400773&view=diff
==============================================================================
--- commons/proper/daemon/branches/1.0.x/src/native/windows/src/rprocess.c (original)
+++ commons/proper/daemon/branches/1.0.x/src/native/windows/src/rprocess.c Mon Oct 22 06:38:03
2012
@@ -116,6 +116,12 @@ static DWORD WINAPI __apxProcWorkerThrea
     if (WaitForSingleObject(lpProc->stProcInfo.hProcess,
                             INFINITE) == WAIT_OBJECT_0) {
         lpProc->dwChildStatus |= CHILD_MAINTREAD_FINISHED;
+
+        /* store worker's exit code as VM exit code for later use */
+        GetExitCodeProcess(lpProc->stProcInfo.hProcess, &dwExitCode);
+        apxLogWrite(APXLOG_MARK_DEBUG "Child process exit code %d", dwExitCode);
+        apxSetVmExitCode(dwExitCode);
+
 #if 0
         if (hProcess->fnCallback)
             (*hProcess->fnCallback)(hProcess, WM_QUIT, (WPARAM)dwExitCode, 0);



Mime
View raw message