summaryrefslogtreecommitdiffstats
path: root/usr.sbin/wsmoused
diff options
context:
space:
mode:
authormiod <miod@openbsd.org>2007-11-24 16:28:09 +0000
committermiod <miod@openbsd.org>2007-11-24 16:28:09 +0000
commit0329dfd0b754cbc76b370aa9f14c8ab6ad8ec4d6 (patch)
tree7215a630011cf6819872dc7b63684de7e62213c0 /usr.sbin/wsmoused
parentextend the url lookup algorithm to match the full URL and different (diff)
downloadwireguard-openbsd-0329dfd0b754cbc76b370aa9f14c8ab6ad8ec4d6.tar.xz
wireguard-openbsd-0329dfd0b754cbc76b370aa9f14c8ab6ad8ec4d6.zip
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 {