implement openpty(3C), forkpty(3C), and login_tty(3C)
Other systems have openpty() and forkpty() functions to make dealing with pty's considerably easier and more foolproof than they are for us.
The way it must be done on illumos is basically to implement whichever of those two routines you want, completely, and yourself. This should not be.
A correct implementation of each (and anything related I don't know of) should be in libc.
Updated by Joshua M. Clulow almost 2 years ago
I don't believe these interfaces appear in any published UNIX standard. They do, however, appear on OpenBSD, FreeBSD, Mac OS X, Oracle Solaris, and Linux systems:
int openpty(int *, int *, char *, struct termios *, struct winsize *); int forkpty(int *, int *, char *, struct termios *, struct winsize *); int login_tty(int);
OpenBSD offers some additional interfaces in this family:
int getptmfd(void); int fdopenpty(int, int *, int *, char *, struct termios *, struct winsize *); int fdforkpty(int, int *, char *, struct termios *, struct winsize *);
They seem somewhat predicated on having a file descriptor that represents a management device. What we have is, instead, a cloning device: you open it and the act of opening it is what gets you a pseudo terminal pair. As it isn't exactly clear how these would work for us, and they don't seem to be widely available otherwise, so I am going to leave them out.
These routines will go directly in the C library. The header situation is something of a mess; each platform has made a slightly different choice, and we don't have the
pty.h header that Linux (and only Linux) is using here. What we do have is
termios.h, which you will need for
struct termios anyway, so that seems as good a place as any -- and is the choice that Oracle have made as well.