vc-get-tty — set up the environment appropriate to a virtual terminal and chain


vc-get-tty [--long-hostname] [--term type] {terminal-device-name} {next-prog}


vc-get-tty is a chain-loading utility that sets up environment variables appropriate to a specified virtual console, 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-tty will ignore.

vc-get-tty sets the TTY environment variable to the full device filename of the controlling terminal. Programs such as open-controlling-tty(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-tty 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 console is a user-space rather than a kernel one.

vc-get-tty sets the HOST environment variable to the machine hostname, as obtained from the gethostname(3) library function. If the --long-hostname command line option is present, the machine hostname is assigned to the variable as-is. Otherwise, it is truncated at the first dot.

vc-get-tty sets the TERM(7) environment variable to a system-dependent default for virtual consoles. For user-space virtual consoles, it also sets the COLORTERM environment variable to truecolor.

It does not make any attempt to deduce terminal types, as the gettys that talk to serial terminals do, or read the BSD /etc/ttys or /etc/gettytab databases. The terminal types for virtual consoles are effectively fixed by what the console driver emulates on each operating system, and can thus be hardwired.

  • The terminal types for virtual consoles on Linux are fixed as linux.

  • The terminal types for virtual consoles on FreeBSD are fixed as teken. In FreeBSD 9.0 the old cons25 was replaced with the teken library, replacing the kernel terminal emulator's escape sequence handler and enabling UTF-8 support. Unfortunately, the FreeBSD termcap library was not updated with teken to match (although the terminfo library used by other operating systems was, in 2017). Also unfortunately, other operating systems lack FreeBSD's mis-named xterm-clear terminal type and the teken library does not fully nor correctly duplicate the functionality of XTerm.

  • The terminal types for virtual consoles on NetBSD are fixed as pcvtXX. In theory, NetBSD also supports sun and dumb terminals.

  • The terminal types for virtual consoles on OpenBSD are fixed as pccon. 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 consoles have not changed for several years on FreeBSD and for a decade and a half (as of 2013) on Linux.


vc-get-tty 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-tty(1) (q.v.), vc-get-tty ensures that the virtual console is owned by the effective UID of the process, and has rw------- permissions.

See Also

  • TERM(7)

  • terminal-types(7)

  • linux-vt(4)


Jonathan de Boyne Pollard