Skip to content

Commit

Permalink
Improve error reporting when the tmp dir has the noexec flag, fixes #193
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Oct 13, 2021
1 parent 454d858 commit 3d97645
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/main/java/org/fusesource/jansi/internal/JansiLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public static synchronized boolean initialize() {
try {
loadJansiNativeLibrary();
} catch (Exception e) {
throw new RuntimeException("Unable to load jansi native library. You may want set the `jansi.graceful` system property to true to be able to use Jansi on your platform", e);
if (!Boolean.parseBoolean(System.getProperty(AnsiConsole.JANSI_GRACEFUL, "true"))) {
throw new RuntimeException("Unable to load jansi native library. You may want set the `jansi.graceful` system property to true to be able to use Jansi on your platform", e);
}
}
return loaded;
}
Expand Down Expand Up @@ -249,7 +251,17 @@ private static boolean loadNativeLibrary(File libPath) {
nativeLibraryPath = path;
return true;
} catch (UnsatisfiedLinkError e) {
System.err.println("Failed to load native library:" + libPath.getName() + ". osinfo: " + OSInfo.getNativeLibFolderPathForCurrentOS());
if (!libPath.canExecute()) {
// NOTE: this can be tested using something like:
// docker run --rm --tmpfs /tmp -v $PWD:/jansi openjdk:11 java -jar /jansi/target/jansi-xxx-SNAPSHOT.jar
System.err.printf("Failed to load native library:%s. The native library file at %s is not executable, "
+ "make sure that the directory is mounted on a partition without the noexec flag, or set the "
+ "jansi.tmpdir system property to point to a proper location. osinfo: %s%n",
libPath.getName(), libPath, OSInfo.getNativeLibFolderPathForCurrentOS());
} else {
System.err.printf("Failed to load native library:%s. osinfo: %s%n",
libPath.getName(), OSInfo.getNativeLibFolderPathForCurrentOS());
}
System.err.println(e);
return false;
}
Expand Down Expand Up @@ -331,11 +343,8 @@ private static void loadJansiNativeLibrary() throws Exception {
}
}

loaded = false;
if (!Boolean.parseBoolean(System.getProperty(AnsiConsole.JANSI_GRACEFUL, "true"))) {
throw new Exception(String.format("No native library found for os.name=%s, os.arch=%s, paths=[%s]",
OSInfo.getOSName(), OSInfo.getArchName(), join(triedPaths, File.pathSeparator)));
}
throw new Exception(String.format("No native library found for os.name=%s, os.arch=%s, paths=[%s]",
OSInfo.getOSName(), OSInfo.getArchName(), join(triedPaths, File.pathSeparator)));
}

private static boolean hasResource(String path) {
Expand Down

0 comments on commit 3d97645

Please sign in to comment.