Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Jan 2001 15:39:27 +0100
From:      Poul-Henning Kamp <phk@critter.freebsd.dk>
To:        Peter Wemm <peter@netplex.com.au>
Cc:        Brian Somers <brian@Awfulhak.org>, freebsd-arch@FreeBSD.ORG
Subject:   Re: Cloned open support 
Message-ID:  <21576.980779167@critter>
In-Reply-To: Your message of "Mon, 29 Jan 2001 06:24:38 PST." <200101291424.f0TEOc451827@mobile.wemm.org> 

next in thread | previous in thread | raw e-mail | index | archive | help
In message <200101291424.f0TEOc451827@mobile.wemm.org>, Peter Wemm writes:
>Poul-Henning Kamp wrote:
>> In message <200101291228.f0TCSgP60147@storm.FreeBSD.org.uk>, Brian Somers wri
>    tes:
>
>> >o Makes minor 0 available in /dev as a control device
>> 
>> No worries:
>> 
>> 	make_dev(..., minor = 0, "/dev/foo");
>> 
>> >o Makes minor 1 available as something that'll be cloned.
>> 
>> Nope, decide on a name which is cloned; and recognize it
>> in foo_clone(dev_t *dev, ...)  Allocate the next free minor and
>> 
>> 	if (strcmp(name, "fooclone"))
>> 		return;
>> 	... /* find free minor */
>> 	*dev = make_dev(..., minor = n, "dev/foo%03d", n);
>> 	return;
>> 
>> This should work as far as I know.  Userland needs to find the
>> right pathname, preferably without too much magic. fstat(2) +
>> devname(3) is probably doing that just fine for that.
>
>Well, how do we support Unix98 /dev/ptmx then?  This is not an academic
>question, Linux apps are starting to do it this way and if we want to run
>anything that uses ptys....
>
>          int fdm fds;
>          char *slavename;
>          extern char *ptsname();
>
>          fdm = open("/dev/ptmx", O_RDWR);   /* open master */
>          grantpt(fdm);                      /* change permission ofslave */
>          unlockpt(fdm);                     /* unlock slave */
>          slavename = ptsname(fdm);          /* get name of slave */
>          fds = open(slavename, O_RDWR);     /* open slave */
>
>Opening the master allocates you a private unit of the device with its own
>minor number.

We will support it just like that.  pts_clone() will recognize the "ptmx"
name.  Create a new dev_t and return it.  Getting the name can be done
with fstat(2) and devname(3).  A transformation to slave name is needed
but that will always be needed. and it will DTRT.

In fact, I think you can implement this in less than 20 lines of code total.

In pty_clone() you add recognition for "ptmx" as a name, but create the
pty with the "real" name (pty%c%c).  The rest of the code is needed in
the ptsname() function.  I'm not quite sure what the grantpt() and unlockpt()
does, but it sounds like ioctl(2) implemeted stuff on the fdm handle, being
dealt with in the pty driver.
	
>grantpt() is a wrapper that calls a setuid program to chown the /dev/pts/%03d
>slave to the new owner.

ARGH! -- Ohh, allright, you said Linux.  You can do that in the pty_clone()
function in the make_dev() call so this can become a null function.

>unlockpt() does an ioctl on the master that tells it to revoke all access
>to the slave and kill off any existing processes that have fd's to it.  It
>allows the new process to now open it with guarantees that there are no
>races (you now own it, mode 600) and everything/everyone esle got nuked.

Check, we will not even open a slave if this hasn't been done already.

>You can then open the slave at your leisure.
>
>There is no need to "create" /dev/ptm/%03d as it is all multiplexed off
>the single node.  One /dev/pts/%03d is created when a master node is opened.

We don't have that choice, we need to have separate vnodes on the master
side also or we can't track the open/dup/close counts reliably.

--
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?21576.980779167>