[ 
https://issues.apache.org/jira/browse/DAEMON-401?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16839279#comment-16839279
 ] 

Jonathan Gallimore commented on DAEMON-401:
-------------------------------------------

I've attached an updated patch for this - this checks that the function 
"SetDefaultDllDirectories" is available in kernel32.dll before attempting to 
use LOAD_LIBRARY_SEARCH_SYSTEM32 in LoadLibraryExA.

If this isn't available, it still checks for ucrtbase.dll by using the full 
path name to the System32 directory - I guess its possible that ucrtbase.dll 
could be present while KB2533623 might not be installed. Happy to remove this 
though.

I included the constant for LOAD_LIBRARY_SEARCH_SYSTEM32 in apxwin.h, as it 
didn't appear to be in the standard build setup (or I've missed it!).

Also attached is my test case - a simple webapp with a JSP that accesses a 
class with a native method that calls getenv(). The nativeenv.dll is X64, built 
with VC14 and shows the issue. The JNI source code is in there too. I've tried 
the exes I've built with Windows XP x64 and Windows Server 2019. Happy to test 
with other flavours as well, particularly if there is a standard set of tests 
that we run.

PS - the build setup instructions were great - they worked an absolute treat. I 
believe I'm reproducing the executable in the same way as the common build - 
the headers from dumpbin seem to confirm that.

> Environment variables set on service not available in JNI dll
> -------------------------------------------------------------
>
>                 Key: DAEMON-401
>                 URL: https://issues.apache.org/jira/browse/DAEMON-401
>             Project: Commons Daemon
>          Issue Type: Bug
>            Reporter: Jonathan Gallimore
>            Priority: Major
>         Attachments: daemon-1.diff, daemon-env.diff, simple-jni.zip
>
>
> I have a JNI dll loaded by a Java process running as a Windows service on 
> Windows 2019 using prunsrv. The JNI library is built with VC14, and makes 
> calls to getenv(), which is imported from ucrtbase.dll.
> This call to getenv does not pick up environment variables that are set on 
> the service via //US//Service ++Environment "key=value". Commons Daemon is 
> setting these environment variables using _wputenv(), which is imported from 
> msvcrt.dll.
> I started a discussion on the mailing list regarding this. I have patch which 
> dynamically loads ucrtbase.dll and calls its _wputenv method as well, if it 
> is available.
> I'm happy to provide changes or further patches, and work on this issue, but 
> feedback would be useful and very much appreciated.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to