daniele77 / cli

A library for interactive command line interfaces in modern C++
Boost Software License 1.0
1.23k stars 140 forks source link

Bad file descriptor on ARM build #217

Closed inf265 closed 7 months ago

inf265 commented 1 year ago

Hi, first of all many thanks for this work, it is amazing, I was able to make a cli in nearby no-time. I am using standalone version with:

   89  mkdir build
   90  cd build/
   91  cmake .. -DCLI_BuildExamples=ON -DCLI_UseStandaloneAsio=ON
   92  cmake --build .
   93  cd examples/
   94  ./complete

and then telnet to localhost 5000. That works fine on my local PC x86. Then I did the same on an iMX8 ARM aarch64, the telnet session immediately closes

Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
cli> Terminating this session...
Connection closed by foreign host.

and the process where "complete" is running exits with:

cli> Exception caugth in main: shutdown: Bad file descriptor

What I've seen when compiling on ARM was a warning:

/home/root/cli/include/cli/detail/linuxkeyboard.h:153:13: warning: case label value is less than minimum value for type [-Wswitch-outside-range]
  153 |             case EOF:
      |             ^~~~
[ 83%] Linking CXX executable complete

Any help appreciated...

inf265 commented 1 year ago

bt.txt

bt_with_debug.txt

I removed the try catch in main and added a gdb backtrace

daniele77 commented 1 year ago

Hi @inf265 ,

Thank you for using the library and reporting the issue. Although I don't have access to ARM to replicate the problem directly, I have some insights into what you've described.

The warning may be caused by the fact that the library is using:

    auto ch = GetChar();
    ...
    switch(ch) {
       case EOF: ... 

If, in your system, GetChar() returns an unsigned type and EOF has a negative value, it could trigger this warning. However, this would only affect the local session, not the remote one. Therefore, the abrupt closure of your telnet connection is likely not caused by this warning.

The exception in the main is thrown by Session::Disconnect():

    virtual void Disconnect()
    {
        socket.shutdown(asiolib::ip::tcp::socket::shutdown_both);
        socket.close();
    }

This method is called by the exit action of a CliTelnetSession. So, something is causing the telnet session to close, leading to the subsequent exception. Investigating the root cause of the telnet session closing soon after the connection is essential.

You can try using a newer version of the asio library (or try with Boost) if you're using an older one. Additionally, experimenting with different telnet clients or connection options might provide more insights.

Please keep me informed if you gather new information.

edenbenzimra commented 10 months ago

I had the same issue, solved it by changing the Telnet negotiation mode to Active :)

daniele77 commented 10 months ago

Should we add in the README.md file that the telnet client must be configured with negotiation = active to successfully connect to the CLI?

edenbenzimra commented 10 months ago

I apologize I meant passive not active 😄 Maybe you should add it to the read me (windows is ok with both it solved the problem on Linux) also I found that in genericasioremotecli I had to remove the lines 81,84,87 in order to fix the Linux problem (a combination of the two - telnet négociation and removing the lines) I'm havent really figured out why but that is what worked for me 😄

daniele77 commented 9 months ago

I have fixed an ARM issue with the commit: 2921758 Please, check if this solves your problem and let me know. Thanks.