hal: Branch 'master' - 15 commits

Danny Kukawka dkukawka at kemper.freedesktop.org
Fri Aug 7 00:17:07 PDT 2009


 doc/spec/hal-spec-properties.xml    |   45 +++++++++++++++
 hald/.gitignore                     |    1 
 hald/freebsd/libprobe/hfp.c         |    2 
 hald/freebsd/probing/probe-smbios.c |    4 -
 hald/hald_dbus.c                    |   15 ++---
 hald/hald_runner.c                  |    3 -
 hald/linux/acpi.c                   |    1 
 hald/linux/addons/addon-leds.c      |   54 +++++++++++++++---
 hald/linux/device.c                 |  107 ++++++++++++++++++++++++++++++++----
 hald/linux/hotplug.c                |   55 +++++++++++++++++-
 hald/linux/osspec.c                 |    1 
 hald/massif-hald.sh                 |   35 +++++++++--
 hald/valgrind-hald.sh               |    3 -
 13 files changed, 280 insertions(+), 46 deletions(-)

New commits:
commit 62e80cfc72e07036e188bf847b366e4f812a7944
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Thu Aug 6 18:17:36 2009 +0200

    add a check for leds.num_levels to addon-leds.c
    
    Added a check for leds.num_levels to addon-leds.c.

diff --git a/hald/linux/addons/addon-leds.c b/hald/linux/addons/addon-leds.c
index 024c51b..e3ab34f 100644
--- a/hald/linux/addons/addon-leds.c
+++ b/hald/linux/addons/addon-leds.c
@@ -99,13 +99,21 @@ set_leds_brightness (const char *udi, int level)
 	char path[256];
 	char buf[5];	/* Assume we don't need more */
 	char *sysfs_path;
+	DBusError error;
 
-	ret = -1;	
+	ret = -1;
 
 	if (!g_hash_table_lookup_extended (leds, udi, NULL, (gpointer) &sysfs_path)) {
 		return -1;
 	}
 
+	dbus_error_init (&error);
+
+	if (level > libhal_device_get_property_int (ctx, udi, "leds.num_levels", &error) -1) {
+		HAL_DEBUG (("Requested level is higher than max level (check leds.num_levels)."));
+		return -1;
+	}
+
 	snprintf (path, sizeof (path), "%s/brightness", sysfs_path);
 
 	fd = open (path, O_WRONLY);
commit 6947c6cceaf3c7787aaf109e6c9ec913dac97f77
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Thu Aug 6 18:08:18 2009 +0200

    always set leds.num_levels since it's mandatory
    
    Always set leds.num_levels since it's mandatory.

diff --git a/hald/linux/device.c b/hald/linux/device.c
index 5cd0437..3bd1383 100644
--- a/hald/linux/device.c
+++ b/hald/linux/device.c
@@ -1396,10 +1396,10 @@ leds_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_d
 	if (function != NULL && strcmp (function, "kbd_backlight")) {
 		hal_device_property_set_int (d, "keyboard_backlight.num_levels", max_brightness + 1);
 		hal_device_add_capability (d, "keyboard_backlight");
-	} else {
-		hal_device_property_set_int (d, "leds.num_levels", max_brightness + 1);
 	}
 
+	hal_device_property_set_int (d, "leds.num_levels", max_brightness + 1);
+
 	g_free (function);	
 	return d;
 }
commit 6a24907092f0ab835a4f4a1737e56ceb4ebe741a
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Thu Aug 6 18:06:40 2009 +0200

    update SPEC with kbd_backlight(.*) and leds.num_levels
    
    Updated SPEC with info about:
    - the kbd_backlight namespace including the
      keyboard_backlight.num_levels property
    - leds.num_levels

diff --git a/doc/spec/hal-spec-properties.xml b/doc/spec/hal-spec-properties.xml
index 711ef3f..fdfacf1 100644
--- a/doc/spec/hal-spec-properties.xml
+++ b/doc/spec/hal-spec-properties.xml
@@ -2149,6 +2149,16 @@ org.freedesktop.Hal.Device.Volume.method_signatures = {'ssas', 'as', 'as'}
               <entry>Yes</entry>
               <entry>The function of the LED.</entry>
             </row>
+            <row>
+              <entry>
+                <literal>leds.num_levels</literal> (int)
+              </entry>
+              <entry></entry>
+              <entry>Yes</entry>
+              <entry>
+                The brightness levels supported by the LED device.
+              </entry>
+            </row>
           </tbody>
         </tgroup>
       </informaltable>
@@ -4904,6 +4914,41 @@ org.freedesktop.Hal.Device.Volume.method_signatures = {'ssas', 'as', 'as'}
       </informaltable>
     </sect2>
 
+    <sect2 id="device-properties-keyboard_backlight">
+      <title>
+        keyboard_backlight namespace
+      </title>
+      <para>
+        Device objects with the capability <literal>keyboard_backlight</literal>
+        represent all the devices capable handling the keyboard backlight. (Note:
+	normally those devices have also the <literal>leds</literal> capability.)
+      </para>
+      <informaltable>
+        <tgroup cols="2">
+          <thead>
+            <row>
+              <entry>Key (type)</entry>
+              <entry>Values</entry>
+              <entry>Mandatory</entry>
+              <entry>Description</entry>
+            </row>
+          </thead>
+          <tbody>
+            <row>
+              <entry>
+                <literal>keyboard_backlight.num_levels</literal> (bool)
+              </entry>
+              <entry></entry>
+              <entry>Yes</entry>
+              <entry>
+		The brightness levels supported by the LED device.
+              </entry>
+            </row>
+          </tbody>
+        </tgroup>
+      </informaltable>
+    </sect2>
+
     <sect2 id="device-properties-killswitch">
       <title>
         killswitch namespace
commit f56405d3067eb67b4665b301eff2ef3164e732e4
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Thu Aug 6 17:58:59 2009 +0200

    add keyboard_backlight.* and *.num_levels to led class
    
    Added new keys to leds device class:
    - add keyboard_backlight.num_levels/leds.num_levels to store
      the available number of brightness levels
    - add keyboard_backlight capability if the device has
      leds.function == "kbd_backlight"

diff --git a/hald/linux/device.c b/hald/linux/device.c
index 902e0a9..5cd0437 100644
--- a/hald/linux/device.c
+++ b/hald/linux/device.c
@@ -1351,10 +1351,13 @@ leds_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_d
 {
 	HalDevice *d;
 	const gchar *dev_name;
-        gchar **attributes;
+	gchar *function;
+	gchar **attributes;
+	int max_brightness;
 
 	d = hal_device_new ();
-
+	function = NULL;
+	
 	if (parent_dev != NULL)
                 hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev));
         else
@@ -1377,14 +1380,27 @@ leds_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_d
 				if (attributes[1] != NULL ) {
 					if (attributes[1][0] != '\0')
 						hal_device_property_set_string (d, "leds.colour", attributes[1]);
-					if (attributes[2] != NULL && attributes[2][0] != '\0')
+					if (attributes[2] != NULL && attributes[2][0] != '\0') {
 						hal_device_property_set_string (d, "leds.function", attributes[2]);
+						function = g_strdup (attributes[2]);
+					}
 				}
 			}
 		}
 		g_strfreev (attributes);
 	}
-	
+
+	if (!hal_util_get_int_from_file (sysfs_path, "max_brightness", &max_brightness, 0))
+		max_brightness = 255;
+
+	if (function != NULL && strcmp (function, "kbd_backlight")) {
+		hal_device_property_set_int (d, "keyboard_backlight.num_levels", max_brightness + 1);
+		hal_device_add_capability (d, "keyboard_backlight");
+	} else {
+		hal_device_property_set_int (d, "leds.num_levels", max_brightness + 1);
+	}
+
+	g_free (function);	
 	return d;
 }
 
commit 83c33b40c2be23d4d982777272c7ae2bc714f9e8
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Wed Aug 5 13:36:57 2009 +0200

    adopted version of commit 122e41a10 to fix docking stations
    
    Adopted version of reverted commit 122e41a10 to adapt changes
    in the kernel regarding to docking stations from Holger Macht
    <hmacht at suse.de>.
    
    Added function and code to check for kernel version >= 2.6.28
    to get HAL working also with older kernel versions.

diff --git a/hald/linux/device.c b/hald/linux/device.c
index d8c543d..902e0a9 100644
--- a/hald/linux/device.c
+++ b/hald/linux/device.c
@@ -88,6 +88,42 @@ static gboolean battery_poll_running = FALSE;
 #define LONG(x) ((x)/BITS_PER_LONG)
 #define test_bit(bit, array)    ((array[LONG(bit)] >> OFF(bit)) & 1)
 
