Subject: Re: unexpected behaviour of grantpt(3)
To: None <tech-kern@NetBSD.org>
From: None <joerg@britannica.bec.de>
List: tech-kern
Date: 02/18/2006 16:22:50
On Sat, Feb 18, 2006 at 03:57:26PM +0100, Klaus Heinz wrote:
> Can anyone (Christos?) explain why NetBSD's grantpt() (or rather
> TIOCGRANTPT) implements this extension?
> Are there any other systems which act the same?

I don't really think it is such an unexpected behaviour.
Basically, grantpt can be implemented with one of two backing
mechanisms:
- static /dev + chmod / chown of master and slave
- dynamic /dev or /dev/pty: ownership of slave is based on the calling
process.

Linux has implemented the latter for ages, the former is what openpty
traditionally did. To prevent races in the former way, you must close
all other references to slave, since they might have been acquired by
the original permissions.

The real question for me is why do you mix openpty and grantpt at all?
You should use posix_openpt and grantpt for this purpose.

Joerg