Subject: Re: Linux pseudo tty
To: None <tech-kern@netbsd.org>
From: Christos Zoulas <christos@zoulas.com>
List: tech-kern
Date: 02/14/2001 00:28:18
In article <1eosjsq.1n8c6c11356f9rM@[10.0.12.137]>,
Emmanuel Dreyfus <p99dreyf@criens.u-psud.fr> wrote:
>Here is the ktrace of Linux's xterm on PowerPC.
>
> 210 xterm CALL ioctl(0x4,_IOR('T',0x30,0x4),0x7fffd178)
> 210 xterm RET ioctl 0
> 210 xterm CALL stat(0x5040ce08,0x7fffcbc8)
> 210 xterm NAMI "/emul/linux/dev/pts/0"
> 210 xterm NAMI "/dev/pts/0"
> 210 xterm RET stat -1 errno 2 No such file or directory
>
>_IOR('T',0x30,0x4) is LINUX_TIOCGPTN, it should return the pty number. I
>implemented it like this
>
> case LINUX_TIOCGPTN: /* get Pty number */
> tty = curproc->p_pgrp->pg_session->s_ttyp;
> idat = minor(tty->t_dev);
> error = copyout (&idat, SCARG(uap,data), sizeof idat);
>
>It seems Linux uses things we don't do (the /dev/pts stuff). I've got
>very basic understanding of the tty stuff. Anyone can explain me what is
>going wrong?
1. All ioctl routines pass in struct proc *p, so you should be using that
instead of curproc. New code should avoid using curproc.
2. s_ttyp could be null if the process does not have a controlling tty.
In that case my guess is that ioctl should return ENOTTY or something.
3. For sizeof I usually do sizeof(output), instead of input for safety.
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].
5. Well you are returning the right number, but you need to make the correct
device nodes under /dev/pts [slave] /dev/ptc [master]
I.e.
ln -s /dev/ptyp0 /dev/ptc/0
ln -s /dev/ttyp0 /dev/pts/0
...
ln -s /dev/ptypf /dev/ptc/15
ln -s /dev/ttypf /dev/pts/15
...
ln -s /dev/ptyq0 /dev/ptc/16
ln -s /dev/ttyq0 /dev/pts/16
...
I prefer symlinks rather than making the actual devices so that locking
works.
I hope that helps. Of course it would be nice if NetBSD supported a pty
cloning device as opposed to the current scanning kludge...
christos