Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jni provider fails on linux #896

Closed
jvalkeal opened this issue Nov 2, 2023 · 6 comments
Closed

Jni provider fails on linux #896

jvalkeal opened this issue Nov 2, 2023 · 6 comments
Milestone

Comments

@jvalkeal
Copy link
Contributor

jvalkeal commented Nov 2, 2023

I'm still debugging this issue on my side but I wanted to throw this out here if it immediately rings a bell.

When trying to use 3.24.1 I'm getting into trouble with tests(where I don't have a proper tty). I get jni and exec and then jni fails with newTerminal with

java: symbol lookup error: /tmp/jlinenative-3.24.1-e342cc4f6f2aa9de-libjlinenative.so: undefined symbol: openpty

jline-error-1

If I run my cli in a real terminal and attach debugger, I have jni, jansi, jna and exec but jni doesn't fail with sysTerminal and I get PosixSysTerminal.

jline-error-2

I'm on Ubuntu 18.04.6 LTS in this system.

@jvalkeal
Copy link
Contributor Author

jvalkeal commented Nov 2, 2023

So it looks to be CLibrary.openpty() in LinuxNativePty.open() which throws that hard error if org.jline:jline-terminal-jna is in a classpath. If jna is not in a classpath then newTerminal throws NoClassDefFoundError and JLine catches that and moves on.

@gnodet
Copy link
Member

gnodet commented Nov 2, 2023

Not sure to understand, is the problem with the JNI provider or the JNA provider ? Or are those two different problems ?

@jvalkeal
Copy link
Contributor Author

jvalkeal commented Nov 2, 2023

I'm a bit rusty with this jni stuff so give me some rope here. Looks like when this /tmp/jlinenative-3.24.1-e342cc4f6f2aa9de-libjlinenative.so is extracted and used this call

CLibrary.openpty(
master,
slave,
buf,
attr != null ? termios(attr) : null,
size != null ? new CLibrary.WinSize((short) size.getRows(), (short) size.getColumns()) : null);

doesn't work. Looking ldd:

$ ldd /tmp/jlinenative-3.24.1-e342cc4f6f2aa9de-libjlinenative.so
	linux-vdso.so.1 (0x00007fff87b3c000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc9d0365000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fc9d0959000)

I don't see it linking to libutil where I think openpty is. If I do:

export LD_PRELOAD=/lib/x86_64-linux-gnu/libutil.so.1

before build then the error goes away.

@jvalkeal
Copy link
Contributor Author

jvalkeal commented Nov 7, 2023

Quickest way to see this in JLine itself is to force system to false and run demo. Felix sets system to true so I had to tweak a code.

$ git diff
diff --git a/terminal/src/main/java/org/jline/terminal/TerminalBuilder.java b/terminal/src/main/java/org/jline/terminal/TerminalBuilder.java
index 64708c7d..a08d5ea0 100644
--- a/terminal/src/main/java/org/jline/terminal/TerminalBuilder.java
+++ b/terminal/src/main/java/org/jline/terminal/TerminalBuilder.java
@@ -148,7 +148,7 @@ public final class TerminalBuilder {
     private String type;
     private Charset encoding;
     private int codepage;
-    private Boolean system;
+    private Boolean system = false;
     private SystemOutput systemOutput;
     private String provider;
     private String providers;
@@ -179,7 +179,7 @@ public final class TerminalBuilder {
     }
 
     public TerminalBuilder system(boolean system) {
-        this.system = system;
+        // this.system = system;
         return this;
     }

13:07 $ ./build demo
Launching Gogo JLine...
Classpath: /home/jvalkealahti/repos/jvalkeal/jline3/demo/target/classes:/home/jvalkealahti/repos/jvalkeal/jline3/demo/target/lib/jline-terminal-jni-3.24.2-SNAPSHOT.jar:/home/jvalkealahti/repos/jvalkeal/jline3/demo/target/lib/jline-terminal-jansi-3.24.2-SNAPSHOT.jar:/home/jvalkealahti/repos/jvalkeal/jline3/demo/target/lib/jline-console-3.24.2-SNAPSHOT.jar:/home/jvalkealahti/repos/jvalkeal/jline3/demo/target/lib/jline-remote-telnet-3.24.2-SNAPSHOT.jar:/home/jvalkealahti/repos/jvalkeal/jline3/demo/target/lib/jline-terminal-3.24.2-SNAPSHOT.jar:/home/jvalkealahti/repos/jvalkeal/jline3/demo/target/lib/jline-builtins-3.24.2-SNAPSHOT.jar:/home/jvalkealahti/repos/jvalkeal/jline3/demo/target/lib/jline-style-3.24.2-SNAPSHOT.jar:/home/jvalkealahti/repos/jvalkeal/jline3/demo/target/lib/jline-remote-ssh-3.24.2-SNAPSHOT.jar:/home/jvalkealahti/repos/jvalkeal/jline3/demo/target/lib/jline-terminal-jna-3.24.2-SNAPSHOT.jar:/home/jvalkealahti/repos/jvalkeal/jline3/demo/target/lib/jline-terminal-ffm-3.24.2-SNAPSHOT.jar:/home/jvalkealahti/repos/jvalkeal/jline3/demo/target/lib/jline-reader-3.24.2-SNAPSHOT.jar:/home/jvalkealahti/repos/jvalkeal/jline3/demo/target/lib/jline-native-3.24.2-SNAPSHOT.jar:/home/jvalkealahti/repos/jvalkeal/jline3/demo/target/lib/jline-groovy-3.24.2-SNAPSHOT.jar:/home/jvalkealahti/repos/jvalkeal/jline3/demo/target/lib/org.apache.felix.gogo.runtime-1.1.6.jar:/home/jvalkealahti/repos/jvalkeal/jline3/demo/target/lib/org.apache.felix.gogo.jline-1.1.8.jar
java: symbol lookup error: /tmp/jlinenative-3.24.2-349cf11782093e50-libjlinenative.so: undefined symbol: openpty

In my issue above I used custom streams(for doing testing), so it ended up calling:

terminal = prov.newTerminal(
name, type, in, out, encoding, signalHandler, paused, attributes, size);

@gnodet
Copy link
Member

gnodet commented Nov 7, 2023

Sorry for the delay. The thing I'm wondering about, is how to change the makefile so that the libraries are linked with libutil...

@dattasid
Copy link
Contributor

You may need to load required libraries explicitly whenever you use Linker.nativeLinker() . Linker.defaultLookup() behaves differently depending on architecture, I dont think it is reliable.

gnodet added a commit to gnodet/jline3 that referenced this issue Dec 22, 2023
@gnodet gnodet closed this as completed in b08189a Dec 22, 2023
@gnodet gnodet added this to the 3.25.0 milestone Dec 22, 2023
gnodet added a commit that referenced this issue Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants