From 27c1914625a2e118a5986a035dffb0a7b952bf89 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Fri, 28 Aug 2020 15:27:58 +0000 Subject: terminal: Explain FreeBSD current_vt behavior --- common/terminal.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'common/terminal.c') diff --git a/common/terminal.c b/common/terminal.c index aa9797e..e397357 100644 --- a/common/terminal.c +++ b/common/terminal.c @@ -138,6 +138,31 @@ int terminal_current_vt(int fd) { log_errorf("could not retrieve VT state: %s", strerror(errno)); return -1; } + + // The FreeBSD VT_GETACTIVE is implemented in the kernel as follows: + // + // static int + // vtterm_ioctl(struct terminal *tm, u_long cmd, caddr_t data, + // struct thread *td) + // { + // struct vt_window *vw = tm->tm_softc; + // struct vt_device *vd = vw->vw_device; + // ... + // switch (cmd) { + // ... + // case VT_GETACTIVE: + // *(int *)data = vd->vd_curwindow->vw_number + 1; + // return (0); + // ... + // } + // ... + // } + // + // The side-effect here being that the returned VT number is one + // greater than the internal VT number, which is what is used for e.g. + // numbering the associated VT. To simplify things, we subtract one + // from the returned VT number before returning it. + if (vt < 1) { log_errorf("invalid vt: %d", vt); return -1; -- cgit v1.2.3