Impelemnt ttys onifexists in init.

Implement a new init(8) option in /etc/ttys. If this option is present
on the entry in /etc/ttys, the entry will be active if and only if it
exists.  If the name starts with a '/', it will be considered an
absolute path. If not, it will be a path relative to /dev.

This allows one to turn off video console getty that aren't present
(while running a getty on them even when they aren't the system
console). Likewise with serial ports.

It differs from onifconsole in only requiring the device exist rather
than it be listed as one of the system consoles.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D10037
This commit is contained in:
Warner Losh 2017-03-22 19:00:41 +00:00
parent 8b36e24529
commit 37b5835028
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=315733
3 changed files with 30 additions and 1 deletions

View file

@ -38,6 +38,7 @@
#define _TTYS_OFF "off"
#define _TTYS_ON "on"
#define _TTYS_ONIFCONSOLE "onifconsole"
#define _TTYS_ONIFEXISTS "onifexists"
#define _TTYS_SECURE "secure"
#define _TTYS_INSECURE "insecure"
#define _TTYS_WINDOW "window"

View file

@ -97,6 +97,26 @@ auto_tty_status(const char *ty_name)
return (0);
}
static int
auto_exists_status(const char *ty_name)
{
struct stat sb;
char *dev;
int rv;
rv = 0;
if (*ty_name == '/')
asprintf(&dev, "%s", ty_name);
else
asprintf(&dev, "/dev/%s", ty_name);
if (dev == NULL)
return 0;
if (stat(dev, &sb) == 0)
rv = TTY_ON;
free(dev);
return (rv);
}
struct ttyent *
getttyent(void)
{
@ -161,6 +181,8 @@ getttyent(void)
tty.ty_status |= TTY_ON;
else if (scmp(_TTYS_ONIFCONSOLE))
tty.ty_status |= auto_tty_status(tty.ty_name);
else if (scmp(_TTYS_ONIFEXISTS))
tty.ty_status |= auto_exists_status(tty.ty_name);
else if (scmp(_TTYS_SECURE))
tty.ty_status |= TTY_SECURE;
else if (scmp(_TTYS_INSECURE))

View file

@ -28,7 +28,7 @@
.\" from: @(#)ttys.5 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\" "
.Dd March 9, 2014
.Dd March 16, 2017
.Dt TTYS 5
.Os
.Sh NAME
@ -105,6 +105,12 @@ should (should not) execute the command given in the second field.
``onifconsole'' will cause this line to be enabled if and only if it is
an active kernel console device (it is equivalent to ``on'' in this
case).
The flag ``onifexists'' will cause this line to be enabled if and only
if the name exists.
If the name starts with a ``/'', it will be considered an absolute
path.
Otherwise, it is considered a path relative to
.Pa /dev .
The flag ``secure'' (if the console is enabled) allows users with a
uid of 0 to login on
this line.