I've been unable to get to alpha.gnu.org tonight. Could you send me a copy
of the grantpt.c?
> Well, I said it was easy... Here's my first attempt (also available at
> http://www.lysator.liu.se/~nisse/lsh/src/server_pty.c). 75 lines. Do
> you think something like this will do? Next question is whether or not
> the tty_setctty works for UNIX98 sockets. And if it can be done in a
> cleaner way than reopening the slave, this time without the O_NOCTTY
> flag.
No better way to set an open standard than to charge money to be able to
see the standard. Thus, I don't have any information at hand on the way to
set a controlling terminal under POSIX, but quoting sparsely from the
UNIX98 specs in hopes of avoiding their wrath:
"If a session leader has no controlling terminal, and opens a terminal
device file...whether the terminal becomes the controlling terminal...may
vary among systems..."
Seemingly, there are no other documented ways within the UNIX98 standard
to set a terminal as the controlling terminal, and even this way (calling
open without O_NOCTTY) is not guaranteed to work. Lowest common
denominator at work, I suppose.
At any rate, APUE endorses setting the controlling terminal via open, and
I can't find any hints at alternatives in other documents.
Thus, placing my faith in Stevens, I hereby endorse the minimalist
tty_setctty for UNIX98:
1. setsid()
2. open()
3. close()
This also means that tty_setctty (at least for UNIX98 purposes) can be
called with only the slave fd.
-John