+/******************** helper functions **********************/
+
+static gboolean
+compare_ge_kernel_version (int major, int minor, int micro) {
+
+	HalDevice *root;
+
+	root = hal_device_store_find (hald_get_gdl (), "/org/freedesktop/Hal/devices/computer");
+	if (root == NULL) {
+		root = hal_device_store_find (hald_get_tdl (), "/org/freedesktop/Hal/devices/computer");
+		if (root == NULL) {
+			HAL_ERROR (("Couldn't find computer root object."));
+			return FALSE;
+		}
+	}
+
+	if (hal_device_has_property (root, "system.kernel.version.major")) {
+		int _major, _minor, _micro;
+
+		_major = hal_device_property_get_int (root, "system.kernel.version.major");
+		_minor = hal_device_property_get_int (root, "system.kernel.version.minor");
+		_micro = hal_device_property_get_int (root, "system.kernel.version.micro");
+
+		if ((major < _major) || ((major == _major) && (minor < _minor)) ||
+		   ((major == _major) && (minor == _minor) && (micro < _micro)) ) {
+			return FALSE;
+		} else {
+			return TRUE;
+		}
+	} else {
+		HAL_DEBUG (("Couldn't get system.kernel.version.m* properties."));
+		return FALSE;
+	}
+}
+
+
 /*--------------------------------------------------------------------------------------------------------------*/
 /* 		 	PLEASE KEEP THE SUBSYSTEMS IN ALPHABETICAL ORDER !!!					*/
 /*--------------------------------------------------------------------------------------------------------------*/
@@ -2041,6 +2077,17 @@ platform_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *pare
 	if (strncmp (dev_id, "dock", 4) == 0) {
 		int docked;
 
+		if (compare_ge_kernel_version(2,6,28)) {
+			gchar *type;
+
+			type = hal_util_get_string_from_file (sysfs_path, "type");
+			if (type != NULL && strcmp (type, "dock_station") == 0) {
+				hal_device_property_set_string (d, "info.type", type);
+				hal_device_add_capability (d, "dock_station");
+			}
+	
+		} 
+
 		hal_util_get_int_from_file (sysfs_path, "docked", &docked, 0);
 		hal_device_property_set_bool (d, "info.docked", docked);
 	}
@@ -2075,9 +2122,15 @@ platform_refresh_undock (gpointer data)
 	sysfs_path = hal_device_property_get_string(d, "linux.sysfs_path");
 	hal_util_get_int_from_file (sysfs_path, "flags", &flags, 0);
 
-	/* check for != 0, maybe the user did an immediate dock */
-	if (flags != 0)
-		return TRUE;
+	if (compare_ge_kernel_version (2,6,28)) {
+		/* check for != 16, maybe the user did an immediate dock */
+		if (flags != 16)
+			return TRUE;
+	} else {
+		/* check for != 0, maybe the user did an immediate dock */
+		if (flags != 0)
+			return TRUE;
+	}
 
 	hal_util_get_int_from_file (sysfs_path, "docked", &docked, 0);
 	hal_device_property_set_bool (d, "info.docked", docked);
@@ -2095,16 +2148,32 @@ platform_refresh (HalDevice *d)
 	if (strncmp (id, "dock", 4) != 0)
 		return TRUE;
 
+	if (compare_ge_kernel_version (2,6,28)) {
+		const gchar *type;
+
+		type = hal_device_property_get_string(d, "info.type");
+		if (type != NULL && strcmp (type, "dock_station") != 0)
+			return TRUE;
+	}
+
 	sysfs_path = hal_device_property_get_string(d, "linux.sysfs_path");
 	hal_util_get_int_from_file (sysfs_path, "docked", &docked, 0);
 
 	if (docked == 1) {
 		/* undock still in progress? */
 		hal_util_get_int_from_file (sysfs_path, "flags", &flags, 0);
-		if (flags == 2) {
-			g_timeout_add (DOCK_STATION_UNDOCK_POLL_INTERVAL,
-				       platform_refresh_undock, d);
-			return TRUE;
+		if (compare_ge_kernel_version (2,6,28)) {
+			if (flags == 2) {
+				g_timeout_add (DOCK_STATION_UNDOCK_POLL_INTERVAL,
+					       platform_refresh_undock, d);
+				return TRUE;
+			}
+		} else {
+			if (flags == 18) {
+				g_timeout_add (DOCK_STATION_UNDOCK_POLL_INTERVAL,
+					       platform_refresh_undock, d);
+				return TRUE;
+			}
 		}
 	}
 
commit ac7648c841fb6d2685c15094e3ccbf2a1e9fe0e8
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Sun Aug 2 16:06:00 2009 +0200

    fix DBusError handling in freebsd code
    
    Fixed DBusError handling in freebsd code:
    - free DBusError only if really set
    - remove unneeded DBusError variable

diff --git a/hald/freebsd/libprobe/hfp.c b/hald/freebsd/libprobe/hfp.c
index d51ca61..7d16bae 100644
--- a/hald/freebsd/libprobe/hfp.c
+++ b/hald/freebsd/libprobe/hfp.c
@@ -69,7 +69,7 @@ hfp_init (int argc, char **argv)
 
   dbus_error_init(&hfp_error);
   hfp_ctx = libhal_ctx_init_direct(&hfp_error);
-  dbus_error_free(&hfp_error);
+  LIBHAL_FREE_DBUS_ERROR(&hfp_error);
 
   return TRUE;
 }
