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 527c8f5  Add workaround for 
https://issues.apache.org/jira/browse/DAEMON-398
527c8f5 is described below

commit 527c8f57a7fc91a7546e48d90f57407f47b16b49
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Jun 12 14:03:47 2019 +0100

    Add workaround for https://issues.apache.org/jira/browse/DAEMON-398
    
    Make vfprintf the first parameter passed when creating the JVM as that
    allows subsequent error messages to be captured.
---
 src/changes/changes.xml          |  5 +++++
 src/native/windows/src/javajni.c | 30 +++++++++++++++++++-----------
 2 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f0c4ccb..19d0720 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -117,6 +117,11 @@
         Procrun. Remove the code that removed quotes from configured Java and
         Java 9 Options.
       </action>
+      <action issue="DAEMON-398" type="fix" dev="markt">
+        Procrun. Ensure that vfprintf is the first parameter passed when using
+        JNI to create the JVM as a workaround for startup error messages not
+        being visible on stdout or stderr.
+      </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/src/javajni.c b/src/native/windows/src/javajni.c
index e1e8c45..7ad44bd 100644
--- a/src/native/windows/src/javajni.c
+++ b/src/native/windows/src/javajni.c
@@ -446,9 +446,10 @@ static DWORD __apxMultiSzToJvmOptions(APXHANDLE hPool,
                                       LPCSTR lpString,
                                       LPCSTR lpString9,
                                       JavaVMOption **lppArray,
-                                      DWORD  nExtra)
+                                      DWORD  nExtra,
+                                                                         DWORD 
bJniVfprintf)
 {
-    DWORD i, n = 0, n9 = 0, nTotal, l = 0, l9 = 0, lTotal;
+    DWORD i = 0, n = 0, n9 = 0, nTotal, l = 0, l9 = 0, lTotal;
     char *buff;
     LPSTR p;
 
@@ -468,7 +469,13 @@ static DWORD __apxMultiSzToJvmOptions(APXHANDLE hPool,
     p = (LPSTR)(buff + (nTotal + 1) * sizeof(JavaVMOption));
     if (lpString)
         AplCopyMemory(p, lpString, l + 1);
-    for (i = 0; i < n; i++) {
+    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++;
+    }
+    for (; i < n; i++) {
         (*lppArray)[i].optionString = p;
         while (*p)
             p++;
@@ -476,7 +483,7 @@ static DWORD __apxMultiSzToJvmOptions(APXHANDLE hPool,
     }
     if (lpString9)
         AplCopyMemory(p, lpString9, l9 + 1);
-    for (i = n; i < (n + n9); i++) {
+    for (; i < (n + n9); i++) {
         (*lppArray)[i].optionString = p;
         while (*p)
             p++;
@@ -706,7 +713,14 @@ apxJavaInitialize(APXHANDLE hJava, LPCSTR szClassPath,
         sOptions++; /* unconditionally set for extraInfo abort */
 
         nOptions = __apxMultiSzToJvmOptions(hJava->hPool, lpOptions, 
lpOptions9,
-                                            &lpJvmOptions, sOptions);
+                                            &lpJvmOptions, sOptions, 
bJniVfprintf);
+        if (bJniVfprintf) {
+            /* Default JNI error printer. Hard-coded to position zero if 
present */
+            lpJvmOptions[0].optionString = "vfprintf";
+            lpJvmOptions[0].extraInfo    = __apxJniVfprintf;
+            --sOptions;
+        }
+
         if (szClassPath && *szClassPath) {
             szCp = __apxEvalClasspath(hJava->hPool, szClassPath);
             if (szCp == NULL) {
@@ -716,12 +730,6 @@ apxJavaInitialize(APXHANDLE hJava, LPCSTR szClassPath,
             lpJvmOptions[nOptions - sOptions].optionString = szCp;
             --sOptions;
         }
-        if (bJniVfprintf) {
-            /* default JNI error printer */
-            lpJvmOptions[nOptions - sOptions].optionString = "vfprintf";
-            lpJvmOptions[nOptions - sOptions].extraInfo    = __apxJniVfprintf;
-            --sOptions;
-        }
 
         /* unconditionally add hook for System.exit() in order to store exit 
code */
         lpJvmOptions[nOptions - sOptions].optionString = "exit";

Reply via email to