You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2019/12/12 19:07:46 UTC

[commons-daemon] branch master updated: More startup logging. (#14)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git


The following commit(s) were added to refs/heads/master by this push:
     new 2b457fd  More startup logging. (#14)
2b457fd is described below

commit 2b457fd37f6107b723342387f6de6c76a27b32c6
Author: Gary Gregory <ga...@users.noreply.github.com>
AuthorDate: Thu Dec 12 14:07:37 2019 -0500

    More startup logging. (#14)
    
    * More startup logging.
    
    * Tab police. Ignore MS VC dir.
---
 .gitignore                       |  1 +
 src/native/windows/src/javajni.c | 86 +++++++++++++++++++++++++---------------
 2 files changed, 56 insertions(+), 31 deletions(-)

diff --git a/.gitignore b/.gitignore
index 96d43cb..21fb1ae 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,3 +16,4 @@
 /src/native/windows/apps/prunmgr/*_GUI_RELEASE
 /src/native/windows/apps/prunsrv/*_RELEASE
 /target/
+**/.vs/
diff --git a/src/native/windows/src/javajni.c b/src/native/windows/src/javajni.c
index 4f516cd..534feea 100644
--- a/src/native/windows/src/javajni.c
+++ b/src/native/windows/src/javajni.c
@@ -210,13 +210,13 @@ static BOOL __apxLoadJvmDll(APXHANDLE hPool, LPCWSTR szJvmDllPath, LPCWSTR szJav
         if (GetFileAttributesW(dllJvmPath) == INVALID_FILE_ATTRIBUTES) {
             /* DAEMON-247: Invalid RuntimeLib explicitly specified is error.
              */
-            apxLogWrite(APXLOG_MARK_DEBUG "Invalid RuntimeLib specified '%S'", dllJvmPath);
+            apxLogWrite(APXLOG_MARK_ERROR "Invalid RuntimeLib specified '%S'", dllJvmPath);
             return FALSE;
         }
         apxLogWrite(APXLOG_MARK_DEBUG "Explicit RuntimeLib specified '%S'", dllJvmPath);
     }
     else {
-    	// No explicit JVM path. Use the standard registry locations.
+        // No explicit JVM path. Use the standard registry locations.
         dllJvmPath = apxGetJavaSoftRuntimeLib(NULL);
         apxLogWrite(APXLOG_MARK_DEBUG "No explicit RuntimeLib specified. Checking registry. Found '%S'", dllJvmPath);
     }
@@ -276,19 +276,22 @@ static BOOL __apxLoadJvmDll(APXHANDLE hPool, LPCWSTR szJvmDllPath, LPCWSTR szJav
         }
     }
 
-    /* Add java bin path to the PATH to fix loading of awt.dll */
+    /* Add Java bin path to the PATH to fix loading of awt.dll */
+    apxLogWrite(APXLOG_MARK_DEBUG "Adding Java bin path to the PATH to fix loading of awt.dll: '%S'", jreBinPath);
     apxAddToPathW(hPool, jreBinPath);
 
     /* Set the environment using putenv, so JVM can use it */
     apxSetInprocEnvironment();
 
-    apxLogWrite(APXLOG_MARK_DEBUG "loading jvm '%S'", dllJvmPath);
+    apxLogWrite(APXLOG_MARK_DEBUG "Loading JVM DLL '%S'", dllJvmPath);
     _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL, 0);
     if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle) &&
         GetFileAttributesW(dllJvmPath) != INVALID_FILE_ATTRIBUTES) {
         /* There is a file but cannot be loaded.
          * Try to load the MSVCRTxx.dll before JVM.dll
          */
+        apxLogWrite(APXLOG_MARK_ERROR "Found '%S' but couldn't load it.", dllJvmPath);
+
         WCHAR  crtBinPath[SIZ_PATHLEN];
 
         lstrlcpyW(jreBinPath, SIZ_PATHLEN, dllJvmPath);
@@ -296,35 +299,43 @@ static BOOL __apxLoadJvmDll(APXHANDLE hPool, LPCWSTR szJvmDllPath, LPCWSTR szJav
             lstrlcpyW(crtBinPath, SIZ_PATHLEN, jreBinPath);
             lstrlcatW(crtBinPath, SIZ_PATHLEN, MSVCRT71_DLLNAME);
             if (GetFileAttributesW(crtBinPath) != INVALID_FILE_ATTRIBUTES) {
+                apxLogWrite(APXLOG_MARK_DEBUG "Loading '%S'.", crtBinPath);
                 if (LoadLibraryW(crtBinPath)) {
                     /* Found MSVCRTxx.dll
                      */
-                    apxLogWrite(APXLOG_MARK_DEBUG "preloaded '%S'",
-                                crtBinPath);
+                    apxLogWrite(APXLOG_MARK_DEBUG "Preloaded '%S'", crtBinPath);
+                }
+                else {
+                    apxLogWrite(APXLOG_MARK_DEBUG "Failed preloading '%S'.", crtBinPath);
                 }
             }
         }
     }