diff --git a/hald/freebsd/probing/probe-smbios.c b/hald/freebsd/probing/probe-smbios.c
index 1c479b7..62149fa 100644
--- a/hald/freebsd/probing/probe-smbios.c
+++ b/hald/freebsd/probing/probe-smbios.c
@@ -71,6 +71,7 @@ setstr (char *buf, char *str, char *prop)
 			goto out;
 
 		libhal_device_set_property_string (hfp_ctx, hfp_udi, prop, value, &hfp_error);
+		LIBHAL_FREE_DBUS_ERROR (&hfp_error);
 		hfp_info ("Setting %s='%s'", prop, value);
 		return TRUE;
 	}
@@ -102,7 +103,6 @@ int
 main (int argc, char *argv[])
 {
 	int ret;
-	DBusError error;
 	char buf[512];
 	char *nbuf;
 	int dmipipe[2];
@@ -124,8 +124,6 @@ main (int argc, char *argv[])
 	if (! hfp_init (argc, argv))
 	  goto out;
 
-	dbus_error_init (&error);
-
 	tmp_ret = pipe (dmipipe);
 	f = fdopen (dmipipe[0], "r");
 	nullfd = open ("/dev/null", O_RDONLY);
commit 8a53cf85780e167d5a62d6b2702982d79b4486ea
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Sun Aug 2 12:24:49 2009 +0200

    fix memory leak due to usage of g_strdup()
    
    Fixed  memory leak due to usage of g_strdup().

diff --git a/hald/linux/osspec.c b/hald/linux/osspec.c
index 998ae79..e339902 100644
--- a/hald/linux/osspec.c
+++ b/hald/linux/osspec.c
@@ -360,6 +360,7 @@ osspec_privileged_init_preparse_set_dmi (gboolean set, HalDevice *d)
 				hal_device_property_set_string (d, "system.board.serial", board_serial);
 				g_free (product_serial);
 				g_free (product_uuid);
+				g_free (board_serial);
 				parsed = FALSE;
 			}
 		}
commit f40d305cf928fe2d0d79f66e6d39126b06cbf0f8
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Sun Aug 2 12:09:32 2009 +0200

    fix memory leak in acpi_button_add() in error case
    
    Fixed memory leak in acpi_button_add() in error case due to
    usage of hal_util_get_parent_path() which return a gchar*
    created with g_strndup().

diff --git a/hald/linux/acpi.c b/hald/linux/acpi.c
index 6f76af6..518093d 100644
--- a/hald/linux/acpi.c
+++ b/hald/linux/acpi.c
@@ -1003,6 +1003,7 @@ acpi_button_add (const gchar *acpi_path, HalDevice *parent, ACPIDevHandler *hand
 	return acpi_generic_add (acpi_path, parent, handler);
 
 out:
+	g_free (parent_path);
 	return NULL;
 }
 
commit 77e9b8b8884c763de5cae2dacb5dd8df54ffbcd6
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Sun Aug 2 11:50:50 2009 +0200

    add hald/valgrind.log to .gitignore
    
    Added hald/valgrind.log to .gitignore.

diff --git a/hald/.gitignore b/hald/.gitignore
index d7a36ff..d67b00b 100644
--- a/hald/.gitignore
+++ b/hald/.gitignore
@@ -12,3 +12,4 @@ hald-generate-fdi-cache
 *~
 .local-fdi
 massif.*
+valgrind.log
commit 011cc3cd603f74460762e6473ce97c1808e20a42
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Sun Aug 2 11:47:56 2009 +0200

    fix memory leaks due to usage of g_path_get_basename()
    
    Fixed memory leaks due to usage of g_path_get_basename()
    and free'ing in error cases.

