Make NativeLibraryLoader check java.library.path first
Motivation: On restricted systems (e.g. grsecurity), it might not be possible to write a .so on disk and load it afterwards. On those system Netty should check java.library.path for libraries to load. Modifications: Changed NativeLibraryLoader.java to first try to load libs from java.library.path before exporting the .so to disk. Result: Libraries load fine on restricted systems.
This commit is contained in:
parent
053e6184f2
commit
da86b85a28
@ -113,6 +113,17 @@ public final class NativeLibraryLoader {
|
|||||||
// Adjust expected name to support shading of native libraries.
|
// Adjust expected name to support shading of native libraries.
|
||||||
String name = calculatePackagePrefix().replace('.', '_') + originalName;
|
String name = calculatePackagePrefix().replace('.', '_') + originalName;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// first try to load from java.library.path
|
||||||
|
loadLibrary(loader, name, false);
|
||||||
|
logger.debug("{} was loaded from java.libary.path", name);
|
||||||
|
return;
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
logger.debug(
|
||||||
|
"{} cannot be loaded from java.libary.path, "
|
||||||
|
+ "now trying export to -Dio.netty.native.workdir: {}", name, WORKDIR, ex);
|
||||||
|
}
|
||||||
|
|
||||||
String libname = System.mapLibraryName(name);
|
String libname = System.mapLibraryName(name);
|
||||||
String path = NATIVE_RESOURCE_HOME + libname;
|
String path = NATIVE_RESOURCE_HOME + libname;
|
||||||
|
|
||||||
@ -125,12 +136,6 @@ public final class NativeLibraryLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url == null) {
|
|
||||||
// Fall back to normal loading of JNI stuff
|
|
||||||
loadLibrary(loader, name, false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int index = libname.lastIndexOf('.');
|
int index = libname.lastIndexOf('.');
|
||||||
String prefix = libname.substring(0, index);
|
String prefix = libname.substring(0, index);
|
||||||
String suffix = libname.substring(index, libname.length());
|
String suffix = libname.substring(index, libname.length());
|
||||||
|
Loading…
Reference in New Issue
Block a user