summaryrefslogtreecommitdiff
path: root/usr.sbin/wsmoused
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2007-11-24 16:28:10 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2007-11-24 16:28:10 +0000
commitfc458b9310c15c1659a7269c64100ea95ba7709b (patch)
tree2117717d3e0fd0093fba3be37b762323fce3fea4 /usr.sbin/wsmoused
parentcf8f9dcf9399c394b93fb2ab847c3bdcaa8477ed (diff)
Since switches from X to consoles are aysnchronous, wsmoused(8) can be awakened
before the X server has release the mouse device. Instead of an arbitrary sleep, loop (with increasing delays) until we can open the device again. Found the hard way and tested by jmc@
Diffstat (limited to 'usr.sbin/wsmoused')
-rw-r--r--usr.sbin/wsmoused/wsmoused.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/usr.sbin/wsmoused/wsmoused.c b/usr.sbin/wsmoused/wsmoused.c
index bc90bb29b59..43c9fd88886 100644
--- a/usr.sbin/wsmoused/wsmoused.c
+++ b/usr.sbin/wsmoused/wsmoused.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: wsmoused.c,v 1.22 2007/09/18 20:19:20 otto Exp $ */
+/* $OpenBSD: wsmoused.c,v 1.23 2007/11/24 16:28:09 miod Exp $ */
/*
* Copyright (c) 2001 Jean-Baptiste Marchand, Julien Montagne and Jerome Verdon
@@ -453,6 +453,7 @@ wsmoused(void)
the X server release it */
struct wscons_event sleeping;
+ unsigned int tries;
/* restore mouse resolution to default value */
res = WSMOUSE_RES_DEFAULT;
@@ -467,13 +468,31 @@ wsmoused(void)
ioctl(mouse.cfd, WSDISPLAYIO_WSMOUSED,
&sleeping);
- /* waiting for availability of mouse device */
- sleep(1);
+ /*
+ * Since the X server could still be running
+ * (e.g. when switching from the graphics
+ * screen to a virtual text console), it might
+ * not have freed the device yet.
+ *
+ * Try to open the device until it succeeds.
+ */
+ tries = 0;
+ for (;;) {
+ if ((mouse.mfd = open(mouse.portname,
+ O_RDONLY | O_NONBLOCK, 0)) != -1)
+ break;
+
+ if (tries < 10) {
+ tries++;
+ sleep(1);
+ } else {
+ logerr(1, "unable to open %s, "
+ "will retry in 10 seconds",
+ mouse.portname);
+ sleep(10);
+ }
+ }
- if ((mouse.mfd = open(mouse.portname,
- O_RDONLY | O_NONBLOCK, 0)) == -1)
- logerr(1, "unable to open %s",
- mouse.portname);
mouse_init();
}
} else {