-    /* This shuldn't happen, but try to search in %PATH% */
-    if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle))
-        _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL,
-                                              LOAD_WITH_ALTERED_SEARCH_PATH);
-
+    /* This shouldn't happen, but try to search in %PATH% */
     if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle)) {
+        apxLogWrite(APXLOG_MARK_DEBUG "Invalid JVM DLL handle.");
+        apxLogWrite(APXLOG_MARK_DEBUG "Loading JVM DLL '%S' using LOAD_WITH_ALTERED_SEARCH_PATH.", dllJvmPath);
+        _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
+    }
+    if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle)) {
+        apxLogWrite(APXLOG_MARK_DEBUG "Invalid JVM DLL handle.");
         DYNLOAD_FPTR_ADDRESS(SetDllDirectoryW, KERNEL32);
-        if(l == 2) {
+        if (l == 2) {
+            apxLogWrite(APXLOG_MARK_DEBUG "Setting DLL search path to '%S'", jreBinPath);
             DYNLOAD_CALL(SetDllDirectoryW)(jreBinPath);
-            apxLogWrite(APXLOG_MARK_DEBUG "Setting DLL search path to '%S'",
-                            jreBinPath);
         }
+        apxLogWrite(APXLOG_MARK_DEBUG "Loading JVM DLL '%S'.", dllJvmPath);
         _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL, 0);
-        if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle))
-            _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL,
-                                                  LOAD_WITH_ALTERED_SEARCH_PATH);
+        if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle)) {
+            apxLogWrite(APXLOG_MARK_DEBUG "Invalid JVM DLL handle.");
+            apxLogWrite(APXLOG_MARK_DEBUG "Loading JVM DLL '%S' using LOAD_WITH_ALTERED_SEARCH_PATH.", dllJvmPath);
+            _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
+        }
     }
     /* Restore the error mode signalization */
     SetErrorMode(errMode);
     if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle)) {
+        apxLogWrite(APXLOG_MARK_ERROR "Invalid JVM DLL handle.");
         apxLogWrite(APXLOG_MARK_SYSERR);
         return FALSE;
     }
@@ -337,8 +348,10 @@ static BOOL __apxLoadJvmDll(APXHANDLE hPool, LPCWSTR szJvmDllPath, LPCWSTR szJav
         !DYNLOAD_FPTR(JNI_CreateJavaVM) ||
         !DYNLOAD_FPTR(JNI_GetCreatedJavaVMs)) {
         apxLogWrite(APXLOG_MARK_SYSERR);
+        apxLogWrite(APXLOG_MARK_DEBUG "Freeing JVM DLL.");
         FreeLibrary(_st_sys_jvmDllHandle);
         _st_sys_jvmDllHandle = NULL;
+        apxLogWrite(APXLOG_MARK_ERROR "Failed loading JNI function pointers.");
         return FALSE;
     }
 
@@ -380,8 +393,8 @@ static BOOL __apxJavaJniCallback(APXHANDLE hObject, UINT uMsg,
         break;
     }
     return TRUE;
-	UNREFERENCED_PARAMETER(wParam);
-	UNREFERENCED_PARAMETER(lParam);
+    UNREFERENCED_PARAMETER(wParam);
+    UNREFERENCED_PARAMETER(lParam);
 }
 
 APXHANDLE
@@ -394,23 +407,32 @@ apxCreateJava(APXHANDLE hPool, LPCWSTR szJvmDllPath, LPCWSTR szJavaHome)
     JavaVM       *lpJvm = NULL;
     struct       APX_JDK1_1InitArgs jArgs1_1;
 
