Name

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

Synopsis

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

Description

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 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/.

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 environment variable to a system-dependent default for virtual consoles. 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 database. The terminal types for virtual consoles are effectively fixed by what the console driver emulates on each operating system, and can 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 xterm. In theory, the console driver on FreeBSD could emulate either xterm or cons25. But in practice cons25 has been obsolete ever since the move (in FreeBSD 9.0) to enable UTF-8 on the console, which completely replaced the driver's escape sequence handler.

  • 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.

SECURITY

vc-get-tty expects to be run either directly from init(1) or under a daemon 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.

Author

Jonathan de Boyne Pollard