aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenny Levinsen <kl@kl.wtf>2020-08-28 15:27:58 +0000
committerKenny Levinsen <kl@kl.wtf>2020-08-28 17:46:13 +0200
commit27c1914625a2e118a5986a035dffb0a7b952bf89 (patch)
treedbbfeeb141eefc8a22f9ba79d94a8c1ba863853a
parentdbdce8a54beec1385149a77d1005ef85dbfc2ac5 (diff)
terminal: Explain FreeBSD current_vt behavior
-rw-r--r--common/terminal.c25
1 files changed, 25 insertions, 0 deletions
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;