Skip to content

Commit 3d97645

Browse files
committed
Improve error reporting when the tmp dir has the noexec flag, fixes #193
1 parent 454d858 commit 3d97645

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/main/java/org/fusesource/jansi/internal/JansiLoader.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ public static synchronized boolean initialize() {
6161
try {
6262
loadJansiNativeLibrary();
6363
} catch (Exception e) {
64-
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);
64+
if (!Boolean.parseBoolean(System.getProperty(AnsiConsole.JANSI_GRACEFUL, "true"))) {
65+
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);
66+
}
6567
}
6668
return loaded;
6769
}
@@ -249,7 +251,17 @@ private static boolean loadNativeLibrary(File libPath) {
249251
nativeLibraryPath = path;
250252
return true;
251253
} catch (UnsatisfiedLinkError e) {
252-
System.err.println("Failed to load native library:" + libPath.getName() + ". osinfo: " + OSInfo.getNativeLibFolderPathForCurrentOS());
254+
if (!libPath.canExecute()) {
255+
// NOTE: this can be tested using something like:
256+
// docker run --rm --tmpfs /tmp -v $PWD:/jansi openjdk:11 java -jar /jansi/target/jansi-xxx-SNAPSHOT.jar
257+
System.err.printf("Failed to load native library:%s. The native library file at %s is not executable, "
258+
+ "make sure that the directory is mounted on a partition without the noexec flag, or set the "
259+
+ "jansi.tmpdir system property to point to a proper location. osinfo: %s%n",
260+
libPath.getName(), libPath, OSInfo.getNativeLibFolderPathForCurrentOS());
261+
} else {
262+
System.err.printf("Failed to load native library:%s. osinfo: %s%n",
263+
libPath.getName(), OSInfo.getNativeLibFolderPathForCurrentOS());
264+
}
253265
System.err.println(e);
254266
return false;
255267
}
@@ -331,11 +343,8 @@ private static void loadJansiNativeLibrary() throws Exception {
331343
}
332344
}
333345

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

341350
private static boolean hasResource(String path) {

0 commit comments

Comments
 (0)