-    if (!__apxLoadJvmDll(hPool, szJvmDllPath, szJavaHome))
+    if (!__apxLoadJvmDll(hPool, szJvmDllPath, szJavaHome)) {
+        apxLogWrite(APXLOG_MARK_ERROR "Failed to load JVM DLL '%S', home '%S'.", szJvmDllPath, szJavaHome);
         return NULL;
-
+    }
+    apxLogWrite(APXLOG_MARK_DEBUG "Loaded JVM DLL '%S', home '%S'.", szJvmDllPath, szJavaHome);
 
     /*
+     * JNI_GetCreatedJavaVMs
      */
+    apxLogWrite(APXLOG_MARK_DEBUG "JNI_GetCreatedJavaVMs...");
     if (DYNLOAD_FPTR(JNI_GetCreatedJavaVMs)(&lpJvm, 1, &iVmCount) != JNI_OK) {
+        apxLogWrite(APXLOG_MARK_ERROR "JNI_GetCreatedJavaVMs failed.");
         return NULL;
     }
-    if (iVmCount && !lpJvm)
+    if (iVmCount && !lpJvm) {
+        apxLogWrite(APXLOG_MARK_ERROR "JNI_GetCreatedJavaVMs OK but JavaVM pointer is NULL.");
         return NULL;
+    }
 
     hJava = apxHandleCreate(hPool, 0,
                             NULL, sizeof(APXJAVAVM),
                             __apxJavaJniCallback);
-    if (IS_INVALID_HANDLE(hJava))
+    if (IS_INVALID_HANDLE(hJava)) {
+        apxLogWrite(APXLOG_MARK_ERROR "Failed to create handle.");
         return NULL;
+    }
     hJava->dwType = APXHANDLE_TYPE_JVM;
     lpJava = APXHANDLE_DATA(hJava);
     lpJava->lpJvm = lpJvm;
@@ -481,7 +503,7 @@ static DWORD __apxMultiSzToJvmOptions(APXHANDLE hPool,
                                       LPCSTR lpString9,
                                       JavaVMOption **lppArray,
                                       DWORD  nExtra,
-									  DWORD bJniVfprintf)
+                                      DWORD bJniVfprintf)
 {
     DWORD i = 0, n = 0, n9 = 0, nTotal, l = 0, l9 = 0, lTotal;
     char *buff;
@@ -504,10 +526,10 @@ static DWORD __apxMultiSzToJvmOptions(APXHANDLE hPool,
     if (lpString)
         AplCopyMemory(p, lpString, l + 1);
     if (bJniVfprintf) {
-    	// If present, vfprintf is set first so it can be used to report errors
-    	// in later options. Increment indexes to account for this.
-    	i++;
-    	n++;
+        // If present, vfprintf is set first so it can be used to report errors
+        // in later options. Increment indexes to account for this.
+        i++;
+        n++;
     }
     for (; i < n; i++) {
         (*lppArray)[i].optionString = p;
@@ -536,7 +558,7 @@ static jint JNICALL __apxJniVfprintf(FILE *fp, const char *format, va_list args)
     if (apxLogWrite(APXLOG_MARK_INFO "%s", sBuf) == 0)
         fputs(sBuf, stdout);
     return rv;
-	UNREFERENCED_PARAMETER(fp);
+    UNREFERENCED_PARAMETER(fp);
 }
 
 static void JNICALL __apxJniExit(jint exitCode)
@@ -1027,10 +1049,12 @@ static DWORD WINAPI __apxJavaWorkerThread(LPVOID lpParameter)
     apxJavaSetOut(pArgs->hJava, FALSE, pArgs->szStdOutFilename);
 
     /* Check if we have a class and a method */
-    if (!lpJava->clWorker.jClazz || !lpJava->clWorker.jMethod)
+    if (!lpJava->clWorker.jClazz || !lpJava->clWorker.jMethod) {
         WORKER_EXIT(4);
-    if (!__apxJvmAttach(lpJava))
+    }
+    if (!__apxJvmAttach(lpJava)) {
         WORKER_EXIT(5);
+    }
     apxLogWrite(APXLOG_MARK_DEBUG "Java Worker thread started %s:%s",
                 lpJava->clWorker.sClazz, lpJava->clWorker.sMethod);
     lpJava->dwWorkerStatus = 1;