Name

pty-get-tty — allocate a pseudo-terminal

Synopsis

pty-get-tty {next-prog}

Description

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 slave side. 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(7) environment variable and the (as far as the kernel is concerned anyway) original controlling terminal.

Security

Linux

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.

The grantpt(3) library function is only rendered a no-operation if the relevant devpts is mounted with some specific mount options. system-manager(1) specifies these mount options, but that might not be what is performing system management for the machine.

BSD

The grantpt(3) and unlockpt(3) library functions are in fact no-ops on BSD, as the slave side devices of pseudo-terminals are created with these permissions and UID in the first place.

See also

pty-run(1)

used to run a program attached to the newly created pseudo-terminal, passing its input and output to standard input and standard output

console-terminal-emulator(1)

use to run a terminal emulator on the newly created pseudo-terminal, that sends and responds to the same control sequences as the kernel's built-in terminal emulator for (kernel) virtual terminals

Author

Jonathan de Boyne Pollard