vc-get-terminal 1 user commands nosh
vc-get-tty set up the environment appropriate to a virtual terminal and chain
`vc-get-terminal` --term type terminal-device-name next-prog

## Description

`vc-get-terminal` is a chain-loading utility that sets up environment variables appropriate to a specified virtual terminal, secures the device against access by other users, and then chain loads to next-prog with the execvp 3 function.

next-prog may contain its own command line options, which `vc-get-terminal` will ignore.

`vc-get-terminal` sets the `TTY` environment variable to the full device filename of the controlling terminal. Programs such as open-controlling-terminal 1, and login-banner 1 will make use of this environment variable as the name of the controlling terminal.

It determines the terminal character device filename from the passed terminal-device-name. This can be just the absolute pathname of the device file itself or a relative pathname (such as `tty1`). If it is a relative pathname, `vc-get-terminal` tries first prefixing `/dev/` and looking for a file, then prefixing `/var/dev/`, and then prefixing `/run/dev/`. In the case of the latter twain, it assumes that the virtual terminal is a user-space rather than a kernel one.

`vc-get-terminal` sets the `TERM` 7 environment variable to a system-dependent default for virtual terminals. For user-space virtual terminals, it also sets the `COLORTERM` 7 environment variable similarly.

It does not make any attempt to deduce terminal types or read the BSD `/etc/ttys` or `/etc/gettytab` databases. Virtual terminals are either the kernel's built-in terminal emulator or user-space virtual terminals assumed to be running console-terminal-emulator 1. In both cases, the terminal type is fixed and well-known, and can be hardwired.

### FreeBSD (including GhostBSD and DragonFly BSD)

The `TERM` 7 variable is set to `teken` for the kernel's built-in terminal emulator and `teken-16color` for user-space virtual terminals. The `COLORTERM` 7 variable is set to `teken-256color-truecolor`.

In FreeBSD 9.0 the old kernel terminal emulator was replaced with the teken library, improving the escape sequence handler and enabling UTF-8 support. `vc-get-terminal` expects either syscons 4 in its default teken mode or vt 4, and does not support either the old kernel terminal emulator or syscons 4 pretending to be the old kernel terminal emulator in its "cons25" mode.

### Linux

The `TERM` 7 variable is set to `linux-16color` for all virtual terminals. Both the kernel's built-in terminal emulator and console-terminal-emulator 1 are compatible with this. The `COLORTERM` 7 variable is set to `linux-256color-truecolor`.

### NetBSD

The `TERM` 7 variable is set to `netbsd6` for all virtual terminals. The `COLORTERM` 7 variable is set to `netbsd6-256color-truecolor`.

The old `pcvtXX` terminal type in `terminfo` 5 was replaced by `wsvt25` in 1999, and that was replaced by `netbsd6` in 2014.
In theory, NetBSD also supports `sun` and `dumb` terminals. In practice, the former is unfortunately configured out on most platforms and the latter is barely even a "glass lineprinter" which does not even do what an actual lineprinter could, such as overstrike.

### OpenBSD

The `TERM` 7 variable is set to `pccon` for all virtual terminals. The `COLORTERM` 7 variable is set to `pccon-256color-truecolor`.

In theory, OpenBSD also supports `sun` and `dumb` terminals.

The `--term` command line option is available for overriding these hardwired values, but there is little reason for using it as the terminal types for virtual terminals have not changed for several years on FreeBSD and for two and a half decades (as of 2025) on Linux.

## Terminal types

Unfortunately, the FreeBSD termcap library has not been updated with a `teken` entry to match its replacement kernel virtual terminal emulator.

However, proper `teken`, `teken-16color`, `teken-256color`, `linux`, `linux-16color`, and `linux-256color` termcap entries for FreeBSD are supplied with the nosh toolset. They simply require a directory to be added to the list in the `TERMPATH` environment variable and the files to be compiled to binary form. Likewise, `linux-16color` was added to the Dickey terminfo database in 2009, `teken` was added in 2017, and `teken-16color` was added in 2022; but as of 2025 the terminfo database still lacks `teken-256color` and `linux-256color`.

FreeBSD's mis-named `xterm-clear` terminal type that it employs, is incorrect. The teken library does not fully nor correctly duplicate the functionality of XTerm, the terminal type is not any kind of `xterm`, and other operating systems have no `xterm-clear` in terminfo. Do not use `xterm-clear`.

The consequences of this are threefold:

- Remote access in both directions between FreeBSD and Linux systems is possible without undue difficulty, from virtual terminals on either. The Linux-based operating systems have `teken-16color` in terminfo and the FreeBSD systems have `linux-16color` in termcap.

- Although one cannot locally take full advantage of the 256-colour support that console-terminal-emulator 1 actually has on Linux user-space virtual terminals, as there is no terminfo support; when remotely accessing FreeBSD systems `linux-16color` can be overridden with the `linux-256color` terminal type, as there is termcap support for the Linux user-space virtual terminals.

- If remote access to other systems from user-space virtual terminals on FreeBSD is not a concern, `teken-16color` can be overridden with the `teken-256color` terminal type. This enables full use of the 256-colour support that console-terminal-emulator 1 actually has.

## Security

`vc-get-terminal` expects to be run either directly from init 1 or under a dæmon supervisor of some sort. As such, it expects to start up with an already safe environment, open file descriptors, and resource limits for a process that is running under the aegis of the superuser.

To prevent a race condition in open-controlling-terminal 1 (q.v.), `vc-get-tty` ensures that the virtual terminal is owned by the effective UID of the process, and has `rw-------` permissions.

## See Also

- `TERM` 7

- terminal-types 7

- linux-vt 4

## Author

Jonathan de Boyne Pollard