svn commit: r260913 - in head: include lib/libc/gen libexec/getty

Nathan Whitehorn nwhitehorn at FreeBSD.org
Mon Jan 20 18:15:07 UTC 2014


Author: nwhitehorn
Date: Mon Jan 20 18:15:06 2014
New Revision: 260913
URL: http://svnweb.freebsd.org/changeset/base/260913

Log:
  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.
  
  Comments and suggestions by:	grehan, dteske, jilles
  MFC after:	1 month

Modified:
  head/include/ttyent.h
  head/lib/libc/gen/getttyent.c
  head/libexec/getty/ttys.5

Modified: head/include/ttyent.h
==============================================================================
--- head/include/ttyent.h	Mon Jan 20 17:55:22 2014	(r260912)
+++ head/include/ttyent.h	Mon Jan 20 18:15:06 2014	(r260913)
@@ -37,6 +37,7 @@
 
 #define	_TTYS_OFF	"off"
 #define	_TTYS_ON	"on"
+#define	_TTYS_ONIFCONSOLE "onifconsole"
 #define	_TTYS_SECURE	"secure"
 #define	_TTYS_INSECURE	"insecure"
 #define	_TTYS_WINDOW	"window"

Modified: head/lib/libc/gen/getttyent.c
==============================================================================
--- head/lib/libc/gen/getttyent.c	Mon Jan 20 17:55:22 2014	(r260912)
+++ head/lib/libc/gen/getttyent.c	Mon Jan 20 18:15:06 2014	(r260913)
@@ -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))

Modified: head/libexec/getty/ttys.5
==============================================================================
--- head/libexec/getty/ttys.5	Mon Jan 20 17:55:22 2014	(r260912)
+++ head/libexec/getty/ttys.5	Mon Jan 20 18:15:06 2014	(r260913)
@@ -102,8 +102,11 @@ ttys as a group.
 .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.
+``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 ``secure'' (if the console is enabled) allows users with a
 uid of 0 to login on
 this line.
 The flag ``dialin'' indicates that a tty entry describes a dialin


More information about the svn-src-head mailing list