jigawatts/load_library.patch
Andrew Hughes c368530e92 Initial import of Jigawatts for RHEL 9.
Rewrite to use autotools build system, avoiding need for Maven dependencies missing in RHEL 9.
This also ensures use of the standard build flags and installs the jar in the expected location.

Resolves: rhbz#1972029
2021-08-16 18:23:30 +01:00

59 lines
2.2 KiB
Diff

diff --git a/src/main/java/org/openjdk/jigawatts/Jigawatts.java b/src/main/java/org/openjdk/jigawatts/Jigawatts.java
index f2766da..8257eeb 100644
--- a/src/main/java/org/openjdk/jigawatts/Jigawatts.java
+++ b/src/main/java/org/openjdk/jigawatts/Jigawatts.java
@@ -150,38 +150,26 @@ public class Jigawatts {
return Collections.unmodifiableList(crContext.restoreHooks);
}
- private static void copyLibrary(String library, String destDir) throws IOException {
-
- String libraryName = System.mapLibraryName(library);
- String libraryFile = destDir + "/" + libraryName;
-
- try (InputStream is = Jigawatts.class.getClassLoader().getResourceAsStream(libraryName);
- FileOutputStream os = new FileOutputStream(libraryFile)) {
-
- byte[] buf = new byte[1024];
-
- int bytesRead;
-
- while ((bytesRead = is.read(buf)) > 0) {
- os.write(buf, 0, bytesRead);
+ private static void loadLib(String library) {
+ String criuLib = System.mapLibraryName(library);
+ boolean success = false;
+ for (String path: System.getProperty("java.library.path").split(":")) {
+ try {
+ String libPath = path + File.separator + criuLib;
+ System.load(libPath);
+ success = true;
+ break;
+ } catch (UnsatisfiedLinkError e) {
+ continue;
}
+ };
+ if (!success) {
+ throw new RuntimeException(library + " library not found!");
}
}
static {
-
- String libDir = System.getProperty("java.io.tmpdir");
- String tmpLib = libDir+ "/" + System.mapLibraryName("Jigawatts");
-
- if (!Files.exists(Paths.get(tmpLib))) {
- try {
- copyLibrary("Jigawatts", libDir);
- } catch (IOException ex) {
- throw new RuntimeException("can't initialize Jigawatts",ex);
- }
- }
- System.load(tmpLib);
- System.loadLibrary("criu");
+ loadLib("Jigawatts");
checkpointHooks = new ArrayList<Hook>();
restoreHooks = new ArrayList<Hook>();