-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Unix shell support for nerves_ssh #84
Comments
While working on saleyn/erlexec#159, I found that compiling with musl works fine one alpine; so maybe this issue is already fixed by nerves-project/nerves_system_br@fb4e008, I'll try that out soon. Inspired by https://github.com/jjcarstens/extty, I tried to implement https://github.com/SteffenDE/ex_pty, but looking at the resulting C code I'd very much prefer to use erlexec. As already mentioned above, my C is horrible, but if someone is inspired by this and likes to clean it up, feel free. |
My feeling is that if |
So I just tried using the x86_64 base system with musl, the error is still the same iirc:
Not sure what to make of this. |
Looks like erlexec has a hard requirement on glibc. I would need to investigate further if that can be mediated in the lib, or if we can enable something like |
Hmm I though alpine uses musl, but there compiling erlexec works fine:
So gcompat does not seem to be needed (see https://pkgs.alpinelinux.org/contents?file=&path=&name=gcompat&branch=v3.16&repo=community&arch=x86_64). |
So, quick update: Passing /Users/steffen/.nerves/artifacts/nerves_toolchain_x86_64_nerves_linux_musl-darwin_arm-1.6.0/bin/x86_64-nerves-linux-musl-g++ \
c_src/ei++.o c_src/exec.o c_src/exec_impl.o \
--sysroot=/Users/steffen/.nerves/artifacts/nerves_system_x86_64-portable-1.20.0/staging \
-Wl,-rpath-link,/Users/steffen/.nerves/artifacts/nerves_toolchain_x86_64_nerves_linux_musl-darwin_arm-1.6.0/x86_64-nerves-linux-musl/sysroot/usr/lib \
-L/Users/steffen/.nerves/artifacts/nerves_system_x86_64-portable-1.20.0/staging/usr/lib/erlang/lib/erl_interface-5.3/lib \
-lei -o /Users/steffen/Desktop/MonitorNews/nerves_containers/nerves_ssh_shell/examples/ssh_multi_daemon_example/_build/x86_64_dev/lib/erlexec/priv/x86_64-nerves-linux-musl/exec-port Changing the --- old 2022-07-09 15:44:37.000000000 +0200
+++ deps/nerves_system_br/nerves_env.exs 2022-07-09 15:10:16.000000000 +0200
@@ -35,6 +35,14 @@
String.replace_suffix(gcc, "-gcc", "")
end
+
+ def toolchain_sysroot(toolchain_path) do
+ path = toolchain_path |> Path.join("*/sysroot") |> Path.wildcard() |> List.first()
+
+ path || Mix.raise("""
+ Could not find sysroot of toolchain!
+ """)
+ end
end
system_path =
@@ -43,7 +51,7 @@
sdk_sysroot = Path.join(system_path, "staging")
-{_toolchain_path, crosscompile} =
+{toolchain_path, crosscompile} =
if File.dir?(Path.join(system_path, "host")) do
# Grab the toolchain from a Buildroot output directory
toolchain_path = Path.join(system_path, "host")
@@ -141,7 +149,7 @@
"-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -pipe -O2 --sysroot #{sdk_sysroot}"
)
-System.put_env("LDFLAGS", "--sysroot=#{sdk_sysroot}")
+System.put_env("LDFLAGS", "--sysroot=#{sdk_sysroot} -Wl,-rpath-link,#{Utils.toolchain_sysroot(toolchain_path)}/usr/lib")
System.put_env("ERL_CFLAGS", "-I#{erts_dir}/include -I#{erl_interface_dir}/include")
System.put_env("ERL_LDFLAGS", "-L#{erl_interface_dir}/lib -lei")
@@ -218,4 +226,3 @@
run 'make menuconfig' and look for the Erlang options.
""")
end
- I tested this using nerves_system_x86_64 and it seems to work (despite the system being very broken, see nerves-project/nerves_system_x86_64#170). |
So it turns out that nerves-project/nerves_system_x86_64#170 also fixed this issue. Turns out that using the musl toolchain with a gnu system leads to some strange issues 😄 As everything seems to work now, I'll try to come up with a draft PR soon to include the system shells as optional components in |
Hello there,
this is a continuation of a discussion from #83. I think it would be a great feature to allow connecting to nerves devices using SSH into a unix shell, separate to the existing IEx / Erlang shells. Therefore, I've written
:nerves_ssh_shell
and this issue discusses possible ways to maybe integrate this feature into:nerves_ssh
in the future.Some thoughts:
The only problem I see is that currently nerves_ssh_shell depends on erlexec, as this is the only way I found to actually run a process inside a pseudoterminal from the BEAM world and it currently does not compile for musl based systems.
I've seen jjcarstens/extty#8, but this does not create a "real" pseudoterminal for running interactive shell commands.
nerves.system.shell
works around this by wrapping commands with thescript
utility, but this is not a good solution as there seems to be no way to handle resizing terminals properly. Also, depending on tools likescript
andstty
on nerves would require changing the base systems.So with all that, using erlexec works great and I've already contributed a change that makes using interactive terminals much easier. So maybe the way forward is:
:nerves_ssh
and clarify what needs to be configured for Unix shell supportssh_server_channel
s from:nerves_ssh_shell
for using the shells, either as SSH subsystem (with reduced features) or using a separate daemonStill, I feel like I this is maybe not the best solution, as the configuration needed for erlexec is global and might interfere with users that already use erlexec with other settings. Maybe there could be a very small wrapper around
Port
or a nif that allows spawning a command in a pty (https://man7.org/linux/man-pages/man7/pty.7.html) and setting possible pty options (modes, window size, ...), but I'm not proficient enough in C / Rust / Zig to write anything like this.The text was updated successfully, but these errors were encountered: