diff options
author | nwhitehorn <nwhitehorn@FreeBSD.org> | 2014-06-08 17:50:07 +0000 |
---|---|---|
committer | nwhitehorn <nwhitehorn@FreeBSD.org> | 2014-06-08 17:50:07 +0000 |
commit | dc45432cd4f03f948237c53e557e8a56c844f7ca (patch) | |
tree | 65553542f819e6c80a2e85faee72b236e6ddc304 /lib/libc/gen/getttyent.c | |
parent | 4c7f4e5ef3415b0183caaebe7b91bf164418864b (diff) | |
download | FreeBSD-src-dc45432cd4f03f948237c53e557e8a56c844f7ca.zip FreeBSD-src-dc45432cd4f03f948237c53e557e8a56c844f7ca.tar.gz |
MFC r260913,266895:
Add a new flag to /etc/ttys: onifconsole. This is equivalent to "on" if the
device is an active kernel console and "off" otherwise. This is designed to
allow serial-booting x86 systems to provide a login prompt on the serial line
by default without providing one on all systems by default. Set this flag
on x86 systems for ttyu0.
Comments and suggestions by: grehan, dteske, jilles
Diffstat (limited to 'lib/libc/gen/getttyent.c')
-rw-r--r-- | lib/libc/gen/getttyent.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/libc/gen/getttyent.c b/lib/libc/gen/getttyent.c index b82c30a..d104305 100644 --- a/lib/libc/gen/getttyent.c +++ b/lib/libc/gen/getttyent.c @@ -39,6 +39,9 @@ __FBSDID("$FreeBSD$"); #include <ctype.h> #include <string.h> +#include <sys/types.h> +#include <sys/sysctl.h> + static char zapchar; static FILE *tf; static size_t lbsize; @@ -64,6 +67,36 @@ getttynam(const char *tty) return (t); } +static int +auto_tty_status(const char *ty_name) +{ + size_t len; + char *buf, *cons, *nextcons; + + /* Check if this is an enabled kernel console line */ + buf = NULL; + if (sysctlbyname("kern.console", NULL, &len, NULL, 0) == -1) + return (0); /* Errors mean don't enable */ + buf = malloc(len); + if (sysctlbyname("kern.console", buf, &len, NULL, 0) == -1) + goto done; + + if ((cons = strchr(buf, '/')) == NULL) + goto done; + *cons = '\0'; + nextcons = buf; + while ((cons = strsep(&nextcons, ",")) != NULL && strlen(cons) != 0) { + if (strcmp(cons, ty_name) == 0) { + free(buf); + return (TTY_ON); + } + } + +done: + free(buf); + return (0); +} + struct ttyent * getttyent(void) { @@ -126,6 +159,8 @@ getttyent(void) tty.ty_status &= ~TTY_ON; else if (scmp(_TTYS_ON)) tty.ty_status |= TTY_ON; + else if (scmp(_TTYS_ONIFCONSOLE)) + tty.ty_status |= auto_tty_status(tty.ty_name); else if (scmp(_TTYS_SECURE)) tty.ty_status |= TTY_SECURE; else if (scmp(_TTYS_INSECURE)) |