Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 24 Sep 2012 17:13:34 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r240891 - in head: etc usr.sbin/moused
Message-ID:  <201209241713.q8OHDYYp060446@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Mon Sep 24 17:13:33 2012
New Revision: 240891
URL: http://svn.freebsd.org/changeset/base/240891

Log:
  Make sure moused is exiting as quick as possible after that the
  umsX character device returns a read error. Update devd.conf rules
  to use "DEVFS" events which are generated after that the umsX
  character device node has been created/destroyed, and then there
  should be no need for moused to wait up to 10 seconds for umsX to
  be ready. Opening umsX should not fail except if the kernel is low
  on memory. In that case the user can replug the USB mouse or use
  "usbconfig" to reset the device. In case of USB mouse devices,
  moused should neither retry to open its character device,
  once the first read error has happened. This is an indication
  of device detach.
  
  MFC after:	1 week

Modified:
  head/etc/devd.conf
  head/usr.sbin/moused/moused.c

Modified: head/etc/devd.conf
==============================================================================
--- head/etc/devd.conf	Mon Sep 24 16:34:13 2012	(r240890)
+++ head/etc/devd.conf	Mon Sep 24 17:13:33 2012	(r240891)
@@ -115,14 +115,22 @@ detach 100 {
 	action "/etc/rc.d/syscons setkeyboard /dev/kbd0";
 };
 
-attach 100 {
-	device-name "ums[0-9]+";
-	action "/etc/rc.d/moused quietstart $device-name";
+notify 100 {
+	match "system" "DEVFS";
+	match "subsystem" "CDEV";
+	match "type" "CREATE";
+	match "cdev" "ums[0-9]+";
+
+	action "/etc/rc.d/moused quietstart $cdev";
 };
 
-detach 100 {
-        device-name "ums[0-9]+";
-        action "/etc/rc.d/moused stop $device-name";
+notify 100 {
+	match "system" "DEVFS";
+	match "subsystem" "CDEV";
+	match "type" "DESTROY";
+	match "cdev" "ums[0-9]+";
+
+	action "/etc/rc.d/moused stop $cdev";
 };
 
 # Firmware download into the ActiveWire board. After the firmware download is

Modified: head/usr.sbin/moused/moused.c
==============================================================================
--- head/usr.sbin/moused/moused.c	Mon Sep 24 16:34:13 2012	(r240890)
+++ head/usr.sbin/moused/moused.c	Mon Sep 24 17:13:33 2012	(r240891)
@@ -408,6 +408,7 @@ static struct rodentparam {
     int cfd;			/* /dev/consolectl file descriptor */
     int mremsfd;		/* mouse remote server file descriptor */
     int mremcfd;		/* mouse remote client file descriptor */
+    int is_removable;		/* set if device is removable, like USB */
     long clickthreshold;	/* double click speed in msec */
     long button2timeout;	/* 3 button emulation timeout */
     mousehw_t hw;		/* mouse device hardware information */
@@ -434,6 +435,7 @@ static struct rodentparam {
     .cfd = -1,
     .mremsfd = -1,
     .mremcfd = -1,
+    .is_removable = 0,
     .clickthreshold = DFLT_CLICKTHRESHOLD,
     .button2timeout = DFLT_BUTTON2TIMEOUT,
     .accelx = 1.0,
@@ -570,7 +572,6 @@ main(int argc, char *argv[])
     int c;
     int	i;
     int	j;
-    static int retry;
 
     for (i = 0; i < MOUSE_MAXBUTTON; ++i)
 	mstate[i] = &bstate[i];
@@ -876,10 +877,8 @@ main(int argc, char *argv[])
 	usage();
     }
 
-    retry = 1;
-    if (strncmp(rodent.portname, "/dev/ums", 8) == 0) {
-	retry = 5;
-    }
+    if (strncmp(rodent.portname, "/dev/ums", 8) == 0)
+	rodent.is_removable = 1;
 
     for (;;) {
 	if (setjmp(env) == 0) {
@@ -888,13 +887,8 @@ main(int argc, char *argv[])
 	    signal(SIGQUIT, cleanup);
 	    signal(SIGTERM, cleanup);
 	    signal(SIGUSR1, pause_mouse);
-	    for (i = 0; i < retry; ++i) {
-		if (i > 0)
-		    sleep(2);
-		rodent.mfd = open(rodent.portname, O_RDWR | O_NONBLOCK);
-		if (rodent.mfd != -1 || errno != ENOENT)
-		    break;
-	    }
+
+	    rodent.mfd = open(rodent.portname, O_RDWR | O_NONBLOCK);
 	    if (rodent.mfd == -1)
 		logerr(1, "unable to open %s", rodent.portname);
 	    if (r_identify() == MOUSE_PROTO_UNKNOWN) {
@@ -944,6 +938,8 @@ main(int argc, char *argv[])
 	if (rodent.cfd != -1)
 	    close(rodent.cfd);
 	rodent.mfd = rodent.cfd = -1;
+	if (rodent.is_removable)
+		exit(0);
     }
     /* NOT REACHED */
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201209241713.q8OHDYYp060446>