From 7db291d2019e9a2aedc6c7d4fc24e6f40269a861 Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Fri, 25 Aug 2017 02:37:32 +0000 Subject: Fix missing switching of the terminal emulator when switching the terminal state for kernel console output. r56043 in 2000 added many complications to support dynamic selection of the terminal emulator using modules and the ioctl CONS_SETTERM. This was never completed. There are still no modules, but it is easy to restore the scterm and dumb emulators at compile time. Then boot-time configuration for the preferred one doesn't work right, but CONS_SETTERM almost works after fixing this bug. CONS_SETTERM only switches the emulator for the user state, leaving the kernel state(s) still using the boot-time emulator. The fix is especially important when switching from sc to scteken, since the scteken state has pointers in it. Rename kernel_console_ts to sc_kts. --- sys/dev/syscons/syscons.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'sys/dev/syscons') diff --git a/sys/dev/syscons/syscons.c b/sys/dev/syscons/syscons.c index e14beb050413b..07a05b4a32518 100644 --- a/sys/dev/syscons/syscons.c +++ b/sys/dev/syscons/syscons.c @@ -98,7 +98,8 @@ static int sc_console_unit = -1; static int sc_saver_keyb_only = 1; static scr_stat *sc_console; static struct consdev *sc_consptr; -static void *kernel_console_ts[MAXCPU]; +static void *sc_kts[MAXCPU]; +static struct sc_term_sw *sc_ktsw; static scr_stat main_console; static struct tty *main_devs[MAXCONS]; @@ -564,6 +565,7 @@ sc_attach_unit(int unit, int flags) scinit(unit, flags); if (sc_console->tsw->te_size > 0) { + sc_ktsw = sc_console->tsw; /* assert(sc_console->ts != NULL); */ oldts = sc_console->ts; for (i = 0; i <= mp_maxid; i++) { @@ -573,7 +575,7 @@ sc_attach_unit(int unit, int flags) sc_console->ts = ts; (*sc_console->tsw->te_default_attr)(sc_console, sc_kattrtab[i], SC_KERNEL_CONS_REV_ATTR); - kernel_console_ts[i] = ts; + sc_kts[i] = ts; } sc_console->ts = oldts; (*sc_console->tsw->te_default_attr)(sc_console, SC_NORM_ATTR, @@ -1728,11 +1730,14 @@ sc_cnterm(struct consdev *cp) sccnupdate(sc_console); #endif - for (i = 0; i <= mp_maxid; i++) { - ts = kernel_console_ts[i]; - kernel_console_ts[i] = NULL; - (*sc_console->tsw->te_term)(sc_console, &ts); - free(ts, M_DEVBUF); + if (sc_ktsw != NULL) { + for (i = 0; i <= mp_maxid; i++) { + ts = sc_kts[i]; + sc_kts[i] = NULL; + (*sc_ktsw->te_term)(sc_console, &ts); + free(ts, M_DEVBUF); + } + sc_ktsw = NULL; } scterm(sc_console_unit, SC_KERNEL_CONSOLE); sc_console_unit = -1; @@ -1992,13 +1997,16 @@ sc_cnputc(struct consdev *cd, int c) sizeof(sc_cnputc_log)) continue; /* Console output has a per-CPU "input" state. Switch for it. */ + oldtsw = scp->tsw; oldts = scp->ts; - ts = kernel_console_ts[PCPU_GET(cpuid)]; + ts = sc_kts[PCPU_GET(cpuid)]; if (ts != NULL) { + scp->tsw = sc_ktsw; scp->ts = ts; (*scp->tsw->te_sync)(scp); } sc_puts(scp, buf, 1); + scp->tsw = oldtsw; scp->ts = oldts; (*scp->tsw->te_sync)(scp); } -- cgit v1.3