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 ()
Previous text:
2003-02-15 21:21: Subject: setsid
Yes, it seamed very nice, but I only got it to work on Linux. On Solaris grantpt() says "grantpt failed: No child processes". According to truss pike doesn't set up it's own sigchild handler, so that shouldn't be it. The man page for grantpt also mentions that it runs some setuid root program as a possible reason for failures, but again according to truss it doesn't seem to get to that.
/ Peter Bortas