[Patch] Make addon-pmu work blocking

Sjoerd Simons sjoerd at luon.net
Fri Feb 17 11:32:09 PST 2006


Hi,

  Attached patch makes the addon-pmu work in blocking mode (thus open /dev/adb
  blocking). I've been running a little daemon on my system for some years that
  also does this without any problems, so it should be fine and makes the code
  somewhat nice imho. I've also removed some old dead code, don't think there
  is much use in keeping it around right ? 

  Sjoerd
-- 
If you only have a hammer, you tend to see every problem as a nail.
		-- Maslow
-------------- next part --------------
Index: hald/linux2/addons/addon-pmu.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/addons/addon-pmu.c,v
retrieving revision 1.5
diff -u -r1.5 addon-pmu.c
--- hald/linux2/addons/addon-pmu.c	18 Jan 2006 23:22:33 -0000	1.5
+++ hald/linux2/addons/addon-pmu.c	17 Feb 2006 19:25:53 -0000
@@ -66,23 +66,8 @@
 
 	dbus_error_init (&error);
 
-#if 0
-	{
-		DBusConnection *conn;
-		if ((conn = dbus_bus_get (DBUS_BUS_SYSTEM, &error)) == NULL)
-			goto out;
-		
-		if ((ctx = libhal_ctx_new ()) == NULL)
-			goto out;
-		if (!libhal_ctx_set_dbus_connection (ctx, conn))
-			goto out;
-		if (!libhal_ctx_init (ctx, &error))
-			goto out;
-	}
-#else
 	if ((ctx = libhal_ctx_init_direct (&error)) == NULL)
 		goto out;
-#endif
 
 	/* initial state */
 	if ((strstate = getenv ("HAL_PROP_BUTTON_STATE_VALUE")) == NULL) {
@@ -94,7 +79,7 @@
 	else
 		state = FALSE;
 
-	if ((fd = open ("/dev/adb", O_RDWR | O_NONBLOCK)) < 0) {
+	if ((fd = open ("/dev/adb", O_RDWR)) < 0) {
                 dbg ("Cannot open /dev/adb");
                 goto out;
 	}
@@ -106,14 +91,9 @@
 		buf[1] = PMU_GET_COVER;
 
 		n = write (fd, buf, 2);
-
-		usleep (100 * 1000);
-
 		if (n == 2) {
 			rd = read (fd, buf, sizeof (buf));
 			if (rd <= 0) {
-				if (errno == EAGAIN)
-					goto tryagain;
 				dbg ("Error reading from fd; read returned %d; err=%s", errno, strerror (errno));
 				goto out;
 			}
@@ -144,8 +124,7 @@
 
 			
 		}
-	tryagain:
-		usleep (900 * 1000);
+		usleep (1000 * 1000);
 	}
 
 


More information about the hal mailing list