diff --git a/hald/hald_dbus.c b/hald/hald_dbus.c
index 2634217..a144f51 100644
--- a/hald/hald_dbus.c
+++ b/hald/hald_dbus.c
@@ -5689,12 +5689,11 @@ hald_dbus_session_active_changed (CKTracker *tracker, CKSession *session, void *
 
         session_changes_push (d, programs, extra_env);
 
-	g_free (session_id);
 	g_free (extra_env[1]);
 	g_free (extra_env[2]);
 	g_free (extra_env[3]);
 out:
-	;
+	g_free (session_id);
 }
 
 static void 
@@ -5735,13 +5734,12 @@ hald_dbus_session_added (CKTracker *tracker, CKSession *session, void *user_data
 
         session_changes_push (d, programs, extra_env);
 
-	g_free (session_id);
-	g_free (seat_id);
 	g_free (extra_env[1]);
 	g_free (extra_env[2]);
 	g_free (extra_env[3]);
 out:
-	;
+	g_free (session_id);
+	g_free (seat_id);
 }
 
 static void 
@@ -5783,13 +5781,12 @@ hald_dbus_session_removed (CKTracker *tracker, CKSession *session, void *user_da
 
         session_changes_push (d, programs, extra_env);
 
-	g_free (session_id);
-	g_free (seat_id);
 	g_free (extra_env[1]);
 	g_free (extra_env[2]);
 	g_free (extra_env[3]);
 out:
-	;
+	g_free (session_id);
+	g_free (seat_id);
 }
 
 static void
diff --git a/hald/hald_runner.c b/hald/hald_runner.c
index f21e300..35b3b21 100644
--- a/hald/hald_runner.c
+++ b/hald/hald_runner.c
@@ -427,7 +427,7 @@ add_basic_env (DBusMessageIter * iter, const gchar * udi)
                         num_sessions_total += num_sessions;
 			for (j = sessions; j != NULL; j = g_slist_next (j)) {
 				CKSession *session;
-				const char *session_id;
+				char *session_id;
                                 const char *q;
 
 				session = j->data;
@@ -467,6 +467,7 @@ add_basic_env (DBusMessageIter * iter, const gchar * udi)
                                         add_env (iter, s, q);
                                         g_free (s);
                                 }
