https://bz.apache.org/bugzilla/show_bug.cgi?id=64063

--- Comment #4 from Michael Osipov <micha...@apache.org> ---
Now, what do we have:

https://tomcat.apache.org/native-doc/#Building:
* This document is correct, though I do not agree to install libtcnative into
--prefix=$CATALINA_HOME. It is a native library, it should live where other
native libraries live. Either default prefix /usr/local/lib, or else.
* It explicitly refers to LD_LIBRARY_PATH because java(1) does not know where
this library resides.

https://github.com/apache/tomcat-native/blob/master/native/BUILDING:
This one is OK, but largely duplicates the previous document. Both need to be
cleaned up. Neither this one is wrong, but not consistent with the first.

AprLifecycleListener:
Calls

> Library.initialize(null)

which then calls 

> private Library() throws Exception

which explicitly does:

> File binLib = new File(System.getProperty("catalina.home"), "bin");
>        for (int i = 0; i < NAMES.length; i++) {
>            File library = new File(binLib, System.mapLibraryName(NAMES[i]));
>            try {
>                System.load(library.getAbsolutePath());

Here is the first problem, Unix libs always reside in ./lib, but on Windows
next to the executable or ./bin. It is inconsistent with the system behavior.
Let's assume tcnative is neither in ./lib nor ./bin:

> System.loadLibrary(NAMES[i]);

is used which automatically queries java.library.path/LD_LIBRARY_PATH, you
provide the symbolic name only. Here you *need* either one set.

https://github.com/apache/tomcat/blob/master/build.xml:
* Line 87:
> <property name="test.apr.loc"          value="${test.basedir}/bin"/>

There is no way that APR and tcnative will exist in that output directory if
you don't change "test.apr.loc".
* Later on in line 1623:
> <jvmarg value="-Djava.library.path=${test.apr.loc}"/>

to make the library loadable.

Logically, this requires if/else for Windows/Unix for ./lib or ./bin. Moreover,
not APR is required, but tcnative is because tcnative is either statically or
dynamically linked against APR. We never load APR directly.

Also doing --prefix=/home/martin/git/apache/tomcat/output/build is non-sense
because this will be wiped away with "ant clean". Consider
'value="${test.basedir}/bin"' to be a guard value to satisfy arguments for
<jvmarg />.

What needs to be done?

* At worst recommend ./bin for Windows, ./lib for Unix(-like)
* At best recommend libtcnative.so/tcnative.dll to live outside of Tomcat to
survive upgrades. In most cases there is no need to recompile it if you update
Tomcat.
* Change "File binLib = new File(System.getProperty("catalina.home"), "bin");"
to be OS-dependent or iterate over {"lib", "bin"} to suit both OS families.
* Change build.xml not to mention test.apr.loc, but test.tcnative.loc and
document the default value to be a guard, but not to be used by default or drop
the default value completely and have an empty value handled appropriately.


The need for LD_LIBRARY_PATH also depends on the OS and loader config, e.g., on
HP-UX I need to supply LD_LIBRARY_PATH=/opt/ports/lib/hpux32 whereas on FreeBSD
the libtcnative is in /usr/local/lib and I do not set LD_LIBRARY_PATH because
it is by default included in ldconfig_paths
(https://github.com/freebsd/freebsd/blob/stable/12/libexec/rc/rc.conf#L650).

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to