Subject: bug#12040: 24.1.50; `term' hangs on FreeBSD 10.0-CURRENT without pty(4)

From: Jan Beich <[email-masked]>
Date: Thu, 16 Aug 2012 05:10:03 -0500

(cc'ing Robert in case I misread glibc code)

Glenn Morris <[email-masked]> writes:

> Jan Beich wrote:
>
>> A few ways to solve this:
>> - use openpty() in -lutil like darwin
>> - add use posix_openpt() support
>
> Thanks for the patches.
> Do you (or anyone else) have a feeling for which is the best?

I'd go with less wrappers - posix_openpt(). And also use it on netbsd,
dragonfly and probably darwin.

openpty() is implemented via posix_openpt() in libutil on recent freebsd.

posix_openpt() is a syscall on (k)freebsd. And /dev/ptmx only exists if
pty(4) is loaded, not sure how it affects binaries under linuxulator.

> As written the posix_openpt one changes the behaviour on gnu-linux
> platforms to use posix_openpt instead of getpt.

In glibc/linux case getpt() is implemented via posix_openpt():

  // sysdeps/unix/sysv/linux/getpt.c
  int
  __getpt (void)
  {
    int fd = __posix_openpt (O_RDWR);
    if (fd == -1)
      fd = __bsd_getpt ();
    return fd;
  }

In glibc/kfreebsd case getpt() iterates over /dev/ptyXX which won't work
without pty(4) in kernel.