From nobody Fri Jan 05 15:55:03 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4T67MC4QWMz559nP; Fri, 5 Jan 2024 15:55:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4T67MC2GQPz4sLb; Fri, 5 Jan 2024 15:55:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704470103; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=m4/CJKUM/yZWDbAfWbXve7yO7TIAeXdLqiG4SmXJOCE=; b=oqUgsWAZYTjNXSDgCxjuuqxSh1udRZRJ/WVJS4TY6HDHzUA2RZ2wNCyW5ThotTHQNSChsA 9tgU4s1Xwefw3jwsMdGUXMwNvK/LedPoP7HhfuOOI01RFxBFXst0C01XVRHKFGBb5iUGAd vyDSayyAs4emWidFFhdN5Rat+nhQQAY93nPHdbmG7KYwMPOPcRhKgW3PyyczXSifBonstE wWluhy6+LifDhK24OiT5M8H2Y/EBycNZkOZL7AS7JFgNbDPZSN1+v09HcesxWuUvlfoDhH xY30cAGzP3ycRfuvgQjcFtLBNiH2LAYaidAXfdnGkOIS4LlAKPr7c7v/6c3hbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704470103; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=m4/CJKUM/yZWDbAfWbXve7yO7TIAeXdLqiG4SmXJOCE=; b=LPtNa2rlND8rsoHxpaQlAPtzXWnGjKyscb7uW2F9KU2kV+aLc14eu1RADYH/V+yBJvC0lD wMJRgDgc5sbGjGYj/brsWv9K5xpevkucAsmsnq5nf0Z5RQsHECqb+YLMZNjrSJRHj8i14Y 6oaFql0jICfy88tsWRzz1rTGlDJW9Tuf5p3jPt2or68XeMoWsiaXBl/SFaoVTQ7RcfdMcM nuAqHiQLgWG7rvwPFLEPFGUj1aHb56iESIyozq+Rfafe4wJ3czC4qEB5y7P93N/uvRQkaR jCQxnZ34mvVBz7Uq+zD3L5YkqQ5JzqpzdcM0vt5YPlMXkXW+75QKpCmAyc6jhw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704470103; a=rsa-sha256; cv=none; b=oI0rTNGclw/rLILt0xYFPei/bNDFlqzDb6BFzs9VQeP5S/My+Jcb1OstdUZ9h5VzhzI/uI sAQ76cwF/ROAJGsAWZ1iOLRxO+BE1KA3sbDpmRcZRf5pLWnLeBjxqahT2zmz1Y2RhBuQgj NNUnSgzUpOPZ7qNO65AK3YGKFVj5eIRyfPPzNuYaAw4QzBn5N39edj1heiQ5sG+qJdUUpG fL1LsFOngdvdf3BUoYwy1V4Xz/NmVl2BFmwuDN2w7IgAJetj2hYeiGK00FHiX5X6xddDRs ep3w/fhSA6DhtsV8zBRBiOYDu6bZAbYlheBym+NFHIDmuIV2yB8qH5PPDkl+Dg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4T67MC1DN8z143n; Fri, 5 Jan 2024 15:55:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 405Ft3YS090298; Fri, 5 Jan 2024 15:55:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 405Ft3KL090295; Fri, 5 Jan 2024 15:55:03 GMT (envelope-from git) Date: Fri, 5 Jan 2024 15:55:03 GMT Message-Id: <202401051555.405Ft3KL090295@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 8ec6d7be2e27 - main - kern: console: make /dev/console backing console more predictable List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8ec6d7be2e27622b8b9e192b4da9ce88a4118636 Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=8ec6d7be2e27622b8b9e192b4da9ce88a4118636 commit 8ec6d7be2e27622b8b9e192b4da9ce88a4118636 Author: Kyle Evans AuthorDate: 2024-01-05 06:09:31 +0000 Commit: Kyle Evans CommitDate: 2024-01-05 15:52:29 +0000 kern: console: make /dev/console backing console more predictable Specifically, altering the console list with conscontrol has some weird behavior: 1. If you remove the first configured console, /dev/console will become unconfigured 2. Any console added becomes the /dev/console In a multicons situation, #1 is clearly a bug and #2 is perhaps slightly less clear. If we have ttyu0, ttyv0, then it seems obvious that one would want ttyv0 to take over the console if ttyu0 is removed. If we add ttyu0 back in, then it's debatable whether it should take over the console or not. Fix it now to make the /dev/console selection more FIFO-ish, with respect to how conscontrol affects it. A `primary` verb for conscontrol(8) might be a good addition. --- sys/kern/kern_cons.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/sys/kern/kern_cons.c b/sys/kern/kern_cons.c index 462cd0c45758..d4a858cb12fd 100644 --- a/sys/kern/kern_cons.c +++ b/sys/kern/kern_cons.c @@ -239,15 +239,31 @@ cnremove(struct consdev *cn) { struct cn_device *cnd; int i; + bool primary = true; STAILQ_FOREACH(cnd, &cn_devlist, cnd_next) { - if (cnd->cnd_cn != cn) + if (cnd->cnd_cn != cn) { + primary = false; continue; - if (STAILQ_FIRST(&cn_devlist) == cnd) - ttyconsdev_select(NULL); + } + STAILQ_REMOVE(&cn_devlist, cnd, cn_device, cnd_next); cnd->cnd_cn = NULL; + /* + * We only need to select a new console if we've removed all + * consoles or if we're removing the primary console. + */ + if (primary) { + struct cn_device *next; + + next = STAILQ_FIRST(&cn_devlist); + if (next == NULL) + ttyconsdev_select(NULL); + else + ttyconsdev_select(next->cnd_cn->cn_name); + } + /* Remove this device from available mask. */ for (i = 0; i < CNDEVTAB_SIZE; i++) if (cnd == &cn_devtab[i]) { @@ -356,8 +372,6 @@ sysctl_kern_console(SYSCTL_HANDLER_ARGS) error = 0; } else { error = cnadd(cp); - if (error == 0) - cnselect(cp); } break; }