Hello,
I am trying to run expect (5.45.4 with tcl 8.6.13) on the Haiku operating system, with this very simple script:
spawn echo
expect eof
On Linux, this works well and returns immediately. On Haiku, the end of file seems to not be detected and the expect blocks for 10 seconds (the default timeout). The problem is probably on Haiku side and I'm happy to fix whatever is needed there. However, I appreciate some help on how to investigate this, as I quickly got lost trying to understand the use of TCL channels and event loops.
Hi,
Normally (on Linux) the best way to debug these sorts of issues are with strace. I don't know if something similar is available on Haiku?
Regards,
Nils
On 30 June 2023 at 22:49:22 +02:00, Adrien Destugues pulkomandy@users.sourceforge.net wrote:
Related
Support Requests: #8
Tcl's channel system will use Expect's input handler (ExpInputProc in exp_chan.c) so verify whether ExpInputProc is even being called. The input handler basically just does a read() which should return immediately IF the pty has been properly configured.
Pty misconfiguration is the most likely issue for a new port since every OS loves to have its own pty variant. Verify that configure is choosing the right implementation. If there is no right implementation, might require a comparison of other's ptys to Haiku's ptys to figure out how to add support for Haiku to Expect.
The PTY system is configured to use openpty and should behave similarly to the BSDs, but of course, there could be bugs. It seems to be working except for the end of file detection. For example if I do:
This is working fine.
Yes, we have strace. Here is the trace on Haiku:
You can see that the "hi" output from echo is read by expect without problems, but then it waits for the end of file and this results in "Operation timed out" (10 seconds later, as that's the default timeout).
Here we see a FUTEX_WAKE_PRIVATE that does not block, followed by a read that returns EIO, which is detected as an end of file.
So it looks like the problem happens before the input handler is called to read the end of file?
I have made some testing of PTY behavior in Haiku and I think I found a bug: https://dev.haiku-os.org/ticket/18486
However, I am not sure where in expect or in tcl this would come into play, as I didn't find an use of select or poll (probably I just missed it because I don't know where to look).
I have now fixed that bug: closing the pty was not unblocking poll()/select() waiting for read events on the other side of it. However, that didn't help: expect is still not noticing when the pty is closed by the child exiting.
The previous strace output was missing spawned threads, here is a more complete one: