Subject: Re: Linux pseudo pty
To: Emmanuel Dreyfus <p99dreyf@criens.u-psud.fr>
From: Christos Zoulas <christos@zoulas.com>
List: tech-kern
Date: 02/14/2001 15:52:12
On Feb 14,  9:08pm, p99dreyf@criens.u-psud.fr (Emmanuel Dreyfus) wrote:
-- Subject: Linux pseudo pty

| > 4. Look at the cloning device on compat_svr4 to see how the pty
| > multiplexor code can be made to work. I am not sure what linux needs
| > [svr4_net.c].
| 
| There is some stuff about ptmx in this file: svr4_ptm_alloc. And it
| seems Linux binaries try to use that device
| 
|    673 xterm    NAMI  "/emul/linux/dev/ptmx"
|    673 xterm    NAMI  "/dev/ptmx"
|    673 xterm    RET   open -1 errno 2 No such file or directory

And they don't find it. And start opening tty's sequentially,

|    673 xterm    CALL  open(0x7fffd0b8,0x2,0x76)
|    673 xterm    NAMI  "/emul/linux/dev/ptyp0"
|    673 xterm    NAMI  "/dev/ptyp0"
|    673 xterm    RET   open -1 errno 5 Input/output error
|    673 xterm    CALL  open(0x7fffd0b8,0x2,0x76)
|    673 xterm    NAMI  "/emul/linux/dev/ptyp1"
|    673 xterm    NAMI  "/dev/ptyp1"
|    673 xterm    RET   open -1 errno 5 Input/output error
|    673 xterm    CALL  open(0x7fffd0b8,0x2,0x76)
|    673 xterm    NAMI  "/emul/linux/dev/ptyp2"
|    673 xterm    NAMI  "/dev/ptyp2"
|    673 xterm    RET   open -1 errno 5 Input/output error
|    673 xterm    CALL  open(0x7fffd0b8,0x2,0x76)
|    673 xterm    NAMI  "/emul/linux/dev/ptyp3"
|    673 xterm    NAMI  "/dev/ptyp3"
|    673 xterm    RET   open 4

until they find one that works...

| I've got really little knoledge about terminal handling. I assume that
| ptmx would give some important information about which ptyp to open, and
| if it cannot use it, it tries all of them sequentially.

ptmx opens the first useable pty and returns a file descriptor to it.

| What is the /dev/ptmx exactly for, and how svr4_net.c could help? Do I
| need to make a device driver for /dev/ptmx? And if I do, where will it
| go in the kernel sources?

That is what the code in svr4_net does. If you want to support ptmx, you
can just steal the code, but it looks like the normal allocation will work
since xterm falls back to scanning for a free pty.

| There is another strange error later. xterm run utempter (I don't know
| what this binary is for, there is no man page about it), and it fails
| with this:
| 
|    676 utempter GIO   fd 2 wrote 45 bytes
|        "fd 3 is not a master pty device (it is 4, 3)
|        "
| 
| I assume this 4,3 is major and minor? Do we lack a device translation
| there that should be handled in linux_sys_fakedev?

Right you need to make the major number for the pty to be the right one
for the linux application... Suckage. on i386 it is 2; looks like on
ppc it is 4.

christos