commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r909347 - in /commons/proper/daemon/trunk/src/native/nt/procrun: apps/prunsrv/prunsrv.c include/javajni.h src/handles.c src/javajni.c src/log.c src/utils.c
Date Fri, 12 Feb 2010 10:38:57 GMT
Author: mturk
Date: Fri Feb 12 10:38:57 2010
New Revision: 909347

URL: http://svn.apache.org/viewvc?rev=909347&view=rev
Log:
Fix DAEMON-97 and DAEMON-130 by making sure we call DestroJavaVM and using UTF8 strings

Modified:
    commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c
    commons/proper/daemon/trunk/src/native/nt/procrun/include/javajni.h
    commons/proper/daemon/trunk/src/native/nt/procrun/src/handles.c
    commons/proper/daemon/trunk/src/native/nt/procrun/src/javajni.c
    commons/proper/daemon/trunk/src/native/nt/procrun/src/log.c
    commons/proper/daemon/trunk/src/native/nt/procrun/src/utils.c

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c?rev=909347&r1=909346&r2=909347&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c Fri Feb 12 10:38:57
2010
@@ -215,8 +215,8 @@
 static LPCWSTR  _jni_sparam               = NULL;    /* Shutdown arguments */
 static LPSTR    _jni_rmethod              = NULL;    /* Startup  arguments */
 static LPSTR    _jni_smethod              = NULL;    /* Shutdown arguments */
-static CHAR     _jni_rclass[SIZ_HUGLEN]   = {'\0'};  /* Startup  class */
-static CHAR     _jni_sclass[SIZ_HUGLEN]   = {'\0'};  /* Shutdown class */
+static LPSTR    _jni_rclass               = NULL;    /* Startup  class */
+static LPSTR    _jni_sclass               = NULL;    /* Shutdown class */
 
 static HANDLE gShutdownEvent = NULL;
 static HANDLE gSignalEvent   = NULL;
@@ -255,8 +255,8 @@
             aOut = TRUE;
             lpWrapper->szStdOutFilename = apxLogFile(gPool,
                                                      lpWrapper->szLogPath,
-                                                     NULL,
-                                                     L"stdout_");
+                                                     L"stdout_",
+                                                     NULL);
         }
         /* Delete the file if not in append mode
          * XXX: See if we can use the params instead of that.
@@ -291,8 +291,8 @@
             aErr = TRUE;
             lpWrapper->szStdErrFilename = apxLogFile(gPool,
                                                      lpWrapper->szLogPath,
-                                                     NULL,
-                                                     L"stderr_");
+                                                     L"stderr_",
+                                                     NULL);
         }
         if (!aErr)
             DeleteFileW(lpWrapper->szStdErrFilename);
@@ -323,13 +323,15 @@
                                               _O_WRONLY | _O_TEXT);
     if (lpWrapper->fdStdOutFile > 0) {
         lpWrapper->fdStdOutFile = dup2(lpWrapper->fdStdOutFile, 1);
-        setvbuf(stdout, NULL, _IONBF, 0);
+        if (lpWrapper->fdStdOutFile > 0)
+            setvbuf(stdout, NULL, _IONBF, 0);
     }
     lpWrapper->fdStdErrFile = _open_osfhandle((ptrdiff_t)lpWrapper->hStdErrFile,
                                               _O_WRONLY | _O_TEXT);
     if (lpWrapper->fdStdErrFile > 0) {
         lpWrapper->fdStdErrFile = dup2(lpWrapper->fdStdErrFile, 2);
-        setvbuf(stderr, NULL, _IONBF, 0);
+        if (lpWrapper->fdStdErrFile > 0)
+            setvbuf(stderr, NULL, _IONBF, 0);
     }
 
     return TRUE;
@@ -1186,7 +1188,7 @@
     if (SO_STARTMODE) {
         if (!lstrcmpiW(SO_STARTMODE, PRSRV_JVM)) {
             _jni_startup = TRUE;
-            WideToAscii(SO_STARTCLASS, _jni_rclass);
+            _jni_rclass  = WideToUTF8(SO_STARTCLASS);
             /* Exchange all dots with slashes */
             apxStrCharReplaceA(_jni_rclass, '.', '/');
             _jni_rparam = SO_STARTPARAMS;
@@ -1214,7 +1216,7 @@
     if (SO_STOPMODE) {
         if (!lstrcmpiW(SO_STOPMODE, PRSRV_JVM)) {
             _jni_shutdown = TRUE;
-            WideToAscii(SO_STOPCLASS, _jni_sclass);
+            _jni_sclass = WideToUTF8(SO_STOPCLASS);
             apxStrCharReplaceA(_jni_sclass, '.', '/');
             _jni_sparam = SO_STOPPARAMS;
         }
@@ -1275,7 +1277,11 @@
         rv = apxHandleWait(gWorker, INFINITE, FALSE);
         apxLogWrite(APXLOG_MARK_DEBUG "Worker finished.");
         reportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
-        fflush(stdout);
+        /* This will cause to wait for all threads to exit
+         * TODO: Use some kind of timeout wait logic
+         */
+        apxDestroyJvm();
+        apxLogWrite(APXLOG_MARK_DEBUG "JVM destroyed.");
     }
     else {
         apxLogWrite(APXLOG_MARK_ERROR "ServiceStart returned %d", rc);
@@ -1416,6 +1422,7 @@
     if (_service_status_handle)
         CloseHandle(_service_status_handle);
     _service_status_handle = NULL;
+    _flushall();
     apxLogClose(NULL);
     apxHandleManagerDestroy();
     ExitProcess(rv);

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/include/javajni.h
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/include/javajni.h?rev=909347&r1=909346&r2=909347&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/include/javajni.h (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/include/javajni.h Fri Feb 12 10:38:57
2010
@@ -19,6 +19,8 @@
 
 __APXBEGIN_DECLS
 
+#define     APX_JVM_DESTROY 0x00000001
+
 APXHANDLE   apxCreateJava(APXHANDLE hPool, LPCWSTR szJvmDllPath);
 
 BOOL        apxJavaInitialize(APXHANDLE hJava, LPCSTR szClassPath,
@@ -39,6 +41,9 @@
 
 BOOL        apxJavaSetOut(APXHANDLE hJava, BOOL setErrorOrOut,
                           LPCWSTR szFilename);
+DWORD       apxJavaSetOptions(APXHANDLE hJava, DWORD dwOptions);
+
+BOOL        apxDestroyJvm(void);
 
 
 __APXEND_DECLS

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/src/handles.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/src/handles.c?rev=909347&r1=909346&r2=909347&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/src/handles.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/src/handles.c Fri Feb 12 10:38:57 2010
@@ -407,9 +407,12 @@
 {
     if (szSource) {
         LPWSTR szDest;
-        DWORD l = lstrlenA(szSource);
-        szDest = apxPoolAlloc(hPool, (l + 1) * sizeof(WCHAR));
-        AsciiToWide(szSource, szDest);
+        int cch = MultiByteToWideChar(CP_UTF8, 0, szSource, -1, NULL, 0);
+        szDest = (LPWSTR)apxPoolAlloc(hPool, cch * sizeof(WCHAR));
+        if (!MultiByteToWideChar(CP_UTF8, 0, szSource, -1, szDest, cch)) {
+            apxFree(szDest);
+            return NULL;
+        }
         return szDest;
     }
     else

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/src/javajni.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/src/javajni.c?rev=909347&r1=909346&r2=909347&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/src/javajni.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/src/javajni.c Fri Feb 12 10:38:57 2010
@@ -45,7 +45,8 @@
 DYNOLAD_TYPE_DECLARE(JNI_GetCreatedJavaVMs, JNICALL, jint)(JavaVM **, jsize, jsize *);
 static DYNLOAD_FPTR_DECLARE(JNI_GetCreatedJavaVMs) = NULL;
 
-static HANDLE _st_sys_jvmDllHandle = NULL;
+static HANDLE  _st_sys_jvmDllHandle = NULL;
+static JavaVM *_st_sys_jvm = NULL;
 
 DYNOLAD_TYPE_DECLARE(SetDllDirectoryW, WINAPI, BOOL)(LPCWSTR);
 static DYNLOAD_FPTR_DECLARE(SetDllDirectoryW) = NULL;
@@ -127,7 +128,11 @@
 
 static __inline BOOL __apxJvmAttach(LPAPXJAVAVM lpJava)
 {
-    jint _iStatus = (*(lpJava->lpJvm))->GetEnv(lpJava->lpJvm,
+    jint _iStatus;
+
+    if (!_st_sys_jvm)
+      return FALSE;  
+    _iStatus = (*(lpJava->lpJvm))->GetEnv(lpJava->lpJvm,
                                           (void **)&(lpJava->lpEnv),
                                           lpJava->iVersion);
     if (_iStatus != JNI_OK) {
@@ -145,8 +150,9 @@
 
 static __inline BOOL __apxJvmDetach(LPAPXJAVAVM lpJava)
 {
-    jint _iStatus = (*(lpJava->lpJvm))->DetachCurrentThread(lpJava->lpJvm);
-    if (_iStatus != JNI_OK) {
+    if (!_st_sys_jvm)
+      return FALSE;  
+    if ((*(lpJava->lpJvm))->DetachCurrentThread(lpJava->lpJvm) != JNI_OK) {
         lpJava->lpEnv = NULL;
         return FALSE;
     }
@@ -226,7 +232,7 @@
     lpJava = APXHANDLE_DATA(hObject);
     switch (uMsg) {
         case WM_CLOSE:
-            if (lpJava->lpJvm) {
+            if (_st_sys_jvm && lpJava->lpJvm) {
                 if (!IS_INVALID_HANDLE(lpJava->hWorkerThread)) {
                     if (GetExitCodeThread(lpJava->hWorkerThread, &dwJvmRet) &&
                         dwJvmRet == STILL_ACTIVE) {
@@ -240,11 +246,6 @@
                 __apxJvmDetach(lpJava);
                 /* Check if this is the jvm loader */
                 if (!lpJava->iVmCount && _st_sys_jvmDllHandle) {
-#if 0
-                    /* Do not destroy if we terminated the worker thread */
-                    if (dwJvmRet != STILL_ACTIVE)
-                        (*(lpJava->lpJvm))->DestroyJavaVM(lpJava->lpJvm);
-#endif
                     /* Unload JVM dll */
                     FreeLibrary(_st_sys_jvmDllHandle);
                     _st_sys_jvmDllHandle = NULL;
@@ -286,9 +287,25 @@
     lpJava = APXHANDLE_DATA(hJava);
     lpJava->lpJvm = lpJvm;
     lpJava->iVmCount = iVmCount;
+    if (!_st_sys_jvm)
+        _st_sys_jvm = lpJvm;
     return hJava;
 }
 
+BOOL
+apxDestroyJvm()
+{
+    if (_st_sys_jvm) {
+        JavaVM *lpJvm = _st_sys_jvm;
+        _st_sys_jvm = NULL;
+        (*lpJvm)->DetachCurrentThread(lpJvm);
+        (*lpJvm)->DestroyJavaVM(lpJvm);
+        return TRUE;
+    }
+    else
+        return FALSE;
+}
+
 static DWORD __apxMultiSzToJvmOptions(APXHANDLE hPool,
                                       LPCSTR lpString,
                                       JavaVMOption **lppArray,
@@ -421,8 +438,11 @@
             apxLogWrite(APXLOG_MARK_ERROR "CreateJavaVM Failed");
             rv = FALSE;
         }
-        else
+        else {
             rv = TRUE;
+            if (!_st_sys_jvm)
+                _st_sys_jvm = lpJava->lpJvm;
+        }
         apxFree(szCp);
         apxFree(lpJvmOptions);
     }
@@ -456,7 +476,7 @@
     DWORD i, nJVM, nCmd, nTotal, lJVM, lCmd;
     LPWSTR p;
 
-    // Calculate the number of all arguments
+    /* Calculate the number of all arguments */
     nTotal = 0;
     if (szClassPath)
         ++nTotal;
@@ -476,10 +496,11 @@
     if (nTotal == 0)
         return 0;
 
-    // Allocate the array to store all arguments' pointers
+    /* Allocate the array to store all arguments' pointers
+     */
     *lppArray = (LPWSTR *)apxPoolAlloc(hPool, (nTotal + 2) * sizeof(LPWSTR));
 
-    // Process JVM options
+    /* Process JVM options */
     if (nJVM && lJVM) {
         p = (LPWSTR)apxPoolAlloc(hPool, (lJVM + 1) * sizeof(WCHAR));
         AplCopyMemory(p, szOptions, (lJVM + 1) * sizeof(WCHAR) + sizeof(WCHAR));
@@ -491,7 +512,7 @@
         }
     }
 
-    // Process the 3 extra JVM options
+    /* Process the 3 extra JVM options */
     if (dwMs) {
         p = (LPWSTR)apxPoolAlloc(hPool, 64 * sizeof(WCHAR));
         wsprintfW(p, L"-Xms%dm", dwMs);
@@ -508,7 +529,7 @@
         (*lppArray)[i++] = p;
     }
 
-    // Process the classpath and class
+    /* Process the classpath and class */
     if (szClassPath) {
         p = (LPWSTR)apxPoolAlloc(hPool, (lstrlenW(JAVA_CLASSPATH_W) + lstrlenW(szClassPath))
* sizeof(WCHAR));
         lstrcpyW(p, JAVA_CLASSPATH_W);
@@ -521,7 +542,7 @@
         (*lppArray)[i++] = p;
     }
 
-    // Process command arguments
+    /* Process command arguments */
     if (nCmd && lCmd) {
         p = (LPWSTR)apxPoolAlloc(hPool, (lCmd + 1) * sizeof(WCHAR));
         AplCopyMemory(p, szCmdArgs, (lCmd + 1) * sizeof(WCHAR) + sizeof(WCHAR));
@@ -593,7 +614,6 @@
     return TRUE;
 }
 
-
 /* Main java application worker thread
  * It will launch Java main and wait until
  * it finishes.
@@ -623,6 +643,8 @@
 
     JVM_EXCEPTION_CLEAR(lpJava);
     __apxJvmDetach(lpJava);
+    apxLogWrite(APXLOG_MARK_DEBUG "Java Worker thread %s:%s finished",
+                lpJava->clWorker.sClazz, lpJava->clWorker.sMethod);
 finished:
     lpJava->dwWorkerStatus = 0;
     apxLogWrite(APXLOG_MARK_DEBUG "Java Worker thread finished %s:%s",
@@ -657,6 +679,20 @@
 }
 
 DWORD
+apxJavaSetOptions(APXHANDLE hJava, DWORD dwOptions)
+{
+    DWORD dwOrgOptions;
+    LPAPXJAVAVM lpJava;
+
+    if (hJava->dwType != APXHANDLE_TYPE_JVM)
+        return 0;
+    lpJava = APXHANDLE_DATA(hJava);
+    dwOrgOptions = lpJava->dwOptions;
+    lpJava->dwOptions = dwOptions;
+    return dwOrgOptions;
+}
+
+DWORD
 apxJavaWait(APXHANDLE hJava, DWORD dwMilliseconds, BOOL bKill)
 {
     DWORD rv;

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/src/log.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/src/log.c?rev=909347&r1=909346&r2=909347&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/src/log.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/src/log.c Fri Feb 12 10:38:57 2010
@@ -57,28 +57,23 @@
     if (!szPath) {
         if (GetSystemDirectoryW(sPath, MAX_PATH) == 0)
             return INVALID_HANDLE_VALUE;
-        lstrlcatW(sPath, MAX_PATH, L"\\LogFiles\\");
-        if (!szPrefix)
-            lstrlcatW(sPath, MAX_PATH, L"Apache");
-        else
-            lstrlcatW(sPath, MAX_PATH, szPrefix);
-        wsprintfW(sName, L"\\%s%04d%02d%02d.log",
-                  szName,
-                  sysTime.wYear,
-                  sysTime.wMonth,
-                  sysTime.wDay);
+        lstrlcatW(sPath, MAX_PATH, L"\\LogFiles\\Apache");
     }
     else {
         lstrlcpyW(sPath, MAX_PATH, szPath);
-        if (szPrefix)
-            wsprintfW(sName, L"\\%s", szPrefix);
-        else
-            wsprintfW(sName, L"\\%s%04d%02d%02d.log",
-                      szName,
-                      sysTime.wYear,
-                      sysTime.wMonth,
-                      sysTime.wDay);
     }
+    if (!szPrefix)
+        szPrefix = L"";
+    if (!szName)
+        szName   = L"";
+    wsprintfW(sName,
+              L"\\%s%s%04d%02d%02d.log",
+              szPrefix,
+              szName,
+              sysTime.wYear,
+              sysTime.wMonth,
+              sysTime.wDay);
+
     sRet = apxPoolAlloc(hPool, (MAX_PATH + 1) * sizeof(WCHAR));
     /* Set default level to info */
     CreateDirectoryW(sPath, NULL);

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/src/utils.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/src/utils.c?rev=909347&r1=909346&r2=909347&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/src/utils.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/src/utils.c Fri Feb 12 10:38:57 2010
@@ -149,6 +149,19 @@
     return s;
 }
 
+LPWSTR UTF8ToWide(LPCSTR cs)
+{
+
+    LPWSTR s;
+    int cch = MultiByteToWideChar(CP_UTF8, 0, cs, -1, NULL, 0);
+    s = (LPWSTR)apxAlloc(cch * sizeof(WCHAR));
+    if (!MultiByteToWideChar(CP_UTF8, 0, cs, -1, s, cch)) {
+        apxFree(s);
+        return NULL;
+    }
+    return s;
+}
+
 LPSTR MzWideToAscii(LPCWSTR ws, LPSTR s)
 {
     LPSTR pszSave = s;



Mime
View raw message