Help needed with Streams based pseudo ttys

Larry Philps larry at hcr.UUCP
Thu Jul 6 23:55:35 AEST 1989


In article <670 at vision.UUCP> andyw at vision.UUCP (Andy Warner) writes:
>	I need information on how to use the streams based pseudo-ttys
>distributed with Interactive 386/ix 2.0. There is a single clone major
>(/dev/ptmx), and 16 slaves (/dev/pts???). The major can be opened, but
>I can never open the slaves, even with the master being held open. It
>would seem only sensible due to the clone nature of the master, that
>I need to perform some operation to discover which slave to open. The
>header file defines two ioctl flags, but doesn't elaborate. Interactive
>refused to answer my questions, well they didn't exactly refuse, they just
>never rang back.

I have not tried this with the 386ix 2.0 version of ptys, but have done
similar things with other "clone" pty implementations.  The code
to do such a thing is usually (using your names for the devices):

	int		master, slave;
	struct stat	statbuf;
	char		slavetty[sizeof("/dev/pts00")];

	...

	/* Get the master side */
	if ((master = open("/dev/ptmx", O_RDWR)) < 0) {
		perror("/dev/ptmx");
		exit(1);
	}
	/*
	 * Stat the master and look at the minor device number of the
	 * rdev field to find out which pty the clone device assigned
	 * to us.  Then form the name of the corresponding slave pty
	 */
	if (fstat(master, &statbuf) < 0) {
		perror("fstat");
		exit(2);
	}
	(void) sprintf(slavetty, "/dev/pts%02d", minor(statbuf.st_rdev));

	if ((slave = open(slavetty, O_RDWR) < 0) {
		perror(slavetty);
		exit(2);
	}

Warning: I have not tested this or even copied it, I just typed it in
	 off the top of my head.  This is what I would try.  Use at your
	 own risk.

---
Larry Philps                             HCR Corporation
130 Bloor St. West, 10th floor           Toronto, Ontario.  M5S 1N5
(416) 922-1937                           {utzoo,utcsri,uunet}!hcr!larry



More information about the Comp.unix.questions mailing list