Re: pty pairs in POSIX with devpts

H. Peter Anvin (hpa@transmeta.com)
28 Apr 1998 00:14:32 GMT


Followup to: <E0yTvTU-0006eI-00@taurus.cus.cam.ac.uk>
By author: pjb1008@cam.ac.uk (Peter Benie)
In newsgroup: linux.dev.kernel
>
> What does it do if both /dev/ptmx and /dev/pty?? devices exist?
>
> Suppose a user runs a program that allocates a pty by scanning the
> /dev/pty?? devices and chowning the corresponding slave device when it
> manages to open a pty master. The program may terminate without
> cleaning up. (Let's say the user sent it a SIGQUIT.) The master and
> slave sides of the pty are closed, so the pty can be allocated again,
> but the owner of the slave device remains as the user who started the
> program.
>
> Now suppose another user runs a program that allocates a pty using
> /dev/ptmx and /dev/pts/??. There's a good chance that it will get the
> pty from the program that just died. Now the pty slave is available
> twice - once to the correct user in /dev/pts, and once to somebody
> else as /dev/tty??.
>
> To make the device safe, you still have to use vhangup(), but now you
> have to locate the corresponding /dev/tty?? entry and chown it, even
> though you are using SysV-style pty allocation.
>
> IMO, it would be sensible for slave devices in /dev/pts to have a
> different major number so that the two allocation schemes were better
> separated from each other.
>

This is a very good point. Obviously you can't allocate it twice, but
there is nastiness about having the two allocated from the same pool.
One possibility is to remove the restriction that you need to have
used /dev/ptmx in order for the device node to exist in /dev/pts, and
make all the /dev/tty?? entries symlinks to /dev/pts. Does anyone
know if that solution would work properly? I have a nasty feeling it
wouldn't.

-hpa

-- 
    PGP: 2047/2A960705 BA 03 D3 2C 14 A8 A8 BD  1E DF FE 69 EE 35 BD 74
    See http://www.zytor.com/~hpa/ for web page and full PGP public key
        I am Bahá'í -- ask me about it or see http://www.bahai.org/
   "To love another person is to see the face of God." -- Les Misérables

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu