Index: include/ttyent.h =================================================================== --- include/ttyent.h (revision 260331) +++ include/ttyent.h (working copy) @@ -37,6 +37,7 @@ #define _TTYS_OFF "off" #define _TTYS_ON "on" +#define _TTYS_AUTO "auto" #define _TTYS_SECURE "secure" #define _TTYS_INSECURE "insecure" #define _TTYS_WINDOW "window" Index: lib/libc/gen/getttyent.c =================================================================== --- lib/libc/gen/getttyent.c (revision 260331) +++ lib/libc/gen/getttyent.c (working copy) @@ -39,6 +39,9 @@ #include #include +#include +#include + static char zapchar; static FILE *tf; static size_t lbsize; @@ -64,6 +67,32 @@ 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) + return (0); + + if ((cons = strchr(buf, '/')) == NULL) + return (0); + *cons = '\0'; + nextcons = buf; + while ((cons = strsep(&nextcons, ",")) != NULL && strlen(cons) != 0) { + if (strcmp(cons, ty_name) == 0) + return (TTY_ON); + } + + return (0); +} + struct ttyent * getttyent(void) { @@ -126,6 +155,8 @@ tty.ty_status &= ~TTY_ON; else if (scmp(_TTYS_ON)) tty.ty_status |= TTY_ON; + else if (scmp(_TTYS_AUTO)) + tty.ty_status |= auto_tty_status(tty.ty_name); else if (scmp(_TTYS_SECURE)) tty.ty_status |= TTY_SECURE; else if (scmp(_TTYS_INSECURE)) Index: libexec/getty/ttys.5 =================================================================== --- libexec/getty/ttys.5 (revision 260331) +++ libexec/getty/ttys.5 (working copy) @@ -102,8 +102,11 @@ .Pp As flag values, the strings ``on'' and ``off'' specify that .Xr init 8 -should (should not) execute the command given in the second field, -while ``secure'' (if ``on'' is also specified) allows users with a +should (should not) execute the command given in the second field. +``auto'' 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 ``secure'' (if ``on'' is also specified) allows users with a uid of 0 to login on this line. The flag ``dialin'' indicates that a tty entry describes a dialin