Subject: /dev/ptmx
To: None <>
From: Christos Zoulas <>
List: tech-kern
Date: 05/23/2004 16:28:32
As you all know, we still do the ugly song and dance to allocate a pty,
which amongst other things requires us to have programs that allocate
ptys to be setuid root. 

The POSIX documented way is not very nice...
Ref: search for:

    posix_openpt(int flags); basically open("/dev/ptmx", flags)
    int grantpt(int fd);
    int unlockpt(int fd);
    char *ptsname(int fd);

OpenBSD implemented a different (better) way of doing this, by adding
/dev/ptm, and getting the master, slave fd's and the master and slave
names through an ioctl(3), doing the chown/chmod's in the process.

The posix way, requires a userland setuid program ``pt_chown'' to do
the nasty chown job, which is called from grantpt(3).

We could keep compatibility with the posix interface, by doing most
of the work in the kernel (i.e. opening "/dev/ptmx" does the chown
too, making grantpt and unlockpt a no-op, then having ptsname()
derive the slave name using an ioctl, or by applying a formula to
the device minor number we get from fstat() [since we don't have
the clean namespace /dev/ptc/N that SVRX has].

Never-the-less, we should add "/dev/ptm" device that OpenBSD added,
because it is simple and fits our openpty(3) mode.

Is it worth having this posix compatibility? Or should we just 
forget about it?

To summarize the proposal is:

1. Add /dev/ptm like OpenBSD has.
2. Optionally add /dev/ptmx for Posix compatibility that works like above.