From owner-svn-src-head@freebsd.org Wed Mar 22 19:00:43 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6266FD18BB0; Wed, 22 Mar 2017 19:00:43 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3366C1B61; Wed, 22 Mar 2017 19:00:43 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2MJ0gjo058682; Wed, 22 Mar 2017 19:00:42 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2MJ0gC8058678; Wed, 22 Mar 2017 19:00:42 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201703221900.v2MJ0gC8058678@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Wed, 22 Mar 2017 19:00:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r315733 - in head: include lib/libc/gen libexec/getty X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Mar 2017 19:00:43 -0000 Author: imp Date: Wed Mar 22 19:00:41 2017 New Revision: 315733 URL: https://svnweb.freebsd.org/changeset/base/315733 Log: 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 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 Wed Mar 22 18:45:13 2017 (r315732) +++ head/include/ttyent.h Wed Mar 22 19:00:41 2017 (r315733) @@ -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" Modified: head/lib/libc/gen/getttyent.c ============================================================================== --- head/lib/libc/gen/getttyent.c Wed Mar 22 18:45:13 2017 (r315732) +++ head/lib/libc/gen/getttyent.c Wed Mar 22 19:00:41 2017 (r315733) @@ -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)) Modified: head/libexec/getty/ttys.5 ============================================================================== --- head/libexec/getty/ttys.5 Wed Mar 22 18:45:13 2017 (r315732) +++ head/libexec/getty/ttys.5 Wed Mar 22 19:00:41 2017 (r315733) @@ -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 ``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.