Skip to content

Commit

Permalink
kern: console: make /dev/console backing console more predictable
Browse files Browse the repository at this point in the history
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 freebsd#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.

(cherry picked from commit f508dfd7e6a70417ceb6393fb136ae17012d261b)
  • Loading branch information
kevans91 committed Jun 7, 2024
1 parent f8cef06 commit 5d836ba
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions sys/kern/kern_cons.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,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]) {
Expand Down Expand Up @@ -380,8 +396,6 @@ sysctl_kern_console(SYSCTL_HANDLER_ARGS)
error = 0;
} else {
error = cnadd(cp);
if (error == 0)
cnselect(cp);
}
break;
}
Expand Down

0 comments on commit 5d836ba

Please sign in to comment.