The application I am developing uses pseudo-terminal but it does not work as expected.
The following example program works properly at a rate of about 10%. It freezes about 90%.
This program executes /bin/uname on pseudo-terminal and displays the result.
Next, I made it a bit more complicated using Qt threads. And this doesn’t work as well.
This program executes /bin/bash, ls, exit, and print the result.
Both programs work properly on Linux and macOS.
I can not investigate which problem is my program or Haiku. Please help me.
I’m more or less stumped. The behavior I get is that, sometimes, the parent read(ptm) fails to return, when the child process is gone and the slave unit has presumably closed. I tried several things that changed how often it would fail, but didn’t find a combination that would never fail in that manner.
One thing that helped (more frequent success) was to remove the unnecessary dup2(ptm, 0) in the parent.
One thing that made it worse, curiously, was to wait for a second (sleep(1)), before the second read(ptm). That could have something to do with timer signal handling in sleep(), or something like that, or another explanation is that the “read returns 0” semantics just isn’t really supported on Haiku and only happens to work if you’re already reading when the slave fd closes. It’s unfortunate that it doesn’t work, if that’s the case, but for all I know may not be required by POSIX.
Unless there’s a better answer, I guess you could make it more robust with waitpid() and select().
For the record, neither works for me. ptsname() and open() can come before or after the fork, no effect. Same outcome with openpty() (or rather forkpty() is what I tried), so presumably the issue is with the pty device itself.