pty-get-tty — allocate a pseudo-terminal
pty-get-tty
{next-prog
}
pty-get-tty is a chain-loading utility that allocates and opens the master
side of a new pseudo-terminal, sets up environment variables appropriate to it,
and then chain loads to next-prog
with the
execvp(3) function.
next-prog
may contain its own command line options, which pty-get-tty will ignore.
pty-get-tty sets the TTY
environment variable to the full device filename of the pseudo-terminal.
Programs such as open-controlling-tty(1), login-banner(1) and login-process(1) will make use of this environment variable.
pty-get-tty opens the master side of the pseudo-terminal as file descriptor number 4, closing that descriptor if it was already open. pty-run(1) and console-terminal-emulator(1) expect the pseudo-terminal master side on this open file descriptor.
pty-get-tty otherwise leaves its environment and open file descriptors unchanged.
Thus next-prog
will inherit the TERM
environment variable and the
(as far as the kernel is concerned anyway) original controlling terminal.
To prevent a race condition in open-controlling-tty(1) (q.v.), pty-get-tty calls grantpt(3) to change the ownership of the slave side device to the (real, not effective) UID of the current process and set its permissions to allow only access to the owner; and then calls unlockpt(3) to release the operating system interlock that prevents other processes from opening the slave side device before ownership and permissions have been set.