From 2c6a34deb94268c4fdc494b47242f95a1f40b424 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Mon, 1 Oct 2012 13:23:38 +0200 Subject: [PATCH] uterm: vt: make real_activate() behave like real_deactivate() real_activate() has alsmost the same semantics as real_deactivate() so we should also return -EINPROGRESS when we scheduled the VT switch. This isn't used by kmscon currently, but may be used by other uterm users. Signed-off-by: David Herrmann --- src/uterm_vt.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/uterm_vt.c b/src/uterm_vt.c index a427ad4..f49524e 100644 --- a/src/uterm_vt.c +++ b/src/uterm_vt.c @@ -319,14 +319,28 @@ static void real_close(struct uterm_vt *vt) vt->real_saved_num = -1; } -/* Switch to this VT and make it the active VT. */ +/* Switch to this VT and make it the active VT. If we are already the active + * VT, then 0 is returned, if the VT_ACTIVATE ioctl is called to activate this + * VT, then -EINPROGRESS is returned and we will be activated when receiving the + * VT switch signal. The currently active VT may prevent this, though. + * On error a negative error code is returned other than -EINPROGRESS */ static int real_activate(struct uterm_vt *vt) { int ret; + struct vt_stat vts; if (vt->real_num < 0) return -EINVAL; + ret = ioctl(vt->real_fd, VT_GETSTATE, &vts); + if (ret) { + log_warn("cannot find current VT"); + return -EFAULT; + } + + if (vts.v_active != vt->real_num) + return 0; + ret = ioctl(vt->real_fd, VT_ACTIVATE, vt->real_num); if (ret) { log_warn("cannot enter VT %p", vt); @@ -334,7 +348,7 @@ static int real_activate(struct uterm_vt *vt) } log_debug("entering VT %p on demand", vt); - return 0; + return -EINPROGRESS; } /* -- 2.7.4