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

next in thread | previous in thread | raw e-mail | index | archive | help
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.

grantpt() is a wrapper that calls a setuid program to chown the /dev/pts/%03d
slave to the new owner.

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.

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.

Cheers,
-Peter
--
Peter Wemm - peter@FreeBSD.org; peter@yahoo-inc.com; peter@netplex.com.au
"All of this is for nothing if we don't go to the stars" - JMS/B5



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?200101291424.f0TEOc451827>