You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2019/06/13 22:01:11 UTC

[commons-daemon] branch master updated: Fix https://issues.apache.org/jira/browse/DAEMON-329

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

markt 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 442c759  Fix https://issues.apache.org/jira/browse/DAEMON-329
442c759 is described below

commit 442c75981c67f7e5de678ff025316c1a147f6b1a
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Jun 13 23:00:40 2019 +0100

    Fix https://issues.apache.org/jira/browse/DAEMON-329
    
    When running in jre mode, if the standard Java registry entries for
    JavaHome and RuntimeLib are not present, attempt to use the Procrun
    JavaHome key to find the runtime library.
---
 src/changes/changes.xml                   |  5 +++++
 src/native/windows/apps/prunsrv/prunsrv.c |  4 ++--
 src/native/windows/include/javajni.h      |  2 +-
 src/native/windows/src/javajni.c          | 25 +++++++++++++++++++------
 4 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 40c11e1..e89408c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -126,6 +126,11 @@
         Procrun. Add an option to configure the service to use the 'Automatic
         (Delayed Start)' startup mode.
       </action>
+      <action issue="DAEMON-329" type="add" dev="markt">
+        Procrun. When running in jre mode, if the standard Java registry entries
+        for JavaHome and RuntimeLib are not present, attempt to use the Procrun
+        JavaHome key to find the runtime library.
+      </action>
     </release>
     <release version="1.1.0" date="2017-11-15" description="Feature and bug fix release">
       <action issue="DAEMON-368" type="add" dev="ggregory">
diff --git a/src/native/windows/apps/prunsrv/prunsrv.c b/src/native/windows/apps/prunsrv/prunsrv.c
index cf1ef48..9b55d49 100644
--- a/src/native/windows/apps/prunsrv/prunsrv.c
+++ b/src/native/windows/apps/prunsrv/prunsrv.c
@@ -1013,7 +1013,7 @@ static DWORD WINAPI serviceStop(LPVOID lpParameter)
              */
             SetCurrentDirectoryW(SO_STOPPATH);
         }
-        hWorker = apxCreateJava(gPool, _jni_jvmpath);
+        hWorker = apxCreateJava(gPool, _jni_jvmpath, SO_JAVAHOME);
         if (IS_INVALID_HANDLE(hWorker)) {
             apxLogWrite(APXLOG_MARK_ERROR "Failed creating Java %S", _jni_jvmpath);
             return 1;
@@ -1224,7 +1224,7 @@ static DWORD serviceStart()
            apxAddToPathW(gPool, SO_LIBPATH);
         }
         /* Create the JVM global worker */
-        gWorker = apxCreateJava(gPool, _jni_jvmpath);
+        gWorker = apxCreateJava(gPool, _jni_jvmpath, SO_JAVAHOME);
         if (IS_INVALID_HANDLE(gWorker)) {
             apxLogWrite(APXLOG_MARK_ERROR "Failed creating Java %S", _jni_jvmpath);
             return 1;
diff --git a/src/native/windows/include/javajni.h b/src/native/windows/include/javajni.h
index d88deb6..9f65a59 100644
--- a/src/native/windows/include/javajni.h
+++ b/src/native/windows/include/javajni.h
@@ -40,7 +40,7 @@ typedef struct stAPXJAVA_THREADARGS
     LPCWSTR     szLibraryPath;
 } APXJAVA_THREADARGS, *LPAPXJAVA_THREADARGS;
 
-APXHANDLE   apxCreateJava(APXHANDLE hPool, LPCWSTR szJvmDllPath);
+APXHANDLE   apxCreateJava(APXHANDLE hPool, LPCWSTR szJvmDllPath, LPCWSTR szJavaHome);
 
 BOOL        apxJavaInitialize(APXHANDLE hJava, LPCSTR szClassPath,
                               LPCVOID lpOptions, LPCVOID lpOptions9,
diff --git a/src/native/windows/src/javajni.c b/src/native/windows/src/javajni.c
index 7ad44bd..d599236 100644
--- a/src/native/windows/src/javajni.c
+++ b/src/native/windows/src/javajni.c
@@ -191,7 +191,7 @@ static __inline BOOL __apxJvmDetach(LPAPXJAVAVM lpJava)
         return TRUE;
 }
 
-static BOOL __apxLoadJvmDll(APXHANDLE hPool, LPCWSTR szJvmDllPath)
+static BOOL __apxLoadJvmDll(APXHANDLE hPool, LPCWSTR szJvmDllPath, LPCWSTR szJavaHome)
 {
     UINT errMode;
     WCHAR  jreAltPath[SIZ_PATHLEN];
@@ -215,13 +215,13 @@ static BOOL __apxLoadJvmDll(APXHANDLE hPool, LPCWSTR szJvmDllPath)
         }
     }
     else {
+    	// No explicit JVM path. Use the standard registry locations.
         dllJvmPath = apxGetJavaSoftRuntimeLib(NULL);
-        if (!dllJvmPath)
-            return FALSE;
     }
+
     if (GetFileAttributesW(dllJvmPath) == INVALID_FILE_ATTRIBUTES) {
         /* DAEMON-184: RuntimeLib registry key is invalid.
-         * Check from Jre JavaHome directly
+         * Check from Jre JavaHome registry key directly
          */
         LPWSTR szJreHome = apxGetJavaSoftHome(NULL, TRUE);
         apxLogWrite(APXLOG_MARK_DEBUG "Invalid RuntimeLib '%S'", dllJvmPath);
@@ -232,6 +232,19 @@ static BOOL __apxLoadJvmDll(APXHANDLE hPool, LPCWSTR szJvmDllPath)
             dllJvmPath = jreAltPath;
         }
     }
+
+    if (GetFileAttributesW(dllJvmPath) == INVALID_FILE_ATTRIBUTES) {
+        /* DAEMON-247: JavaSoft registry keys are invalid
+         * Check from Procrun's JavaHome registry key
+         */
+        if (szJavaHome) {
+            apxLogWrite(APXLOG_MARK_DEBUG "Using JavaHome '%S'", szJavaHome);
+            lstrlcpyW(jreAltPath, SIZ_PATHLEN, szJavaHome);
+            lstrlcatW(jreAltPath, SIZ_PATHLEN, L"\\bin\\server\\jvm.dll");
+            dllJvmPath = jreAltPath;
+        }
+    }
+
     /* Suppress the not found system popup message */
     errMode = SetErrorMode(SEM_FAILCRITICALERRORS);
 
@@ -351,7 +364,7 @@ static BOOL __apxJavaJniCallback(APXHANDLE hObject, UINT uMsg,
 }
 
 APXHANDLE
-apxCreateJava(APXHANDLE hPool, LPCWSTR szJvmDllPath)
+apxCreateJava(APXHANDLE hPool, LPCWSTR szJvmDllPath, LPCWSTR szJavaHome)
 {
 
     APXHANDLE    hJava;
@@ -360,7 +373,7 @@ apxCreateJava(APXHANDLE hPool, LPCWSTR szJvmDllPath)
     JavaVM       *lpJvm = NULL;
     struct       APX_JDK1_1InitArgs jArgs1_1;
 
-    if (!__apxLoadJvmDll(hPool, szJvmDllPath))
+    if (!__apxLoadJvmDll(hPool, szJvmDllPath, szJavaHome))
         return NULL;