+				g_free (session_id);
 			}
 
 			/* for each Seat, export sessions on each seat 
commit c9c48ea6db059d77497a7f121f586956650cad60
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Sun Aug 2 11:41:41 2009 +0200

    changed valgrind-hald.sh to write a logfile
    
    Changed valgrind-hald.sh to write a logfile (valgrind.log).

diff --git a/hald/valgrind-hald.sh b/hald/valgrind-hald.sh
index ab56633..365ef20 100755
--- a/hald/valgrind-hald.sh
+++ b/hald/valgrind-hald.sh
@@ -33,4 +33,5 @@ export HAL_FDI_CACHE_NAME=$HALD_TMPDIR/hald-local-fdi-cache
 export POLKIT_POLICY_DIR=$HALD_TMPDIR/share/PolicyKit/policy
 
 #valgrind --num-callers=20 --show-reachable=yes --leak-check=yes --tool=memcheck ./hald --daemon=no --verbose=yes $@
-valgrind --show-reachable=yes --tool=memcheck --leak-check=full ./hald --daemon=no --verbose=yes $@
+valgrind --show-reachable=yes --tool=memcheck --leak-check=full --leak-resolution=high --log-file=valgrind.log \
+	 ./hald --daemon=no --verbose=yes --exit-after-probing $@
commit 7a1a54c14acb7b1479f9b1e7dafb14fab7b77dca
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Sun Aug 2 11:20:21 2009 +0200

    changed massif-hald.sh to work the same way as run-hald.sh
    
    Changed massif-hald.sh to work the same way as run-hald.sh
    (use local fdi and cache files).

diff --git a/hald/massif-hald.sh b/hald/massif-hald.sh
index 8f43259..96359d0 100755
--- a/hald/massif-hald.sh
+++ b/hald/massif-hald.sh
@@ -1,22 +1,43 @@
 #!/bin/sh
 
-export HALD_RUNNER_PATH=`pwd`/linux:`pwd`/linux/probing:`pwd`/linux/addons:`pwd`/.:`pwd`/../tools:`pwd`/../tools/linux
+information_fdidir="../../hal-info/fdi"
+
+case `uname -s` in
+    FreeBSD)    backend=freebsd ;;
+    SunOS)      backend=solaris ;;
+    *)          backend=linux ;;
+esac
+export HALD_RUNNER_PATH=`pwd`/$backend:`pwd`/$backend/probing:`pwd`/$backend/addons:`pwd`/.:`pwd`/../tools:`pwd`/../tools/$backend
 export PATH=`pwd`/../hald-runner:$PATH
 
+HALD_TMPDIR=/tmp/run-hald-$USER
+
 if [ "$1" = "--skip-fdi-install" ] ; then
     shift
 else
-    rm -rf .local-fdi
-    make -C ../fdi install DESTDIR=`pwd`/.local-fdi prefix=/
+    rm -rf $HALD_TMPDIR
+    mkdir -p $HALD_TMPDIR
+    make -C ../policy install DESTDIR=$HALD_TMPDIR prefix=/
+    make -C ../fdi install DESTDIR=$HALD_TMPDIR prefix=/ && \
+    if [ ! -d $information_fdidir ] ; then
+        echo "ERROR: You need to checkout hal-info in the same level"
+        echo "directory as hal to get the information fdi files."
+        exit
+    fi
+    make -C $information_fdidir install DESTDIR=$HALD_TMPDIR prefix=/
 fi
-export HAL_FDI_SOURCE_PREPROBE=.local-fdi/share/hal/fdi/preprobe
-export HAL_FDI_SOURCE_INFORMATION=.local-fdi/share/hal/fdi/information
-export HAL_FDI_SOURCE_POLICY=.local-fdi/share/hal/fdi/policy
+
+export HAL_FDI_SOURCE_PREPROBE=$HALD_TMPDIR/share/hal/fdi/preprobe
+export HAL_FDI_SOURCE_INFORMATION=$HALD_TMPDIR/share/hal/fdi/information
+export HAL_FDI_SOURCE_POLICY=$HALD_TMPDIR/share/hal/fdi/policy
+export HAL_FDI_CACHE_NAME=$HALD_TMPDIR/hald-local-fdi-cache
+export POLKIT_POLICY_DIR=$HALD_TMPDIR/share/PolicyKit/policy
 
 #delete all old memory outputs, else we get hundreds
 rm massif.*
 
-G_SLICE="always-malloc" valgrind --num-callers=24 --tool=massif --depth=24 --format=html \
+#G_SLICE="always-malloc" valgrind --num-callers=24 --tool=massif --depth=24 --format=html \
+G_SLICE="always-malloc" valgrind --num-callers=24 --tool=massif --depth=24  \
         --alloc-fn=g_malloc --alloc-fn=g_realloc \
 	--alloc-fn=g_try_malloc --alloc-fn=g_malloc0 --alloc-fn=g_mem_chunk_all \
         --alloc-fn=g_slice_alloc0 --alloc-fn=g_slice_alloc \
commit c900d0e5012b1dd0e0fa6e20fd0d92a59b3de093
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Sat Aug 1 19:14:23 2009 +0200

    handle keyboard backlight leds via org.freedesktop.Hal.Device.KeyboardBacklight
    
    Changed addon-leds.c to handle keyboard backlight leds via
    the org.freedesktop.Hal.Device.KeyboardBacklight interface if they
    have leds.function=kbd_backlight.

diff --git a/hald/linux/addons/addon-leds.c b/hald/linux/addons/addon-leds.c
index a42f856..024c51b 100644
--- a/hald/linux/addons/addon-leds.c
+++ b/hald/linux/addons/addon-leds.c
@@ -137,6 +137,7 @@ filter_function (DBusConnection *connection, DBusMessage *message, void *userdat
 	DBusError err;
 	DBusMessage *reply;
 	const char *_udi;
+	const char *interface;
 	char *sysfs_path;
 
 	if ((_udi = dbus_message_get_path (message)) == NULL) {
@@ -151,16 +152,21 @@ filter_function (DBusConnection *connection, DBusMessage *message, void *userdat
 
 	dbus_error_init (&err);
 
-	if (!check_priv (ctx, connection, message, dbus_message_get_path (message), "org.freedesktop.hal.leds.brightness")) {
+	interface = dbus_message_get_interface (message);
+	if (interface != NULL && strcmp (interface, "org.freedesktop.Hal.Device.KeyboardBacklight") == 0) {
+		if (!check_priv (ctx, connection, message, dbus_message_get_path (message), "org.freedesktop.hal.power-management.keyboard-backlight")) {
+                	HAL_DEBUG(("User don't have the permissions to call the interface"));
+                	return DBUS_HANDLER_RESULT_HANDLED;
+		}
+	} else if (!check_priv (ctx, connection, message, dbus_message_get_path (message), "org.freedesktop.hal.leds.brightness")) {
 		HAL_DEBUG(("User don't have the permissions to call the interface"));
 		return DBUS_HANDLER_RESULT_HANDLED;
 	}
 
 	reply = NULL;
 
-	if (dbus_message_is_method_call (message,
-					 "org.freedesktop.Hal.Device.Leds",
-					 "SetBrightness")) {
+	if (dbus_message_is_method_call (message, "org.freedesktop.Hal.Device.Leds", "SetBrightness") || 
+	    dbus_message_is_method_call (message, "org.freedesktop.Hal.Device.KeyboardBacklight", "SetBrightness")) {
 		int brightness;
 
 		if (dbus_message_get_args (message,
@@ -187,9 +193,8 @@ filter_function (DBusConnection *connection, DBusMessage *message, void *userdat
 
 			dbus_connection_send (connection, reply, NULL);
 		}
-	} else if (dbus_message_is_method_call (message,
-					 	"org.freedesktop.Hal.Device.Leds",
-						"GetBrightness")) {
+	} else if (dbus_message_is_method_call (message, "org.freedesktop.Hal.Device.Leds", "GetBrightness") ||
+		   dbus_message_is_method_call (message, "org.freedesktop.Hal.Device.KeyboardBacklight", "GetBrightness")) {
 		int brightness;
 
 		if (dbus_message_get_args (message,
@@ -225,12 +230,17 @@ add_device (LibHalContext *ctx,
 	DBusError err;
 	DBusConnection *dbus_connection;
 	const char* sysfs_path;
+	const char* function;
 	static gboolean initialized = FALSE;
 
 	if ((sysfs_path = libhal_ps_get_string (properties, "linux.sysfs_path")) == NULL) {
 		HAL_ERROR(("%s has no property linux.sysfs_path", udi));
 		return;
 	}
+	if ((function = libhal_ps_get_string (properties, "leds.function")) == NULL) {
+		HAL_ERROR(("%s has no property leds.function", udi));
+		return;
+	}
 
 	/* claim the interface */
 	
