summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2017-03-22 19:00:41 +0000
committerWarner Losh <imp@FreeBSD.org>2017-03-22 19:00:41 +0000
commit37b5835028cb170fdffb35e33fdf1fdcc402df9a (patch)
treedee31853c91e51b45454d3c700be92320c1269df
parent8b36e24529f54046eda5d317a137592f77318c02 (diff)
Notes
-rw-r--r--include/ttyent.h1
-rw-r--r--lib/libc/gen/getttyent.c22
-rw-r--r--libexec/getty/ttys.58
3 files changed, 30 insertions, 1 deletions
diff --git a/include/ttyent.h b/include/ttyent.h
index f2220ad73b949..c173bb81803b4 100644
--- a/include/ttyent.h
+++ b/include/ttyent.h
@@ -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"
diff --git a/lib/libc/gen/getttyent.c b/lib/libc/gen/getttyent.c
index 8e9ac9883a518..aa08632f60fc7 100644
--- a/lib/libc/gen/getttyent.c
+++ b/lib/libc/gen/getttyent.c
@@ -97,6 +97,26 @@ done:
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))
diff --git a/libexec/getty/ttys.5 b/libexec/getty/ttys.5
index d4c7f1d1a2494..1150909752a8b 100644
--- a/libexec/getty/ttys.5
+++ b/libexec/getty/ttys.5
@@ -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.