pty-allocate 1 user commands nosh
pty-get-tty allocate a pseudo-terminal
`pty-allocate` next-prog

## Description

`pty-allocate` is a chain-loading utility that allocates and opens the back end (called "master side" in older documentation) 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-allocate` will ignore.

`pty-allocate` sets the `TTY` environment variable to the full device filename of the pseudo-terminal front end. Programs such as open-controlling-terminal 1, login-banner 1 and login-process 1 will make use of this environment variable.

`pty-allocate` opens the back end 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 back end on this open file descriptor.

`pty-allocate` 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-terminal 1 (q.v.), `pty-allocate` calls grantpt 3 to change the ownership of the front-end 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 front-end 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 front-end 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