diff --git a/common/src/main/java/io/netty/util/internal/NativeLibraryLoader.java b/common/src/main/java/io/netty/util/internal/NativeLibraryLoader.java index 6f9e425b51..2f5a00836b 100644 --- a/common/src/main/java/io/netty/util/internal/NativeLibraryLoader.java +++ b/common/src/main/java/io/netty/util/internal/NativeLibraryLoader.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URL; +import java.util.Arrays; import java.util.Locale; /** @@ -147,6 +148,26 @@ public final class NativeLibraryLoader { return OSNAME.startsWith("macosx") || OSNAME.startsWith("osx"); } + /** + * Loads the first available library in the collection with the specified + * {@link ClassLoader}. + * + * @throws IllegalArgumentException + * if none of the given libraries load successfully. + */ + public static void loadFirstAvailable(ClassLoader loader, String... names) { + for (String name : names) { + try { + NativeLibraryLoader.load(name, loader); + return; + } catch (Throwable t) { + logger.debug("Unable to load the library: " + name + '.', t); + } + } + throw new IllegalArgumentException("Failed to load any of the given libraries: " + + Arrays.toString(names)); + } + /** * Load the given library with the specified {@link java.lang.ClassLoader} */ diff --git a/handler/src/main/java/io/netty/handler/ssl/OpenSsl.java b/handler/src/main/java/io/netty/handler/ssl/OpenSsl.java index f100ee19f6..125db87e76 100644 --- a/handler/src/main/java/io/netty/handler/ssl/OpenSsl.java +++ b/handler/src/main/java/io/netty/handler/ssl/OpenSsl.java @@ -39,6 +39,7 @@ import java.util.Set; public final class OpenSsl { private static final InternalLogger logger = InternalLoggerFactory.getInstance(OpenSsl.class); + private static final String LINUX = "linux"; private static final String UNKNOWN = "unknown"; private static final Throwable UNAVAILABILITY_CAUSE; @@ -62,19 +63,20 @@ public final class OpenSsl { try { String os = normalizeOs(SystemPropertyUtil.get("os.name", "")); String arch = normalizeArch(SystemPropertyUtil.get("os.arch", "")); - String libName = "netty-tcnative-" + os + '-' + arch; - try { - // First, try loading the platform-specific library. Platform-specific - // libraries will be available if using a tcnative uber jar. - NativeLibraryLoader.load(libName, SSL.class.getClassLoader()); - } catch (Throwable t) { - // Either the uber jar isn't on classpath, or it doesn't contain a library - // for this platform. Load the default library. - logger.debug("Unable to load platform-specific netty-tcnative library: " + - libName + ". Will attempt to load the default netty-tcnative library.", t); - NativeLibraryLoader.load("netty-tcnative", SSL.class.getClassLoader()); + Set libNames = new LinkedHashSet(3); + // First, try loading the platform-specific library. Platform-specific + // libraries will be available if using a tcnative uber jar. + libNames.add("netty-tcnative-" + os + '-' + arch); + if (LINUX.equalsIgnoreCase(os)) { + // Fedora SSL lib so naming (libssl.so.10 vs libssl.so.1.0.0).. + libNames.add("netty-tcnative-" + os + '-' + arch + "-fedora"); } + // finally the default library. + libNames.add("netty-tcnative"); + + NativeLibraryLoader.loadFirstAvailable(SSL.class.getClassLoader(), + libNames.toArray(new String[libNames.size()])); Library.initialize("provided"); SSL.initialize(null); @@ -231,8 +233,8 @@ public final class OpenSsl { return "os400"; } } - if (value.startsWith("linux")) { - return "linux"; + if (value.startsWith(LINUX)) { + return LINUX; } if (value.startsWith("macosx") || value.startsWith("osx")) { return "osx";