@@ -246,7 +256,25 @@ add_device (LibHalContext *ctx,
 
 	dbus_error_init (&err);
 
-	if (!libhal_device_claim_interface (ctx,
+	if (function != NULL && strcmp(function, "kbd_backlight") == 0) {
+		HAL_DEBUG (("Found a led which is a keyboard backlight."));
+		
+		if (!libhal_device_claim_interface (ctx,
+						    udi,
+						    "org.freedesktop.Hal.Device.KeyboardBacklight",
+						    "    <method name=\"SetBrightness\">\n"
+						    "      <arg name=\"brightness_value\" direction=\"in\" type=\"i\"/>\n"
+						    "      <arg name=\"return_code\" direction=\"out\" type=\"i\"/>\n"
+						    "    </method>\n"
+						    "    <method name=\"GetBrightness\">\n"
+						    "      <arg name=\"brightness_value\" direction=\"out\" type=\"i\"/>\n"
+						    "    </method>\n",
+						    &err)) {
+			HAL_ERROR (("Cannot claim interface 'org.freedesktop.Hal.Device.KeyboardBacklight'"));
+			LIBHAL_FREE_DBUS_ERROR (&err);
+			return;
+		}
+	} else if (!libhal_device_claim_interface (ctx,
 					    udi,
 					    "org.freedesktop.Hal.Device.Leds",
 					    "    <method name=\"SetBrightness\">\n"
commit 72a4f3bc742023b39ada6cbda98f2bb75941f5f9
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Sat Aug 1 14:33:32 2009 +0200

    fix hotplug_event_process_queue() to get reprobe working
    
    Fixed hotplug_event_process_queue() to get reprobe working.
    Added new function to check if there is still a REMOVE/ADD event
    for the same device (sysfs_path) in the queue of the running
    hotplug events. Wait for those events to prevent trouble if
    e.g. a HOTPLUG_ACTION_REMOVE is still running and a
    HOTPLUG_ACTION_ADD is the next event.

diff --git a/hald/linux/hotplug.c b/hald/linux/hotplug.c
index 9e80252..63d7cc2 100644
--- a/hald/linux/hotplug.c
+++ b/hald/linux/hotplug.c
@@ -393,8 +393,10 @@ compare_events (HotplugEvent *hotplug_event, GList *events)
 		for (lp = events; lp; lp = g_list_next (lp)) {
 			loop_event = (HotplugEvent*) lp->data;
 			/* skip ourselves and all later events*/
-			if (loop_event->sysfs.seqnum >= hotplug_event->sysfs.seqnum)
+			if (loop_event->sysfs.seqnum >= hotplug_event->sysfs.seqnum) {
+				HAL_DEBUG (("event %s: skip ourselves and all later events", hotplug_event->sysfs.sysfs_path));
 				break;
+			}
 			if (compare_event (hotplug_event, loop_event)) {
 				HAL_DEBUG (("event %s dependant on %s", hotplug_event->sysfs.sysfs_path, loop_event->sysfs.sysfs_path));
 				return TRUE;
@@ -413,6 +415,43 @@ compare_events (HotplugEvent *hotplug_event, GList *events)
 	}
 }
 
+/*
+ * Returns TRUE if @hotplug_event depends on any running event in @events
+ * This function checks if there is a running remove/add event for the same 
+ * sysfs_path/device. (for more see fd.o#23060)
+ */
+static gboolean
+compare_events_running (HotplugEvent *hotplug_event, GList *events)
+{
+	GList *lp;
+	HotplugEvent *loop_event;
+
+	switch (hotplug_event->type) {
+
+	/* explicit fallthrough */
+	case HOTPLUG_EVENT_SYSFS:
+	case HOTPLUG_EVENT_SYSFS_DEVICE:
+	case HOTPLUG_EVENT_SYSFS_BLOCK:
+
+		for (lp = events; lp; lp = g_list_next (lp)) {
+			loop_event = (HotplugEvent*) lp->data;
+			/* skip ourselves and all later events*/
+			if (!strcmp (hotplug_event->sysfs.sysfs_path, loop_event->sysfs.sysfs_path)) {
+				if (loop_event->action != hotplug_event->action) {
+					HAL_DEBUG (("there is still a event running for this device, wait!"));
+					return TRUE;
+				}
+
+			}
+		}
+		return FALSE;
+
+	default:
+		return FALSE;
+	}
+}
+
+
 
 void 
 hotplug_event_process_queue (void)
@@ -432,9 +471,17 @@ hotplug_event_process_queue (void)
 	lp = hotplug_event_queue->head;
 	while (lp != NULL) {
 		hotplug_event = lp->data;
-		HAL_INFO (("checking event %s", hotplug_event->sysfs.sysfs_path));
-		if (!compare_events (hotplug_event, hotplug_event_queue->head)
-		 && !compare_events (hotplug_event, hotplug_events_in_progress)) {
+
+		if (hotplug_event->action == HOTPLUG_ACTION_ADD)
+			HAL_DEBUG (("checking ADD event %s", hotplug_event->sysfs.sysfs_path));
+		else if (hotplug_event->action == HOTPLUG_ACTION_REMOVE)
+			HAL_DEBUG (("checking REMOVE event %s", hotplug_event->sysfs.sysfs_path));
+		else 
+			HAL_DEBUG (("checking event %s, action: %d", hotplug_event->sysfs.sysfs_path, hotplug_event->action));
+
+		if (!compare_events (hotplug_event, hotplug_event_queue->head) && 
+		    !compare_events (hotplug_event, hotplug_events_in_progress) &&
+		    !compare_events_running (hotplug_event, hotplug_events_in_progress)) {
 			lp2 = lp->prev;
 			g_queue_unlink(hotplug_event_queue, lp);
 			hotplug_events_in_progress = g_list_concat (hotplug_events_in_progress, lp);
commit 5152bb3155dc1a6f301b34b1dc9fade9d112630e
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Sat Aug 1 12:41:22 2009 +0200

    extend debug message in device_reprobe()
    
    Extended debug message in device_reprobe().

diff --git a/hald/hald_dbus.c b/hald/hald_dbus.c
index 6d76bb4..2634217 100644
--- a/hald/hald_dbus.c
+++ b/hald/hald_dbus.c
@@ -3165,7 +3165,7 @@ device_reprobe (DBusConnection * connection, DBusMessage * message, dbus_bool_t
 		return DBUS_HANDLER_RESULT_HANDLED;
 	}
 
-	HAL_DEBUG (("udi=%s", udi));
+	HAL_DEBUG (("device_reprobe() for udi=%s", udi));
 
 	device = hal_device_store_find (hald_get_gdl (), udi);
 	if (device == NULL)


More information about the hal-commit mailing list