hal/hald/linux2/addons addon-pmu.c,1.4,1.5
David Zeuthen
david at freedesktop.org
Wed Jan 18 15:22:36 PST 2006
Update of /cvs/hal/hal/hald/linux2/addons
In directory gabe:/tmp/cvs-serv4138/hald/linux2/addons
Modified Files:
addon-pmu.c
Log Message:
2006-01-18 David Zeuthen <david at fubar.dk>
* hald/linux2/addons/addon-pmu.c (main): Use a direct connection to
the bus; sleep between writing and reading as otherwise we may get
EAGAIN. Handle EAGAIN by just trying again later.
Index: addon-pmu.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/addons/addon-pmu.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- addon-pmu.c 27 Sep 2005 09:42:13 -0000 1.4
+++ addon-pmu.c 18 Jan 2006 23:22:33 -0000 1.5
@@ -49,7 +49,6 @@
char *udi;
LibHalContext *ctx = NULL;
DBusError error;
- DBusConnection *conn;
int rd;
char buf[256];
int state;
@@ -66,15 +65,24 @@
goto out;
dbus_error_init (&error);
- 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))
+
+#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) {
@@ -98,10 +106,15 @@
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) {
- dbg ("Error reading from fd; read returned %d; err=%s", strerror (errno));
+ if (errno == EAGAIN)
+ goto tryagain;
+ dbg ("Error reading from fd; read returned %d; err=%s", errno, strerror (errno));
goto out;
}
@@ -131,8 +144,8 @@
}
-
- sleep (1);
+ tryagain:
+ usleep (900 * 1000);
}
More information about the hal-commit
mailing list