Re: devfs v136, ZIP disks and glibc-2.1.2

Zack Weinberg (zack@bitmover.com)
Mon, 08 Nov 1999 09:59:11 -0800


Richard Gooch wrote:
> Andreas Jaeger writes:
> > >>>>> Stefan Monnier writes:
> >
> > >>>>> "Andreas" == Andreas Jaeger <aj@suse.de> writes:
> > >> We have to check for the magic because you can have a directory
> > >> /dev/pts but not devpts compiled into your kernel. Therefore we need
> > >> a way to know exactly if devpts is available.
> >
> > Stefan> Isn't it possible to use a more direct approach where you
> > Stefan> use the devpts code and if the kernel burps or if the file does not
> > Stefan> appear under /dev/pts, you revert to the other case ?
> >
> > Something I don't understand from looking at the current devfs patch
> > is why the statfs call doesn't work. /dev/pts is still it's own
> > filesystem which has its own, well known magic value since devpts is
> > used - or is devfs not passing the calls through to devpts? Could
> > somebody enlighten me?
>
> You're assuming that a devfs-system will still mount devpts on
> /dev/pts, which is not necessarily the case (and is actually
> undesirable). Devfs has a "live" implementation of /dev/pts. In fact,
> devfs fully implemented a dynamic /dev/pts before devpts even existed.
>
> So that's why glibc at least needs to check the magic number of /dev
> and see if /dev/pts is a directory.
>
> But I still favour the speculative open method (get a master, then try
> and open the slave in /dev/pts, if it fails, set a flag). It's robust
> and allows alternative implementations of /dev/pts (such as a daemon).
> Why don't you implement it this way?

The API does not permit this implementation. The Unix98 way to get a
pty is

mfd = open("/dev/ptmx", O_RDWR);
grantpt(mfd);
unlockpt(mfd);
sfd = open(ptsname(mfd), O_RDWR);

This can't possibly work with BSD ptys, so there is an extension. If
you replace the first open with

mfd = getpt();

then it is documented to work no matter what sort of ptys you have.
But notice that we don't look for the slave till later. At that point
it is too late to back up and switch to BSD ptys - the user already
has the master fd squirreled away.

You cannot look for the slave inside getpt() because it may not exist
at that point. devptsfs creates slaves when someone opens them
successfully. But until unlockpt() is called, no one, not even root,
can open the slave.

Even if we could know at getpt() time whether the Unix98 slave
existed, we would still need to know if devfs or devptsfs were in
use. If neither one is in use, grantpt() has to run a setuid helper
program that resets the permissions of the slave. We don't want to do
that if it can be avoided, since it is an expensive and dangerous
operation.

zw

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/