Is there some compelling reason not to do
master = open("/dev/ptmx") grantpt(master)
before fork(), if you aren't going to change uid? Because that is what I do. Doing the grantpt() in the child requires modification* of pike.
* I have on my todo to make a Process.create_ptypair() or something, but not today.
/ Peter Bortas
Previous text:
2003-02-15 21:37: Subject: setsid
The traditioal way of using /dev/ptmx (I'm not doing it quite like that myself in lsh, so I hope I get this right) is as follows:
master = open("/dev/ptmx") fork()
in the child: setuid() // The standard grantpt function depends on the // process uid, so if you want to change uid, do that first. grantpt(master) unlockpt(master) setsid() // Loses old controlling terminal slave = open(ptsname(master) // On sys5, makes the slave our // controlling terminal
for sys5, setup STREAMS: ioctl(slave, I_PUSH, "ptem") ioctl(slave, I_PUSH, "ldterm")
for BSD, where opening the slave didn't make it our controlling terminal ioctl(fd, TIOCSCTTY, NULL)
close(master) dup fd:s around exec new program
in the parent: read and write the master side of the tty.
As an extra complication, at least on Solaris you'll get i/o errors if you try to do any i/o before the child process has opened and set up the tty. So you may need to either move some of the slave code before fork (no problem unless you want to change uid...), or use some extra syncronization.
/ Niels Möller ()