The function 'posix_openpt' do not work as I expected


#1

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.


#2

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().

Didn’t look at the 2nd program.


#3

This is not the right place for bugreports. Please use https://dev.haiku-os.org.


#4

You can try to invoke with “strace -t unixpty1” to display the executed syscalls. If it freezes, you can at least tell on which syscall it hangs.


#5

The recommendation would be to call ptsname() and open() before the fork call. Or use openpty().


#6

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.


#7

Can someone report this issue to the development team instead of me?


#8

Uh, why? You have signed up for a forum account, why can’t you sign up for a Trac account and file a formal bug report?


#9

The behavior of the pty driver has been improved. This should fix the problem exposed in this post.