From c4a0333b55e08f38985828a3a2d3ee533325c568 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Thu, 31 Dec 2020 10:50:43 -0600 Subject: [PATCH] vt: restore tty when console is ungrabbed When a break-to-debugger is triggered, kdb will grab the console and vt(4) will generally switch back to ttyv0. If one issues a continue from the debugger, then kdb will ungrab the console and the system rolls on. This change adds a perhaps minor feature: when we're down to grab == 0 and if vt actually switched away to ttyv0, switch back to the tty it was previously on before the console was grabbed. The justification behind this is that a typical flow is to work in !ttyv0 to avoid console spam while occasionally dropping to ddb to inspect system state before returning. This could easily enough be tossed behind a sysctl or something if it's not generally appreciated, but I anticipate indifference. Reviewed by: ray Differential Revision: https://reviews.freebsd.org/D27110 --- sys/dev/vt/vt.h | 1 + sys/dev/vt/vt_core.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/sys/dev/vt/vt.h b/sys/dev/vt/vt.h index 7d960f68e83f..2d671d692384 100644 --- a/sys/dev/vt/vt.h +++ b/sys/dev/vt/vt.h @@ -124,6 +124,7 @@ struct vt_device { struct vt_window *vd_windows[VT_MAXWINDOWS]; /* (c) Windows. */ struct vt_window *vd_curwindow; /* (d) Current window. */ struct vt_window *vd_savedwindow;/* (?) Saved for suspend. */ + struct vt_window *vd_grabwindow; /* (?) Saved before cngrab. */ struct vt_pastebuf vd_pastebuf; /* (?) Copy/paste buf. */ const struct vt_driver *vd_driver; /* (c) Graphics driver. */ void *vd_softc; /* (u) Driver data. */ diff --git a/sys/dev/vt/vt_core.c b/sys/dev/vt/vt_core.c index c273b703de93..2352ed823424 100644 --- a/sys/dev/vt/vt_core.c +++ b/sys/dev/vt/vt_core.c @@ -1805,6 +1805,9 @@ vtterm_cngrab(struct terminal *tm) vw = tm->tm_softc; vd = vw->vw_device; + /* To be restored after we ungrab. */ + if (vd->vd_grabwindow == NULL) + vd->vd_grabwindow = vd->vd_curwindow; if (!cold) vt_window_switch(vw); @@ -1821,10 +1824,14 @@ vtterm_cnungrab(struct terminal *tm) vw = tm->tm_softc; vd = vw->vw_device; + MPASS(vd->vd_grabwindow != NULL); if (vtterm_cnungrab_noswitch(vd, vw) != 0) return; + if (!cold && vd->vd_grabwindow != vw) + vt_window_switch(vd->vd_grabwindow); + vd->vd_grabwindow = NULL; } static void