hal: Branch 'origin' - 6 commits

David Zeuthen david at kemper.freedesktop.org
Thu Feb 15 16:26:18 PST 2007


 configure.in                                |   38 +
 doc/spec/hal-spec-examples.xml              |   16 
 fdi/policy/10osvendor/10-omap-backlight.fdi |    4 
 fdi/policy/10osvendor/20-acl-management.fdi |   34 +
 fdi/policy/10osvendor/Makefile.am           |    8 
 hald/Makefile.am                            |    3 
 hald/ck-tracker.c                           |  637 ++++++++++++++++++++
 hald/ck-tracker.h                           |   86 ++
 hald/hald.c                                 |    4 
 hald/hald_dbus.c                            |  110 ++-
 hald/hald_dbus.h                            |    2 
 hald/hald_runner.c                          |  881 ++++++++++++++--------------
 hald/linux/addons/Makefile.am               |   11 
 hald/linux/addons/addon-omap-backlight.c    |    4 
 hald/util.c                                 |    6 
 tools/Makefile.am                           |   17 
 tools/hal-acl-add.c                         |   91 ++
 tools/hal-acl-remove.c                      |   15 
 18 files changed, 1502 insertions(+), 465 deletions(-)

New commits:
diff-tree cf5cb809dffe8bbfb25ec90a54c38b0bbe5b4b99 (from 8e2dd8e15febac3b6d7a21f87992b035fa171a73)
Author: Patrice Dumas <pertusus at free.fr>
Date:   Thu Feb 15 15:03:50 2007 -0500

    mention libhal in the docs
    
    > > Something unrelated is that I believe it would be nice to have, in
    > > the section 4 of the HAL 0.5.9 Specification a mention of libhal and
    > > a brief explanation of what it is.
    >
    > Yes, that document needs some love. We take patches though :-)
    
    Here it is. I don't really know the docbook language, so this may
    need corrections. And I am not an english natie speaker.

diff --git a/doc/spec/hal-spec-examples.xml b/doc/spec/hal-spec-examples.xml
index 4157a64..e931631 100644
--- a/doc/spec/hal-spec-examples.xml
+++ b/doc/spec/hal-spec-examples.xml
@@ -114,12 +114,22 @@
       GDL (global device list) and first then it becomes ''visible'' for
       desktop applications.
     </para>
-
+    <para>
+      Using D-BUS terminology, the HAL daemon provides the D-BUS
+      service <literal>org.freedesktop.Hal</literal>. This service may
+      be used to communicate with the HAL daemon, to get or set device
+      properties and to perform some action on the devices. In the 
+      following sections, this D-BUS interface is expanded.
+    </para>
+    <para>
+      A <literal>C</literal> API is provided by the libhal library.
+      This API hides most of the D-BUS complexity and presents the D-BUS 
+      interface as function call or callbacks.
+    </para>
     <sect2>
       <title>Interface org.freedesktop.Hal.Manager</title>
       <para>
-        Using D-BUS terminology, the HAL daemon provides the D-BUS
-        service <literal>org.freedesktop.Hal</literal>. This service
+        The <literal>org.freedesktop.Hal</literal> D-BUS service
         offers a D-BUS object at a well-known
         location <literal>/org/freedesktop/Hal/Manager</literal>. This
         object offers a D-BUS
diff-tree 8e2dd8e15febac3b6d7a21f87992b035fa171a73 (from a366164c0c0cb153b0fcbd6e8810965f5da16532)
Author: David Zeuthen <davidz at redhat.com>
Date:   Thu Feb 15 15:00:07 2007 -0500

    fix up coding style for hald_runner.c
    
    indent -kr -i8 -pcs -lps -psl hald/hald_runner.c

diff --git a/hald/hald_runner.c b/hald/hald_runner.c
index 95edbec..792c9c4 100644
--- a/hald/hald_runner.c
+++ b/hald/hald_runner.c
@@ -45,10 +45,10 @@
 #include "hald_runner.h"
 
 typedef struct {
-  HalDevice *d;
-  HalRunTerminatedCB cb;
-  gpointer data1;
-  gpointer data2;
+	HalDevice *d;
+	HalRunTerminatedCB cb;
+	gpointer data1;
+	gpointer data2;
 } HelperData;
 
 #define DBUS_SERVER_ADDRESS "unix:tmpdir=" HALD_SOCKET_DIR
@@ -57,8 +57,7 @@ static DBusConnection *runner_connection
 static HaldRunnerRunNotify method_run_notify = NULL;
 static gpointer method_run_notify_userdata = NULL;
 
-typedef struct
-{
+typedef struct {
 	GPid pid;
 	HalDevice *device;
 	HalRunTerminatedCB cb;
@@ -70,7 +69,7 @@ typedef struct
 static GSList *running_processes = NULL;
 
 static void
-running_processes_remove_device (HalDevice *device)
+running_processes_remove_device (HalDevice * device)
 {
 	GSList *i;
 	GSList *j;
@@ -83,32 +82,28 @@ running_processes_remove_device (HalDevi
 
 		if (rp->device == device) {
 			g_free (rp);
-			running_processes = g_slist_delete_link (running_processes, i);
+			running_processes =
+			    g_slist_delete_link (running_processes, i);
 		}
 
 	}
 }
 
 void
-runner_device_finalized (HalDevice *device)
+runner_device_finalized (HalDevice * device)
 {
 	running_processes_remove_device (device);
 }
 
 
-static DBusHandlerResult 
-runner_server_message_handler (DBusConnection *connection, 
-			       DBusMessage *message, 
-			       void *user_data)
+static DBusHandlerResult
+runner_server_message_handler (DBusConnection * connection,
+			       DBusMessage * message, void *user_data)
 {
 
-	HAL_INFO (("runner_server_message_handler: destination=%s obj_path=%s interface=%s method=%s", 
-		   dbus_message_get_destination (message), 
-		   dbus_message_get_path (message), 
-		   dbus_message_get_interface (message),
-		   dbus_message_get_member (message)));
-	if (dbus_message_is_signal (message, 
-				    "org.freedesktop.HalRunner", 
+	HAL_INFO (("runner_server_message_handler: destination=%s obj_path=%s interface=%s method=%s", dbus_message_get_destination (message), dbus_message_get_path (message), dbus_message_get_interface (message), dbus_message_get_member (message)));
+	if (dbus_message_is_signal (message,
+				    "org.freedesktop.HalRunner",
 				    "StartedProcessExited")) {
 		dbus_uint64_t dpid;
 		DBusError error;
@@ -123,23 +118,28 @@ runner_server_message_handler (DBusConne
 
 			HAL_INFO (("Previously started process with pid %d exited", pid));
 
-			for (i = running_processes; i != NULL; i = g_slist_next (i)) {
+			for (i = running_processes; i != NULL;
+			     i = g_slist_next (i)) {
 				RunningProcess *rp;
 
 				rp = i->data;
 
 				if (rp->pid == pid) {
-					rp->cb (rp->device, 0, 0, NULL, rp->data1, rp->data2);
+					rp->cb (rp->device, 0, 0, NULL,
+						rp->data1, rp->data2);
 					g_free (rp);
-					running_processes = g_slist_delete_link (running_processes, i);
+					running_processes =
+					    g_slist_delete_link
+					    (running_processes, i);
 					break;
 				}
 			}
 		}
-	} else if (dbus_message_is_signal (message, 
-					   DBUS_INTERFACE_LOCAL, 
+	} else if (dbus_message_is_signal (message,
+					   DBUS_INTERFACE_LOCAL,
 					   "Disconnected") &&
-		   strcmp (dbus_message_get_path (message), DBUS_PATH_LOCAL) == 0) {
+		   strcmp (dbus_message_get_path (message),
+			   DBUS_PATH_LOCAL) == 0) {
 		HAL_INFO (("runner process disconnected"));
 		dbus_connection_unref (connection);
 	}
@@ -148,7 +148,8 @@ runner_server_message_handler (DBusConne
 }
 
 static void
-runner_server_unregister_handler (DBusConnection *connection, void *user_data)
+runner_server_unregister_handler (DBusConnection * connection,
+				  void *user_data)
 {
 	HAL_INFO (("========================================"));
 	HAL_INFO (("runner_server_unregister_handler"));
@@ -156,27 +157,27 @@ runner_server_unregister_handler (DBusCo
 }
 
 
-static void 
-handle_connection(DBusServer *server,
-                  DBusConnection *new_connection,
-                  void *data)
+static void
+handle_connection (DBusServer * server,
+		   DBusConnection * new_connection, void *data)
 {
 
 	if (runner_connection == NULL) {
-		DBusObjectPathVTable vtable = { &runner_server_unregister_handler, 
-						&runner_server_message_handler, 
-						NULL, NULL, NULL, NULL};
-		
+		DBusObjectPathVTable vtable =
+		    { &runner_server_unregister_handler,
+			&runner_server_message_handler,
+			NULL, NULL, NULL, NULL
+		};
+
 		runner_connection = new_connection;
 		dbus_connection_ref (new_connection);
 		dbus_connection_setup_with_g_main (new_connection, NULL);
 
 		HAL_INFO (("runner connection is %p", new_connection));
 
-		dbus_connection_register_fallback (new_connection, 
+		dbus_connection_register_fallback (new_connection,
 						   "/org/freedesktop",
-						   &vtable,
-						   NULL);
+						   &vtable, NULL);
 
 		/* dbus_server_unref(server); */
 
@@ -189,7 +190,7 @@ static guint runner_watch;
 
 
 static void
-runner_died(GPid pid, gint status, gpointer data)
+runner_died (GPid pid, gint status, gpointer data)
 {
 	g_spawn_close_pid (pid);
 	DIE (("Runner died"));
@@ -202,8 +203,10 @@ hald_runner_stop_runner (void)
 		DBusMessage *msg;
 
 		/* Don't care about running processes anymore */
-		
-		HAL_INFO (("running_processes %p, num = %d", running_processes, g_slist_length (running_processes)));
+
+		HAL_INFO (("running_processes %p, num = %d",
+			   running_processes,
+			   g_slist_length (running_processes)));
 
 		g_slist_foreach (running_processes, (GFunc) g_free, NULL);
 		g_slist_free (running_processes);
@@ -214,14 +217,15 @@ hald_runner_stop_runner (void)
 		g_source_remove (runner_watch);
 		g_spawn_close_pid (runner_pid);
 
-		msg = dbus_message_new_method_call("org.freedesktop.HalRunner",
-						   "/org/freedesktop/HalRunner",
-						   "org.freedesktop.HalRunner",
-						   "Shutdown");
-		if (msg == NULL) 
-			DIE(("No memory"));
+		msg =
+		    dbus_message_new_method_call
+		    ("org.freedesktop.HalRunner",
+		     "/org/freedesktop/HalRunner",
+		     "org.freedesktop.HalRunner", "Shutdown");
+		if (msg == NULL)
+			DIE (("No memory"));
 		dbus_connection_send (runner_connection, msg, NULL);
-		dbus_message_unref(msg);
+		dbus_message_unref (msg);
 
 		dbus_server_disconnect (runner_server);
 		dbus_server_unref (runner_server);
@@ -231,448 +235,481 @@ hald_runner_stop_runner (void)
 }
 
 gboolean
-hald_runner_start_runner(void)
+hald_runner_start_runner (void)
 {
-  DBusError err;
-  GError *error = NULL;
-  char *argv[] = { NULL, NULL};
-  char *env[] =  { NULL, NULL, NULL, NULL};
-  const char *hald_runner_path;
-  char *server_address;
-
-  running_processes = NULL;
-
-  dbus_error_init(&err);
-  runner_server = dbus_server_listen(DBUS_SERVER_ADDRESS, &err);
-  if (runner_server == NULL) {
-    HAL_ERROR (("Cannot create D-BUS server for the runner"));
-    goto error;
-  }
-
-  dbus_server_setup_with_g_main(runner_server, NULL);
-  dbus_server_set_new_connection_function(runner_server, handle_connection, 
-                                          NULL, NULL);
-
-
-  argv[0] = "hald-runner";
-  server_address = dbus_server_get_address(runner_server);
-  env[0] = g_strdup_printf("HALD_RUNNER_DBUS_ADDRESS=%s",
-			   server_address);
-  dbus_free (server_address);
-  hald_runner_path = g_getenv("HALD_RUNNER_PATH");
-  if (hald_runner_path != NULL) {
-	  env[1] = g_strdup_printf ("PATH=%s:" PACKAGE_LIBEXEC_DIR ":" PACKAGE_SCRIPT_DIR ":" PACKAGE_BIN_DIR, hald_runner_path);
-  } else {
-	  env[1] = g_strdup_printf ("PATH=" PACKAGE_LIBEXEC_DIR ":" PACKAGE_SCRIPT_DIR ":" PACKAGE_BIN_DIR);
-  }
-
-  /*env[2] = "DBUS_VERBOSE=1";*/
-  
-  
-  if (!g_spawn_async(NULL, argv, env, G_SPAWN_DO_NOT_REAP_CHILD|G_SPAWN_SEARCH_PATH, 
-        NULL, NULL, &runner_pid, &error)) {
-    HAL_ERROR (("Could not spawn runner : '%s'", error->message));
-    g_error_free (error);
-    goto error;
-  }
-  g_free(env[0]);
-  g_free(env[1]);
-
-  HAL_INFO (("Runner has pid %d", runner_pid));
-
-  runner_watch = g_child_watch_add(runner_pid, runner_died, NULL);
-  while (runner_connection == NULL) {
-    /* Wait for the runner */
-    g_main_context_iteration (NULL, TRUE);
-  }
-  return TRUE;
-
-error:
-  if (runner_server != NULL)
-    dbus_server_unref(runner_server);
-  return FALSE;
+	DBusError err;
+	GError *error = NULL;
+	char *argv[] = { NULL, NULL };
+	char *env[] = { NULL, NULL, NULL, NULL };
+	const char *hald_runner_path;
+	char *server_address;
+
+	running_processes = NULL;
+
+	dbus_error_init (&err);
+	runner_server = dbus_server_listen (DBUS_SERVER_ADDRESS, &err);
+	if (runner_server == NULL) {
+		HAL_ERROR (("Cannot create D-BUS server for the runner"));
+		goto error;
+	}
+
+	dbus_server_setup_with_g_main (runner_server, NULL);
+	dbus_server_set_new_connection_function (runner_server,
+						 handle_connection, NULL,
+						 NULL);
+
+
+	argv[0] = "hald-runner";
+	server_address = dbus_server_get_address (runner_server);
+	env[0] = g_strdup_printf ("HALD_RUNNER_DBUS_ADDRESS=%s",
+				  server_address);
+	dbus_free (server_address);
+	hald_runner_path = g_getenv ("HALD_RUNNER_PATH");
+	if (hald_runner_path != NULL) {
+		env[1] =
+		    g_strdup_printf ("PATH=%s:" PACKAGE_LIBEXEC_DIR ":"
+				     PACKAGE_SCRIPT_DIR ":"
+				     PACKAGE_BIN_DIR, hald_runner_path);
+	} else {
+		env[1] =
+		    g_strdup_printf ("PATH=" PACKAGE_LIBEXEC_DIR ":"
+				     PACKAGE_SCRIPT_DIR ":"
+				     PACKAGE_BIN_DIR);
+	}
+
+	/*env[2] = "DBUS_VERBOSE=1"; */
+
+
+	if (!g_spawn_async
+	    (NULL, argv, env,
+	     G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL,
+	     &runner_pid, &error)) {
+		HAL_ERROR (("Could not spawn runner : '%s'",
+			    error->message));
+		g_error_free (error);
+		goto error;
+	}
+	g_free (env[0]);
+	g_free (env[1]);
+
+	HAL_INFO (("Runner has pid %d", runner_pid));
+
+	runner_watch = g_child_watch_add (runner_pid, runner_died, NULL);
+	while (runner_connection == NULL) {
+		/* Wait for the runner */
+		g_main_context_iteration (NULL, TRUE);
+	}
+	return TRUE;
+
+      error:
+	if (runner_server != NULL)
+		dbus_server_unref (runner_server);
+	return FALSE;
 }
 
 static void
-add_property_to_msg (HalDevice *device, 
-		     const char *key, 
-		     gpointer user_data)
-{
-  char *prop_upper, *value;
-  char *c;
-  gchar *env;
-  DBusMessageIter *iter = (DBusMessageIter *)user_data;
-  
-  prop_upper = g_ascii_strup (key, -1);
- 
-  /* periods aren't valid in the environment, so replace them with
-   * underscores. */
-  for (c = prop_upper; *c; c++) {
-    if (*c == '.')
-      *c = '_';
-  }
-
-  value = hal_device_property_to_string (device, key);
-  env = g_strdup_printf ("HAL_PROP_%s=%s", prop_upper, value);
-  dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &env);
-
-  g_free (env);
-  g_free (value);
-  g_free (prop_upper);
+add_property_to_msg (HalDevice * device,
+		     const char *key, gpointer user_data)
+{
+	char *prop_upper, *value;
+	char *c;
+	gchar *env;
+	DBusMessageIter *iter = (DBusMessageIter *) user_data;
+
+	prop_upper = g_ascii_strup (key, -1);
+
+	/* periods aren't valid in the environment, so replace them with
+	 * underscores. */
+	for (c = prop_upper; *c; c++) {
+		if (*c == '.')
+			*c = '_';
+	}
+
+	value = hal_device_property_to_string (device, key);
+	env = g_strdup_printf ("HAL_PROP_%s=%s", prop_upper, value);
+	dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &env);
+
+	g_free (env);
+	g_free (value);
+	g_free (prop_upper);
 }
 
 static void
-add_env(DBusMessageIter *iter, const gchar *key, const gchar *value) {
-  gchar *env;
-  env = g_strdup_printf ("%s=%s", key, value);
-  dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &env);
-  g_free(env);
+add_env (DBusMessageIter * iter, const gchar * key, const gchar * value)
+{
+	gchar *env;
+	env = g_strdup_printf ("%s=%s", key, value);
+	dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &env);
+	g_free (env);
 }
 
 static void
-add_basic_env(DBusMessageIter *iter, const gchar *udi) {
-  struct utsname un;
+add_basic_env (DBusMessageIter * iter, const gchar * udi)
+{
+	struct utsname un;
 
-  if (hald_is_verbose) {
-    add_env(iter, "HALD_VERBOSE", "1");
-  }
-  if (hald_is_initialising) {
-    add_env(iter, "HALD_STARTUP", "1");
-  }
-  if (hald_use_syslog) {
-    add_env(iter, "HALD_USE_SYSLOG", "1");
-  }
-  add_env(iter, "UDI", udi);
-  add_env(iter, "HALD_DIRECT_ADDR", hald_dbus_local_server_addr());
+	if (hald_is_verbose) {
+		add_env (iter, "HALD_VERBOSE", "1");
+	}
+	if (hald_is_initialising) {
+		add_env (iter, "HALD_STARTUP", "1");
+	}
+	if (hald_use_syslog) {
+		add_env (iter, "HALD_USE_SYSLOG", "1");
+	}
+	add_env (iter, "UDI", udi);
+	add_env (iter, "HALD_DIRECT_ADDR", hald_dbus_local_server_addr ());
 #ifdef HAVE_POLKIT
-  add_env(iter, "HAVE_POLKIT", "1");
+	add_env (iter, "HAVE_POLKIT", "1");
 #endif
 
-  if (uname(&un) == 0) {
-    char *sysname;
+	if (uname (&un) == 0) {
+		char *sysname;
 
-    sysname = g_ascii_strdown(un.sysname, -1);
-    add_env(iter, "HALD_UNAME_S", sysname);
-    g_free(sysname);
-  }
+		sysname = g_ascii_strdown (un.sysname, -1);
+		add_env (iter, "HALD_UNAME_S", sysname);
+		g_free (sysname);
+	}
 }
 
 static void
-add_extra_env(DBusMessageIter *iter, gchar **env) {
-  int i;
-  if (env != NULL) for (i = 0; env[i] != NULL; i++) {
-    dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &env[i]);
-  }
+add_extra_env (DBusMessageIter * iter, gchar ** env)
+{
+	int i;
+	if (env != NULL)
+		for (i = 0; env[i] != NULL; i++) {
+			dbus_message_iter_append_basic (iter,
+							DBUS_TYPE_STRING,
+							&env[i]);
+		}
 }
 
 static gboolean
-add_command(DBusMessageIter *iter, const gchar *command_line) {
-  gint argc;
-  gint x;
-  char **argv;
-  GError *err = NULL;
-  DBusMessageIter array_iter;
-
-  if (!g_shell_parse_argv(command_line, &argc, &argv, &err)) {
-    HAL_ERROR (("Error parsing commandline '%s': %s", 
-                 command_line, err->message));
-    g_error_free (err);
-    return FALSE;
-  }
-  if (!dbus_message_iter_open_container(iter, 
-                                   DBUS_TYPE_ARRAY,
-                                   DBUS_TYPE_STRING_AS_STRING,
-                                   &array_iter))
-    DIE (("No memory"));
-  for (x = 0 ; argv[x] != NULL; x++) {
-    dbus_message_iter_append_basic(&array_iter, DBUS_TYPE_STRING, &argv[x]);
-  }
-  dbus_message_iter_close_container(iter, &array_iter);
+add_command (DBusMessageIter * iter, const gchar * command_line)
+{
+	gint argc;
+	gint x;
+	char **argv;
+	GError *err = NULL;
+	DBusMessageIter array_iter;
+
+	if (!g_shell_parse_argv (command_line, &argc, &argv, &err)) {
+		HAL_ERROR (("Error parsing commandline '%s': %s",
+			    command_line, err->message));
+		g_error_free (err);
+		return FALSE;
+	}
+	if (!dbus_message_iter_open_container (iter,
+					       DBUS_TYPE_ARRAY,
+					       DBUS_TYPE_STRING_AS_STRING,
+					       &array_iter))
+		DIE (("No memory"));
+	for (x = 0; argv[x] != NULL; x++) {
+		dbus_message_iter_append_basic (&array_iter,
+						DBUS_TYPE_STRING,
+						&argv[x]);
+	}
+	dbus_message_iter_close_container (iter, &array_iter);
 
-  g_strfreev(argv);
-  return TRUE;
+	g_strfreev (argv);
+	return TRUE;
 }
 
 static gboolean
-add_first_part(DBusMessageIter *iter, HalDevice *device,
-                   const gchar *command_line, char **extra_env) {
-  DBusMessageIter array_iter;
-  const char *udi;
-
-  if (device != NULL)
-	  udi = hal_device_get_udi(device);
-  else
-	  udi = "";
-
-  dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &udi);
-
-  dbus_message_iter_open_container(iter, 
-                                   DBUS_TYPE_ARRAY,
-                                   DBUS_TYPE_STRING_AS_STRING,
-                                   &array_iter);
-  if (device != NULL)
-	  hal_device_property_foreach (device, add_property_to_msg, &array_iter);
-  add_basic_env(&array_iter, udi);
-  add_extra_env(&array_iter, extra_env);
-  dbus_message_iter_close_container(iter, &array_iter);
-
-  if (!add_command(iter, command_line)) {
-    return FALSE;
-  }
-  return TRUE;
+add_first_part (DBusMessageIter * iter, HalDevice * device,
+		const gchar * command_line, char **extra_env)
+{
+	DBusMessageIter array_iter;
+	const char *udi;
+
+	if (device != NULL)
+		udi = hal_device_get_udi (device);
+	else
+		udi = "";
+
+	dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &udi);
+
+	dbus_message_iter_open_container (iter,
+					  DBUS_TYPE_ARRAY,
+					  DBUS_TYPE_STRING_AS_STRING,
+					  &array_iter);
+	if (device != NULL)
+		hal_device_property_foreach (device, add_property_to_msg,
+					     &array_iter);
+	add_basic_env (&array_iter, udi);
+	add_extra_env (&array_iter, extra_env);
+	dbus_message_iter_close_container (iter, &array_iter);
+
+	if (!add_command (iter, command_line)) {
+		return FALSE;
+	}
+	return TRUE;
 }
 
 /* Start a helper, returns true on a successfull start */
 gboolean
-hald_runner_start (HalDevice *device, const gchar *command_line, char **extra_env, 
-		   HalRunTerminatedCB cb, gpointer data1, gpointer data2)
-{
-  DBusMessage *msg, *reply;
-  DBusError err;
-  DBusMessageIter iter;
-
-  dbus_error_init(&err);
-  msg = dbus_message_new_method_call("org.freedesktop.HalRunner",
-                                     "/org/freedesktop/HalRunner",
-                                     "org.freedesktop.HalRunner",
-                                     "Start");
-  if (msg == NULL) 
-    DIE(("No memory"));
-  dbus_message_iter_init_append(msg, &iter);
-
-  if (!add_first_part(&iter, device, command_line, extra_env)) 
-    goto error;
- 
-  /* Wait for the reply, should be almost instantanious */
-  reply = 
-    dbus_connection_send_with_reply_and_block(runner_connection, 
-                                              msg, -1, &err);
-  if (reply) {
-    gboolean ret = 
-      (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN);
-
-    if (ret) {
-	dbus_int64_t pid_from_runner;
-	if (dbus_message_get_args (reply, &err,
-				   DBUS_TYPE_INT64, &pid_from_runner,
-				   DBUS_TYPE_INVALID)) {
-		if (cb != NULL) {
-			RunningProcess *rp;
-			rp = g_new0 (RunningProcess, 1);
-			rp->pid = (GPid) pid_from_runner;
-			rp->cb = cb;
-			rp->device = device;
-			rp->data1 = data1;
-			rp->data2 = data2;
-
-			running_processes = g_slist_prepend (running_processes, rp);
-			HAL_INFO (("running_processes %p, num = %d", running_processes, g_slist_length (running_processes)));
+hald_runner_start (HalDevice * device, const gchar * command_line,
+		   char **extra_env, HalRunTerminatedCB cb, gpointer data1,
+		   gpointer data2)
+{
+	DBusMessage *msg, *reply;
+	DBusError err;
+	DBusMessageIter iter;
+
+	dbus_error_init (&err);
+	msg = dbus_message_new_method_call ("org.freedesktop.HalRunner",
+					    "/org/freedesktop/HalRunner",
+					    "org.freedesktop.HalRunner",
+					    "Start");
+	if (msg == NULL)
+		DIE (("No memory"));
+	dbus_message_iter_init_append (msg, &iter);
+
+	if (!add_first_part (&iter, device, command_line, extra_env))
+		goto error;
+
+	/* Wait for the reply, should be almost instantanious */
+	reply =
+	    dbus_connection_send_with_reply_and_block (runner_connection,
+						       msg, -1, &err);
+	if (reply) {
+		gboolean ret =
+		    (dbus_message_get_type (reply) ==
+		     DBUS_MESSAGE_TYPE_METHOD_RETURN);
+
+		if (ret) {
+			dbus_int64_t pid_from_runner;
+			if (dbus_message_get_args (reply, &err,
+						   DBUS_TYPE_INT64,
+						   &pid_from_runner,
+						   DBUS_TYPE_INVALID)) {
+				if (cb != NULL) {
+					RunningProcess *rp;
+					rp = g_new0 (RunningProcess, 1);
+					rp->pid = (GPid) pid_from_runner;
+					rp->cb = cb;
+					rp->device = device;
+					rp->data1 = data1;
+					rp->data2 = data2;
+
+					running_processes =
+					    g_slist_prepend
+					    (running_processes, rp);
+					HAL_INFO (("running_processes %p, num = %d", running_processes, g_slist_length (running_processes)));
+				}
+			} else {
+				HAL_ERROR (("Error extracting out_pid from runner's Start()"));
+			}
 		}
-	} else {
-	  HAL_ERROR (("Error extracting out_pid from runner's Start()"));
+
+		dbus_message_unref (reply);
+		dbus_message_unref (msg);
+		return ret;
 	}
-    }
 
-    dbus_message_unref(reply);
-    dbus_message_unref(msg);
-    return ret;
-  }
-
-error:
-  dbus_message_unref(msg);
-  return FALSE;
+      error:
+	dbus_message_unref (msg);
+	return FALSE;
 }
 
 static void
-call_notify(DBusPendingCall *pending, void *user_data)
+call_notify (DBusPendingCall * pending, void *user_data)
 {
-  HelperData *hb = (HelperData *)user_data;
-  dbus_uint32_t exitt = HALD_RUN_SUCCESS;
-  dbus_int32_t return_code = 0;
-  DBusMessage *m;
-  GArray *error = NULL;
-  DBusMessageIter iter;
-
-  error = g_array_new(TRUE, FALSE, sizeof(char *));
-
-  m = dbus_pending_call_steal_reply(pending);
-  if (dbus_message_get_type(m) != DBUS_MESSAGE_TYPE_METHOD_RETURN)
-    goto malformed;
-
-  if (!dbus_message_iter_init(m, &iter) ||
-       dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32) 
-    goto malformed;
-  dbus_message_iter_get_basic(&iter, &exitt);
-
-  if (!dbus_message_iter_next(&iter) || 
-        dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32) 
-    goto malformed;
-  dbus_message_iter_get_basic(&iter, &return_code);
-
-  while (dbus_message_iter_next(&iter) &&
-    dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING) {
-    const char *value;
-    dbus_message_iter_get_basic(&iter, &value);
-    g_array_append_vals(error, &value, 1);
-  }
+	HelperData *hb = (HelperData *) user_data;
+	dbus_uint32_t exitt = HALD_RUN_SUCCESS;
+	dbus_int32_t return_code = 0;
+	DBusMessage *m;
+	GArray *error = NULL;
+	DBusMessageIter iter;
+
+	error = g_array_new (TRUE, FALSE, sizeof (char *));
+
+	m = dbus_pending_call_steal_reply (pending);
+	if (dbus_message_get_type (m) != DBUS_MESSAGE_TYPE_METHOD_RETURN)
+		goto malformed;
+
+	if (!dbus_message_iter_init (m, &iter) ||
+	    dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32)
+		goto malformed;
+	dbus_message_iter_get_basic (&iter, &exitt);
+
+	if (!dbus_message_iter_next (&iter) ||
+	    dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32)
+		goto malformed;
+	dbus_message_iter_get_basic (&iter, &return_code);
+
+	while (dbus_message_iter_next (&iter) &&
+	       dbus_message_iter_get_arg_type (&iter) ==
+	       DBUS_TYPE_STRING) {
+		const char *value;
+		dbus_message_iter_get_basic (&iter, &value);
+		g_array_append_vals (error, &value, 1);
+	}
 
-  hb->cb(hb->d, exitt, return_code, 
-      (gchar **)error->data, hb->data1, hb->data2);
+	hb->cb (hb->d, exitt, return_code,
+		(gchar **) error->data, hb->data1, hb->data2);
 
-  if (hb->d != NULL)
-	  g_object_unref (hb->d);
+	if (hb->d != NULL)
+		g_object_unref (hb->d);
 
-  dbus_message_unref(m);
-  g_array_free(error, TRUE);
+	dbus_message_unref (m);
+	g_array_free (error, TRUE);
 
-  g_free (hb);
+	g_free (hb);
 
-  dbus_pending_call_unref (pending);
+	dbus_pending_call_unref (pending);
 
-  goto out;
+	goto out;
 
-malformed:
-  /* Send a Fail callback on malformed messages */
-  HAL_ERROR (("Malformed or unexpected reply message"));
-  hb->cb(hb->d, HALD_RUN_FAILED, return_code, NULL, hb->data1, hb->data2);
+      malformed:
+	/* Send a Fail callback on malformed messages */
+	HAL_ERROR (("Malformed or unexpected reply message"));
+	hb->cb (hb->d, HALD_RUN_FAILED, return_code, NULL, hb->data1,
+		hb->data2);
 
-  if (hb->d != NULL)
-	  g_object_unref (hb->d);
+	if (hb->d != NULL)
+		g_object_unref (hb->d);
 
-  dbus_message_unref(m);
-  g_array_free(error, TRUE);
+	dbus_message_unref (m);
+	g_array_free (error, TRUE);
 
-  g_free (hb);
+	g_free (hb);
 
-  dbus_pending_call_unref (pending);
+	dbus_pending_call_unref (pending);
 
-out:
-  if (method_run_notify)
-    method_run_notify (method_run_notify_userdata);
+      out:
+	if (method_run_notify)
+		method_run_notify (method_run_notify_userdata);
 }
 
 /* Run a helper program using the commandline, with input as infomation on
  * stdin */
 void
-hald_runner_run_method(HalDevice *device,
-                           const gchar *command_line, char **extra_env, 
-                           gchar *input, gboolean error_on_stderr,
-                           guint32 timeout,
-                           HalRunTerminatedCB  cb,
-                           gpointer data1, gpointer data2) {
-  DBusMessage *msg;
-  DBusMessageIter iter;
-  DBusPendingCall *call;
-  HelperData *hd = NULL;
-
-  msg = dbus_message_new_method_call("org.freedesktop.HalRunner",
-                             "/org/freedesktop/HalRunner",
-                             "org.freedesktop.HalRunner",
-                             "Run");
-  if (msg == NULL) 
-    DIE(("No memory"));
-  dbus_message_iter_init_append(msg, &iter);
-  
-  if (!add_first_part(&iter, device, command_line, extra_env)) 
-    goto error;
-
-  dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &input);
-  dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &error_on_stderr);
-  dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32, &timeout);
-
-  if (!dbus_connection_send_with_reply(runner_connection, 
-                                              msg, &call, INT_MAX))
-    DIE (("No memory"));
-
-  hd = g_new0 (HelperData, 1);
-  hd->d = device;
-  hd->cb = cb;
-  hd->data1 = data1;
-  hd->data2 = data2;
-
-  if (device != NULL)
-	  g_object_ref (device);
-
-  dbus_pending_call_set_notify(call, call_notify, hd, NULL);
-  dbus_message_unref(msg);
-  return;
-error:
-  dbus_message_unref(msg);
-  g_free(hd);
-  cb(device, HALD_RUN_FAILED, 0, NULL, data1, data2);
+hald_runner_run_method (HalDevice * device,
+			const gchar * command_line, char **extra_env,
+			gchar * input, gboolean error_on_stderr,
+			guint32 timeout,
+			HalRunTerminatedCB cb,
+			gpointer data1, gpointer data2)
+{
+	DBusMessage *msg;
+	DBusMessageIter iter;
+	DBusPendingCall *call;
+	HelperData *hd = NULL;
+
+	msg = dbus_message_new_method_call ("org.freedesktop.HalRunner",
+					    "/org/freedesktop/HalRunner",
+					    "org.freedesktop.HalRunner",
+					    "Run");
+	if (msg == NULL)
+		DIE (("No memory"));
+	dbus_message_iter_init_append (msg, &iter);
+
+	if (!add_first_part (&iter, device, command_line, extra_env))
+		goto error;
+
+	dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &input);
+	dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN,
+					&error_on_stderr);
+	dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &timeout);
+
+	if (!dbus_connection_send_with_reply (runner_connection,
+					      msg, &call, INT_MAX))
+		DIE (("No memory"));
+
+	hd = g_new0 (HelperData, 1);
+	hd->d = device;
+	hd->cb = cb;
+	hd->data1 = data1;
+	hd->data2 = data2;
+
+	if (device != NULL)
+		g_object_ref (device);
+
+	dbus_pending_call_set_notify (call, call_notify, hd, NULL);
+	dbus_message_unref (msg);
+	return;
+      error:
+	dbus_message_unref (msg);
+	g_free (hd);
+	cb (device, HALD_RUN_FAILED, 0, NULL, data1, data2);
 }
 
 void
-hald_runner_run(HalDevice *device,
-                    const gchar *command_line, char **extra_env, 
-                    guint timeout,
-                    HalRunTerminatedCB  cb,
-                    gpointer data1, gpointer data2) {
-  hald_runner_run_method(device, command_line, extra_env, 
-                             "", FALSE, timeout, cb, data1, data2);
+hald_runner_run (HalDevice * device,
+		 const gchar * command_line, char **extra_env,
+		 guint timeout,
+		 HalRunTerminatedCB cb, gpointer data1, gpointer data2)
+{
+	hald_runner_run_method (device, command_line, extra_env,
+				"", FALSE, timeout, cb, data1, data2);
 }
 
 
 
 void
-hald_runner_kill_device(HalDevice *device) {
-  DBusMessage *msg, *reply;
-  DBusError err;
-  DBusMessageIter iter;
-  const char *udi;
-
-  running_processes_remove_device (device);
-  
-  msg = dbus_message_new_method_call("org.freedesktop.HalRunner",
-                             "/org/freedesktop/HalRunner",
-                             "org.freedesktop.HalRunner",
-                             "Kill");
-  if (msg == NULL) 
-    DIE(("No memory"));
-  dbus_message_iter_init_append(msg, &iter);
-  udi = hal_device_get_udi(device);
-  dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &udi);
-
-  /* Wait for the reply, should be almost instantanious */
-  dbus_error_init(&err);
-  reply = 
-    dbus_connection_send_with_reply_and_block(runner_connection, msg, -1, &err);
-  if (reply) {
-    dbus_message_unref(reply);
-  }
+hald_runner_kill_device (HalDevice * device)
+{
+	DBusMessage *msg, *reply;
+	DBusError err;
+	DBusMessageIter iter;
+	const char *udi;
+
+	running_processes_remove_device (device);
 
-  dbus_message_unref(msg);
+	msg = dbus_message_new_method_call ("org.freedesktop.HalRunner",
+					    "/org/freedesktop/HalRunner",
+					    "org.freedesktop.HalRunner",
+					    "Kill");
+	if (msg == NULL)
+		DIE (("No memory"));
+	dbus_message_iter_init_append (msg, &iter);
+	udi = hal_device_get_udi (device);
+	dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &udi);
+
+	/* Wait for the reply, should be almost instantanious */
+	dbus_error_init (&err);
+	reply =
+	    dbus_connection_send_with_reply_and_block (runner_connection,
+						       msg, -1, &err);
+	if (reply) {
+		dbus_message_unref (reply);
+	}
+
+	dbus_message_unref (msg);
 }
 
 void
-hald_runner_kill_all(HalDevice *device) {
-  DBusMessage *msg, *reply;
-  DBusError err;
-
-  running_processes_remove_device (device);
-
-  msg = dbus_message_new_method_call("org.freedesktop.HalRunner",
-                             "/org/freedesktop/HalRunner",
-                             "org.freedesktop.HalRunner",
-                             "KillAll");
-  if (msg == NULL) 
-    DIE(("No memory"));
-
-  /* Wait for the reply, should be almost instantanious */
-  dbus_error_init(&err);
-  reply = 
-    dbus_connection_send_with_reply_and_block(runner_connection,
-                                              msg, -1, &err);
-  if (reply) {
-    dbus_message_unref(reply);
-  }
+hald_runner_kill_all (HalDevice * device)
+{
+	DBusMessage *msg, *reply;
+	DBusError err;
+
+	running_processes_remove_device (device);
+
+	msg = dbus_message_new_method_call ("org.freedesktop.HalRunner",
+					    "/org/freedesktop/HalRunner",
+					    "org.freedesktop.HalRunner",
+					    "KillAll");
+	if (msg == NULL)
+		DIE (("No memory"));
+
+	/* Wait for the reply, should be almost instantanious */
+	dbus_error_init (&err);
+	reply =
+	    dbus_connection_send_with_reply_and_block (runner_connection,
+						       msg, -1, &err);
+	if (reply) {
+		dbus_message_unref (reply);
+	}
 
-  dbus_message_unref(msg);
+	dbus_message_unref (msg);
 }
 
 void
-hald_runner_set_method_run_notify (HaldRunnerRunNotify cb, gpointer user_data)
+hald_runner_set_method_run_notify (HaldRunnerRunNotify cb,
+				   gpointer user_data)
 {
-  method_run_notify = cb;
-  method_run_notify_userdata = user_data;
+	method_run_notify = cb;
+	method_run_notify_userdata = user_data;
 }
diff-tree a366164c0c0cb153b0fcbd6e8810965f5da16532 (from 6124fb56eb8a96750c18a2986f952de0d0f9c179)
Author: Guillem Jover <guillem.jover at nokia.com>
Date:   Thu Feb 15 14:26:16 2007 -0500

    rename nokia770 to omap
    
    The Nokia 770 code is OMAP generic, so others may benefit, also it
    should only be available on ARM. Switched the --with-omap to be
    auto (from no), but only enabled automatically on ARM.

diff --git a/configure.in b/configure.in
index 231114f..053d738 100644
--- a/configure.in
+++ b/configure.in
@@ -646,12 +646,28 @@ elif test "x$with_macbookpro" = "x" ; th
 fi
 AM_CONDITIONAL(BUILD_MACBOOKPRO, test x$BUILD_MACBOOKPRO = xyes)
 
-AC_ARG_WITH(nokia770,     [  --with-nokia770         Whether to build Nokia 770 utils (no)])
-BUILD_N770=no
-if test "x$with_nokia770" = "xyes"; then
-    BUILD_N770=yes
+AC_ARG_WITH([omap],
+	    [AS_HELP_STRING([--with-omap],
+			    [Whether to build OMAP utils (auto)])])
+BUILD_OMAP=no
+if test "x$with_omap" = "xyes" ; then
+    BUILD_OMAP=yes
+elif test "x$with_omap" = "x" ; then
+    case "${HALD_BACKEND}" in
+    linux)
+	case "${host}" in
+	arm*-*-*)
+	    BUILD_OMAP=yes
+	    ;;
+	*)
+	    ;;
+	esac
+	;;
+    *)
+	;;
+    esac
 fi
-AM_CONDITIONAL(BUILD_N770, test x$BUILD_N770 = xyes)
+AM_CONDITIONAL(BUILD_OMAP, [test x$BUILD_OMAP = xyes])
 
 dnl cpufreq
 AC_ARG_WITH(cpufreq,        [  --with-cpufreq          Whether to build cpufreq utils (auto)])
@@ -802,6 +818,7 @@ echo "
         use APM:                    ${msg_apm}
 
         Macbook Pro utils:          ${BUILD_MACBOOKPRO} (Linux only, x86 only, requires libpci)
+        OMAP utils:                 ${BUILD_OMAP} (Linux only, arm only)
         CPU frequency scaling:      ${BUILD_CPUFREQ} (Linux only)
 	USB wireless mouse power:   ${BUILD_USBCSR} (Linux only, requires libusb)
 	Dell Backlight              ${BUILD_DELL} (Linux only, requires libsmbios >= 0.11.6)
diff --git a/fdi/policy/10osvendor/10-nokia770-backlight.fdi b/fdi/policy/10osvendor/10-nokia770-backlight.fdi
deleted file mode 100644
index ca1c19c..0000000
--- a/fdi/policy/10osvendor/10-nokia770-backlight.fdi
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-
-<deviceinfo version="0.2">
-  <device>
-    <match key="platform.id" string="omapfb">
-     <spawn udi="/org/freedesktop/Hal/devices/omapfb_bl"/>
-    </match>
-   </device>
-   <device>
-    <match key="info.udi" string="/org/freedesktop/Hal/devices/omapfb_bl">
-        <merge key="info.product" type="string">Nokia 770 LCD controller and panel</merge>
-        <append key="info.capabilities" type="strlist">laptop_panel</append>
-        <merge key="laptop_panel.access_method" type="string">custom</merge>
-        <merge key="laptop_panel.num_levels" type="int">15</merge>
-        <append key="info.addons" type="strlist">hald-addon-nokia770-backlight</append>
-    </match>
-  </device>
-</deviceinfo>
diff --git a/fdi/policy/10osvendor/10-omap-backlight.fdi b/fdi/policy/10osvendor/10-omap-backlight.fdi
new file mode 100644
index 0000000..5d3f1ce
--- /dev/null
+++ b/fdi/policy/10osvendor/10-omap-backlight.fdi
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+
+<deviceinfo version="0.2">
+  <device>
+    <match key="platform.id" string="omapfb">
+     <spawn udi="/org/freedesktop/Hal/devices/omapfb_bl"/>
+    </match>
+   </device>
+   <device>
+    <match key="info.udi" string="/org/freedesktop/Hal/devices/omapfb_bl">
+        <merge key="info.product" type="string">OMAP LCD controller and panel</merge>
+        <append key="info.capabilities" type="strlist">laptop_panel</append>
+        <merge key="laptop_panel.access_method" type="string">custom</merge>
+        <merge key="laptop_panel.num_levels" type="int">15</merge>
+        <append key="info.addons" type="strlist">hald-addon-omap-backlight</append>
+    </match>
+  </device>
+</deviceinfo>
diff --git a/fdi/policy/10osvendor/Makefile.am b/fdi/policy/10osvendor/Makefile.am
index aed14e1..e2e1d8a 100644
--- a/fdi/policy/10osvendor/Makefile.am
+++ b/fdi/policy/10osvendor/Makefile.am
@@ -21,8 +21,8 @@ if BUILD_USBCSR
 dist_fdi_DATA += 10-usbcsr-mice.fdi
 endif
 
-if BUILD_N770
-dist_fdi_DATA += 10-nokia770-backlight.fdi
+if BUILD_OMAP
+dist_fdi_DATA += 10-omap-backlight.fdi
 endif
 
 if BUILD_DELL
diff --git a/hald/linux/addons/Makefile.am b/hald/linux/addons/Makefile.am
index 32bfb4d..597aee8 100644
--- a/hald/linux/addons/Makefile.am
+++ b/hald/linux/addons/Makefile.am
@@ -25,9 +25,11 @@ libexec_PROGRAMS  += 			\
 	hald-addon-acpi-buttons-toshiba
 endif
 
-if BUILD_N770
+if BUILD_OMAP
 libexec_PROGRAMS  +=			\
-	hald-addon-nokia770-backlight
+	hald-addon-omap-backlight
+hald_addon_omap_backlight_SOURCES = addon-omap-backlight.c ../../logger.c ../../util_helper.c
+hald_addon_omap_backlight_LDADD = $(top_builddir)/libhal/libhal.la @GLIB_LIBS@
 endif
 
 if BUILD_MACBOOKPRO
@@ -73,8 +75,3 @@ hald_addon_pmu_LDADD = $(top_builddir)/l
 
 hald_addon_storage_SOURCES = addon-storage.c ../../logger.c ../../util_helper.c
 hald_addon_storage_LDADD = $(top_builddir)/libhal/libhal.la
-
-if BUILD_N770
-hald_addon_nokia770_backlight_SOURCES = addon-nokia770-backlight.c ../../logger.c ../../util_helper.c
-hald_addon_nokia770_backlight_LDADD = $(top_builddir)/libhal/libhal.la @GLIB_LIBS@
-endif
diff --git a/hald/linux/addons/addon-nokia770-backlight.c b/hald/linux/addons/addon-nokia770-backlight.c
deleted file mode 100644
index b9cefe1..0000000
--- a/hald/linux/addons/addon-nokia770-backlight.c
+++ /dev/null
@@ -1,271 +0,0 @@
-/***************************************************************************
- * CVSID: $Id$
- *
- * addon-nokia770-backlight.c : daemon, handling Nokia 770
- * non-standard backlight. Based on macbookpro addon by
- * David Zeuthen and Nicolas Boichat
- *
- * Copyright (C) 2006 Sergey Lapin <slapinid at gmail.com>
- *
- * Licensed under the Academic Free License version 2.1
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- **************************************************************************/
-
-#include <config.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/io.h>
-#include <sys/mman.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h> 
-
-#include <glib/gmain.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
-
-#include "libhal/libhal.h"
-#include "../../logger.h"
-#include "../../util_helper.h"
-
-
-static GMainLoop *main_loop;
-static LibHalContext *halctx = NULL;
-static char * udi;
-static DBusConnection *conn;
-
-#define NUM_BUF_LEN 11
-
-static char buffer[NUM_BUF_LEN];
-
-struct backlight
-{
-    void (*set_backlight_level)(struct backlight * bl, int i);
-    int (*get_backlight_level)(struct backlight * bl);
-    void (*backlight_init)(struct backlight * bl);
-    int bl_min;
-    int bl_max;
-};
-
-struct backlight bl_data;
-
-/* Reads backligh level */
-static int read_backlight(struct backlight * bl)
-{
- int fd;
-
- fd = open("/sys/devices/platform/omapfb/panel/backlight_level", O_RDONLY);
- if(fd <0 || read(fd, buffer, NUM_BUF_LEN) < 0)
-    return -1;
-
- return atoi(buffer);
-}
-
-/* Read maximum bl level */
-/* TODO: set actual maximum level in property.
-   No we have fixed value in FDI file, but it
-   is better to set it in addon code.
-*/
-static void backlight_init(struct backlight * bl)
-{
-    int fd;
-
-    /* Reading maximum backlight level */
-    fd = open("/sys/devices/platform/omapfb/panel/backlight_max", O_RDONLY);
-
-    if(fd <0 || read(fd, buffer, NUM_BUF_LEN - 1) < 0)
-	return;
-
-    bl->bl_max = atoi(buffer);
-    close(fd);
-}
-
-/* Setting backlight level */
-static void write_backlight(struct backlight * bl, int level)
-{
-    int fd, l;
-
-    /* sanity-checking level we're required to set */
-    if(level > bl->bl_max)
-	level = bl->bl_max;
-
-    if(level < bl->bl_min)
-	level = bl->bl_min;
-
-    fd = open("/sys/devices/platform/omapfb/panel/backlight_level", O_WRONLY);
-    l = snprintf(buffer, NUM_BUF_LEN - 1, "%d", level);
-
-    if(l >= (NUM_BUF_LEN - 1)) {
-	close(fd);
-	return;
-    }
-
-    write(fd, buffer, l);
-    close(fd);
-}
-
-/* DBus filter function */
-static DBusHandlerResult
-filter_function (DBusConnection *connection, DBusMessage *message, void *userdata)
-{
-	DBusError err;
-	DBusMessage *reply;
-
-#ifdef DEBUG_N770_BL
-	dbg ("filter_function: sender=%s destination=%s obj_path=%s interface=%s method=%s", 
-	     dbus_message_get_sender (message), 
-	     dbus_message_get_destination (message), 
-	     dbus_message_get_path (message), 
-	     dbus_message_get_interface (message),
-	     dbus_message_get_member (message));
-#endif
-	reply = NULL;
-
-	if (dbus_message_is_method_call (message, 
-					 "org.freedesktop.Hal.Device.LaptopPanel", 
-					 "SetBrightness")) {
-		int brightness;
-
-		dbus_error_init (&err);
-		if (dbus_message_get_args (message, 
-					   &err,
-					   DBUS_TYPE_INT32, &brightness,
-					   DBUS_TYPE_INVALID)) {
-			if (brightness < 0 || brightness > 228) {
-				reply = dbus_message_new_error (message,
-								"org.freedesktop.Hal.Device.LaptopPanel.Invalid",
-								"Brightness has to be between 0 and 228!");
-
-			} else {
-				int return_code;
-
-				bl_data.set_backlight_level (&bl_data, brightness);
-
-				reply = dbus_message_new_method_return (message);
-				if (reply == NULL)
-					goto error;
-
-				return_code = 0;
-				dbus_message_append_args (reply,
-							  DBUS_TYPE_INT32, &return_code,
-							  DBUS_TYPE_INVALID);
-			}
-
-			dbus_connection_send (connection, reply, NULL);
-		}
-		
-	} else if (dbus_message_is_method_call (message, 
-						"org.freedesktop.Hal.Device.LaptopPanel", 
-						"GetBrightness")) {
-		int brightness;
-
-		dbus_error_init (&err);
-		if (dbus_message_get_args (message, 
-					   &err,
-					   DBUS_TYPE_INVALID)) {
-
-			brightness = bl_data.get_backlight_level (&bl_data);
-			if (brightness < bl_data.bl_min)
-				brightness = bl_data.bl_min;
-			if (brightness > bl_data.bl_max)
-				brightness = bl_data.bl_max;
-
-			/* dbg ("getting brightness, it's %d", brightness); */
-
-			reply = dbus_message_new_method_return (message);
-			if (reply == NULL)
-				goto error;
-
-			dbus_message_append_args (reply,
-						  DBUS_TYPE_INT32, &brightness,
-						  DBUS_TYPE_INVALID);
-			dbus_connection_send (connection, reply, NULL);
-		}
-		
-	}
-	
-error:
-	if (reply != NULL)
-		dbus_message_unref (reply);
-
-	return DBUS_HANDLER_RESULT_HANDLED;
-}
-
-/* Setting-up backlight structure */
-static void setup_cb(void)
-{
- memset(&bl_data, 0, sizeof(struct backlight));
- bl_data.backlight_init = backlight_init;
- bl_data.get_backlight_level = read_backlight;
- bl_data.set_backlight_level = write_backlight;
-}
-
-int
-main (int argc, char *argv[])
-{
-	DBusError err;
-
-	setup_logger ();
-	setup_cb();
-	udi = getenv ("UDI");
-
-	HAL_DEBUG (("udi=%s", udi));
-	if (udi == NULL) {
-		HAL_ERROR (("No device specified"));
-		return -2;
-	}
-
-	dbus_error_init (&err);
-	if ((halctx = libhal_ctx_init_direct (&err)) == NULL) {
-		HAL_ERROR (("Cannot connect to hald"));
-		return -3;
-	}
-
-
-
-	conn = libhal_ctx_get_dbus_connection (halctx);
-	dbus_connection_setup_with_g_main (conn, NULL);
-
-	dbus_connection_add_filter (conn, filter_function, NULL, NULL);
-
-	if (!libhal_device_claim_interface (halctx, 
-					    "/org/freedesktop/Hal/devices/omapfb_bl", 
-					    "org.freedesktop.Hal.Device.LaptopPanel", 
-					    "    <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.LaptopPanel'"));
-		return -4;
-	}
-	dbus_error_init (&err);
-	if (!libhal_device_addon_is_ready (halctx, udi, &err)) {
-		return -4;
-	}
-	bl_data.backlight_init(&bl_data);
-	main_loop = g_main_loop_new (NULL, FALSE);
-	g_main_loop_run (main_loop);
-	return 0;
-}
diff --git a/hald/linux/addons/addon-omap-backlight.c b/hald/linux/addons/addon-omap-backlight.c
new file mode 100644
index 0000000..f7a443d
--- /dev/null
+++ b/hald/linux/addons/addon-omap-backlight.c
@@ -0,0 +1,271 @@
+/***************************************************************************
+ * CVSID: $Id$
+ *
+ * addon-omap-backlight.c : daemon, handling OMAP
+ * non-standard backlight. Based on macbookpro addon by
+ * David Zeuthen and Nicolas Boichat
+ *
+ * Copyright (C) 2006 Sergey Lapin <slapinid at gmail.com>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ **************************************************************************/
+
+#include <config.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/io.h>
+#include <sys/mman.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h> 
+
+#include <glib/gmain.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "libhal/libhal.h"
+#include "../../logger.h"
+#include "../../util_helper.h"
+
+
+static GMainLoop *main_loop;
+static LibHalContext *halctx = NULL;
+static char * udi;
+static DBusConnection *conn;
+
+#define NUM_BUF_LEN 11
+
+static char buffer[NUM_BUF_LEN];
+
+struct backlight
+{
+    void (*set_backlight_level)(struct backlight * bl, int i);
+    int (*get_backlight_level)(struct backlight * bl);
+    void (*backlight_init)(struct backlight * bl);
+    int bl_min;
+    int bl_max;
+};
+
+struct backlight bl_data;
+
+/* Reads backligh level */
+static int read_backlight(struct backlight * bl)
+{
+ int fd;
+
+ fd = open("/sys/devices/platform/omapfb/panel/backlight_level", O_RDONLY);
+ if(fd <0 || read(fd, buffer, NUM_BUF_LEN) < 0)
+    return -1;
+
+ return atoi(buffer);
+}
+
+/* Read maximum bl level */
+/* TODO: set actual maximum level in property.
+   No we have fixed value in FDI file, but it
+   is better to set it in addon code.
+*/
+static void backlight_init(struct backlight * bl)
+{
+    int fd;
+
+    /* Reading maximum backlight level */
+    fd = open("/sys/devices/platform/omapfb/panel/backlight_max", O_RDONLY);
+
+    if(fd <0 || read(fd, buffer, NUM_BUF_LEN - 1) < 0)
+	return;
+
+    bl->bl_max = atoi(buffer);
+    close(fd);
+}
+
+/* Setting backlight level */
+static void write_backlight(struct backlight * bl, int level)
+{
+    int fd, l;
+
+    /* sanity-checking level we're required to set */
+    if(level > bl->bl_max)
+	level = bl->bl_max;
+
+    if(level < bl->bl_min)
+	level = bl->bl_min;
+
+    fd = open("/sys/devices/platform/omapfb/panel/backlight_level", O_WRONLY);
+    l = snprintf(buffer, NUM_BUF_LEN - 1, "%d", level);
+
+    if(l >= (NUM_BUF_LEN - 1)) {
+	close(fd);
+	return;
+    }
+
+    write(fd, buffer, l);
+    close(fd);
+}
+
+/* DBus filter function */
+static DBusHandlerResult
+filter_function (DBusConnection *connection, DBusMessage *message, void *userdata)
+{
+	DBusError err;
+	DBusMessage *reply;
+
+#ifdef DEBUG_OMAP_BL
+	dbg ("filter_function: sender=%s destination=%s obj_path=%s interface=%s method=%s", 
+	     dbus_message_get_sender (message), 
+	     dbus_message_get_destination (message), 
+	     dbus_message_get_path (message), 
+	     dbus_message_get_interface (message),
+	     dbus_message_get_member (message));
+#endif
+	reply = NULL;
+
+	if (dbus_message_is_method_call (message, 
+					 "org.freedesktop.Hal.Device.LaptopPanel", 
+					 "SetBrightness")) {
+		int brightness;
+
+		dbus_error_init (&err);
+		if (dbus_message_get_args (message, 
+					   &err,
+					   DBUS_TYPE_INT32, &brightness,
+					   DBUS_TYPE_INVALID)) {
+			if (brightness < 0 || brightness > 228) {
+				reply = dbus_message_new_error (message,
+								"org.freedesktop.Hal.Device.LaptopPanel.Invalid",
+								"Brightness has to be between 0 and 228!");
+
+			} else {
+				int return_code;
+
+				bl_data.set_backlight_level (&bl_data, brightness);
+
+				reply = dbus_message_new_method_return (message);
+				if (reply == NULL)
+					goto error;
+
+				return_code = 0;
+				dbus_message_append_args (reply,
+							  DBUS_TYPE_INT32, &return_code,
+							  DBUS_TYPE_INVALID);
+			}
+
+			dbus_connection_send (connection, reply, NULL);
+		}
+		
+	} else if (dbus_message_is_method_call (message, 
+						"org.freedesktop.Hal.Device.LaptopPanel", 
+						"GetBrightness")) {
+		int brightness;
+
+		dbus_error_init (&err);
+		if (dbus_message_get_args (message, 
+					   &err,
+					   DBUS_TYPE_INVALID)) {
+
+			brightness = bl_data.get_backlight_level (&bl_data);
+			if (brightness < bl_data.bl_min)
+				brightness = bl_data.bl_min;
+			if (brightness > bl_data.bl_max)
+				brightness = bl_data.bl_max;
+
+			/* dbg ("getting brightness, it's %d", brightness); */
+
+			reply = dbus_message_new_method_return (message);
+			if (reply == NULL)
+				goto error;
+
+			dbus_message_append_args (reply,
+						  DBUS_TYPE_INT32, &brightness,
+						  DBUS_TYPE_INVALID);
+			dbus_connection_send (connection, reply, NULL);
+		}
+		
+	}
+	
+error:
+	if (reply != NULL)
+		dbus_message_unref (reply);
+
+	return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+/* Setting-up backlight structure */
+static void setup_cb(void)
+{
+ memset(&bl_data, 0, sizeof(struct backlight));
+ bl_data.backlight_init = backlight_init;
+ bl_data.get_backlight_level = read_backlight;
+ bl_data.set_backlight_level = write_backlight;
+}
+
+int
+main (int argc, char *argv[])
+{
+	DBusError err;
+
+	setup_logger ();
+	setup_cb();
+	udi = getenv ("UDI");
+
+	HAL_DEBUG (("udi=%s", udi));
+	if (udi == NULL) {
+		HAL_ERROR (("No device specified"));
+		return -2;
+	}
+
+	dbus_error_init (&err);
+	if ((halctx = libhal_ctx_init_direct (&err)) == NULL) {
+		HAL_ERROR (("Cannot connect to hald"));
+		return -3;
+	}
+
+
+
+	conn = libhal_ctx_get_dbus_connection (halctx);
+	dbus_connection_setup_with_g_main (conn, NULL);
+
+	dbus_connection_add_filter (conn, filter_function, NULL, NULL);
+
+	if (!libhal_device_claim_interface (halctx, 
+					    "/org/freedesktop/Hal/devices/omapfb_bl", 
+					    "org.freedesktop.Hal.Device.LaptopPanel", 
+					    "    <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.LaptopPanel'"));
+		return -4;
+	}
+	dbus_error_init (&err);
+	if (!libhal_device_addon_is_ready (halctx, udi, &err)) {
+		return -4;
+	}
+	bl_data.backlight_init(&bl_data);
+	main_loop = g_main_loop_new (NULL, FALSE);
+	g_main_loop_run (main_loop);
+	return 0;
+}
diff-tree 6124fb56eb8a96750c18a2986f952de0d0f9c179 (from 24b151cd176dc8b2e53209be24bb64c647e65179)
Author: Guillem Jover <guillem.jover at nokia.com>
Date:   Thu Feb 15 14:19:08 2007 -0500

    respect --disable-pmu for hal-system-power-pmu
    
    Currently hal-system-power-pmu is built and installed even when
    '--disable-pmu' is used.

diff --git a/tools/Makefile.am b/tools/Makefile.am
index 037b4aa..96844ce 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -55,8 +55,12 @@ libexec_PROGRAMS =                      
 	hal-storage-eject	            \
 	hal-storage-closetray	            \
 	hal-storage-cleanup-mountpoint      \
-	hal-storage-cleanup-all-mountpoints \
+	hal-storage-cleanup-all-mountpoints
+
+if HAVE_PMU
+libexec_PROGRAMS +=			    \
 	hal-system-power-pmu
+endif
 
 if HAVE_ACLMGMT
 libexec_PROGRAMS += hal-acl-add hal-acl-remove
@@ -85,8 +89,10 @@ hal_storage_cleanup_mountpoint_LDADD = @
 hal_storage_cleanup_all_mountpoints_SOURCES = hal-storage-cleanup-all-mountpoints.c hal-storage-shared.c hal-storage-shared.h
 hal_storage_cleanup_all_mountpoints_LDADD = @GLIB_LIBS@ @POLKIT_LIBS@ @DBUS_LIBS@ $(top_builddir)/libhal/libhal.la $(top_builddir)/libhal-storage/libhal-storage.la
 
+if HAVE_PMU
 hal_system_power_pmu_SOURCES = hal-system-power-pmu.c
 hal_system_power_pmu_LDADD = @DBUS_LIBS@ $(top_builddir)/libhal/libhal.la
+endif
 
 scriptdir = $(libdir)/hal/scripts
 
diff-tree 24b151cd176dc8b2e53209be24bb64c647e65179 (from parents)
Merge: 7368286927bad8b996a53c3b4985df17c2068bcb 64fc3f3974074ca3424ede4ca82d993d4bb8ad46
Author: David Zeuthen <davidz at redhat.com>
Date:   Thu Feb 15 13:53:17 2007 -0500

    Merge branch 'master' of ssh://david@git.freedesktop.org/git/hal

diff-tree 7368286927bad8b996a53c3b4985df17c2068bcb (from b26ba073131b944b9ad3760ecc7b60834ee585a0)
Author: David Zeuthen <davidz at redhat.com>
Date:   Thu Feb 15 13:52:56 2007 -0500

    make HAL track ConsoleKit seats and sessions and initial work on ACL mgmt
    
    This is just preliminary work; no ACL's are added nor removed just yet.

diff --git a/configure.in b/configure.in
index 5411b18..73bb40b 100644
--- a/configure.in
+++ b/configure.in
@@ -392,6 +392,16 @@ if test "x$enable_console_kit" != "xno";
    msg_conkit=yes
 fi
 
+# check for ACL handling
+AM_CONDITIONAL(HAVE_ACLMGMT, false)
+AC_ARG_ENABLE(acl-management, [  --enable-acl-management ACL management],enable_acl_management=$enableval,enable_acl_management=no)
+msg_aclmgmt=no
+if test "x$enable_acl_management" != "xno"; then
+   AM_CONDITIONAL(HAVE_ACLMGMT, true)
+   AC_DEFINE(HAVE_ACLMGMT, [], [Set if we manage ACL's])
+   msg_aclmgmt=yes
+fi
+
 # what extra hotplug backends to use (ACPI, APM, PMU etc)
 AC_ARG_ENABLE(have_acpi, [  --disable-acpi          Build without ACPI support])
 msg_acpi=no
@@ -783,6 +793,7 @@ echo "
         use libparted:              ${USE_PARTED}
         use PolicyKit:              ${msg_polkit}
         use ConsoleKit:             ${msg_conkit}
+        use ACL management:         ${msg_aclmgmt}
         use ACPI:                   ${msg_acpi}
         use PMU:                    ${msg_pmu}
         use APM:                    ${msg_apm}
diff --git a/fdi/policy/10osvendor/20-acl-management.fdi b/fdi/policy/10osvendor/20-acl-management.fdi
new file mode 100644
index 0000000..23fbe08
--- /dev/null
+++ b/fdi/policy/10osvendor/20-acl-management.fdi
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deviceinfo version="0.2">
+  <device>
+
+    <!-- allow local sessions to access ALSA device files -->
+    <match key="info.capabilities" contains="alsa">
+      <merge key="acl.is_managed" type="bool">true</merge>
+      <merge key="acl.grant_local_session" type="bool">true</merge>
+      <merge key="acl.file" type="copy_property">alsa.device_file</merge>
+    </match>
+
+    <!-- allow local sessions to access OSS device files -->
+    <match key="info.capabilities" contains="oss">
+      <merge key="acl.is_managed" type="bool">true</merge>
+      <merge key="acl.grant_local_session" type="bool">true</merge>
+      <merge key="acl.file" type="copy_property">oss.device_file</merge>
+    </match>
+
+    <!-- TODO: add more rules for adding/removing ACL's (e.g. webcam, cd drive etc.) -->
+
+    <!-- remove all previously added ACL's on start-up -->
+    <match key="info.udi" string="/org/freedesktop/Hal/devices/computer">
+      <append key="info.callouts.add" type="strlist">hal-acl-remove --remove-all</append>
+    </match>
+
+    <!-- add and remove ACL's when devices are added and removed -->
+    <match key="acl.is_managed" bool="true">
+      <append key="info.callouts.add" type="strlist">hal-acl-add</append>
+      <append key="info.callouts.remove" type="strlist">hal-acl-remove</append>
+    </match>
+
+  </device>
+</deviceinfo>
diff --git a/fdi/policy/10osvendor/Makefile.am b/fdi/policy/10osvendor/Makefile.am
index 734eead..aed14e1 100644
--- a/fdi/policy/10osvendor/Makefile.am
+++ b/fdi/policy/10osvendor/Makefile.am
@@ -29,6 +29,10 @@ if BUILD_DELL
 dist_fdi_DATA += 10-dell-laptop-brightness.fdi
 endif
 
+if HAVE_ACLMGMT
+dist_fdi_DATA += 20-acl-management.fdi
+endif
+
 check:
 	for f in $(dist_fdi_DATA); do \
             echo -n "Validate XML in $$f : "; \
diff --git a/hald/Makefile.am b/hald/Makefile.am
index 589832f..3949a79 100644
--- a/hald/Makefile.am
+++ b/hald/Makefile.am
@@ -62,6 +62,9 @@ hald_SOURCES =                          
 	rule.h				mmap_cache.c			\
 	mmap_cache.h
 
+if HAVE_CONKIT
+hald_SOURCES += ck-tracker.h ck-tracker.c
+endif
 
 
 hald_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ -lm @HALD_OS_LIBS@ $(top_builddir)/hald/$(HALD_BACKEND)/libhald_$(HALD_BACKEND).la
diff --git a/hald/ck-tracker.c b/hald/ck-tracker.c
new file mode 100644
index 0000000..fb8417f
--- /dev/null
+++ b/hald/ck-tracker.c
@@ -0,0 +1,637 @@
+/***************************************************************************
+ * CVSID: $Id$
+ *
+ * ck-tracker.c : Track seats and sessions via ConsoleKit
+ *
+ * Copyright (C) 2007 David Zeuthen, <david at fubar.dk>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <sys/time.h>
+
+#include <dbus/dbus.h>
+#include <glib.h>
+
+#include "logger.h"
+#include "ck-tracker.h"
+
+struct CKSeat_s {
+	int refcount;
+	char *seat_objpath;           /* obj path of ConsoleKit seat */
+	gboolean is_local;            /* whether the seat is local */
+	GSList *sessions;             /* list of sessions on this seat */
+};
+
+struct CKSession_s {
+	int refcount;
+	char *session_objpath;        /* obj path of ConsoleKit session */
+	CKSeat *seat;                 /* seat that session belongs to */
+	gboolean is_active;           /* whether the session is active */
+	uid_t user;                   /* user id of the user the session belongs to */
+};
+
+struct CKTracker_s {
+	int refcount;
+	DBusConnection *dbus_connection;
+	void *user_data;
+	CKSessionAddedCB session_added_cb;
+	CKSessionRemovedCB session_removed_cb;
+	CKSessionActiveChangedCB session_active_changed_cb;
+	GSList *seats;
+	GSList *sessions;
+};
+
+static CKSession *
+ck_session_new (const char *session_objpath)
+{
+	CKSession *session;
+	session = g_new0 (CKSession, 1);
+	session->refcount = 1;
+	session->session_objpath = g_strdup (session_objpath);
+	session->seat = NULL;
+	return session;
+}
+
+static void 
+ck_session_unref (CKSession *session)
+{
+	session->refcount--;
+	if (session->refcount == 0) {
+		g_free (session->session_objpath);
+		g_free (session);
+	}
+}
+
+static void 
+ck_session_ref (CKSession *session)
+{
+	session->refcount++;
+}
+
+static CKSeat *
+ck_seat_new (const char *seat_objpath)
+{
+	CKSeat *seat;
+	seat = g_new0 (CKSeat, 1);
+	seat->refcount = 1;
+	seat->seat_objpath = g_strdup (seat_objpath);
+	seat->sessions = NULL;
+	return seat;
+}
+
+static void
+ck_seat_attach_session (CKSeat *seat, CKSession *session)
+{
+	ck_session_ref (session);
+	session->seat = seat;
+	seat->sessions = g_slist_append (seat->sessions, session);
+}
+
+static void
+ck_seat_detach_session (CKSeat *seat, CKSession *session)
+{
+	seat->sessions = g_slist_remove (seat->sessions, session);
+	session->seat = NULL;
+	ck_session_unref (session);
+}
+
+static void 
+ck_seat_unref (CKSeat *seat)
+{
+	seat->refcount--;
+	if (seat->refcount == 0) {
+		GSList *i;
+
+		/* effictively detach all sessions without manually removing each element */
+		for (i = seat->sessions; i != NULL; i = g_slist_next (i)) {
+			CKSession *session = (CKSession *) i->data;
+			session->seat = NULL;
+			ck_session_unref (session);
+		}
+		g_slist_free (seat->sessions);
+
+		g_free (seat->seat_objpath);	
+		g_free (seat);
+	}
+}
+
+#if 0
+static void 
+ck_seat_ref (CKSeat *seat)
+{
+	seat->refcount++;
+}
+#endif
+
+static gboolean
+ck_seat_get_info (CKTracker *tracker, CKSeat *seat)
+{
+	/* TODO: replace with a D-Bus call to IsLocal() when that appears on ConsoleKit */
+	seat->is_local = TRUE;
+	return TRUE;
+}
+
+static gboolean
+ck_session_get_info (CKTracker *tracker, CKSession *session)
+{
+	gboolean ret;
+	DBusError error;
+	DBusMessage *message;
+	DBusMessage *reply;
+
+	ret = FALSE;
+
+	message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", 
+						session->session_objpath,
+						"org.freedesktop.ConsoleKit.Session",
+						"IsActive");
+	dbus_error_init (&error);
+	reply = dbus_connection_send_with_reply_and_block (tracker->dbus_connection, message, -1, &error);
+	if (reply == NULL || dbus_error_is_set (&error)) {
+		HAL_ERROR (("Error doing Session.IsActive on ConsoleKit: %s: %s", error.name, error.message));
+		dbus_message_unref (message);
+		if (reply != NULL)
+			dbus_message_unref (reply);
+		goto error;
+	}
+	if (!dbus_message_get_args (reply, NULL,
+				    DBUS_TYPE_BOOLEAN, &(session->is_active),
+				    DBUS_TYPE_INVALID)) {
+		HAL_ERROR (("Invalid IsActive reply from CK"));
+		goto error;
+	}
+	dbus_message_unref (message);
+	dbus_message_unref (reply);
+
+	message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", 
+						session->session_objpath,
+						"org.freedesktop.ConsoleKit.Session",
+						"GetUser");
+	dbus_error_init (&error);
+	reply = dbus_connection_send_with_reply_and_block (tracker->dbus_connection, message, -1, &error);
+	if (reply == NULL || dbus_error_is_set (&error)) {
+		HAL_ERROR (("Error doing Session.GetUser on ConsoleKit: %s: %s", error.name, error.message));
+		dbus_message_unref (message);
+		if (reply != NULL)
+			dbus_message_unref (reply);
+		goto error;
+	}
+	if (!dbus_message_get_args (reply, NULL,
+				    DBUS_TYPE_INT32, &(session->user),
+				    DBUS_TYPE_INVALID)) {
+		HAL_ERROR (("Invalid GetUser reply from CK"));
+		goto error;
+	}
+	dbus_message_unref (message);
+	dbus_message_unref (reply);
+
+	HAL_INFO (("Got active state (%s) and uid %d on session '%s'",
+		   session->is_active ? "ACTIVE" : "INACTIVE",
+		   session->user,
+		   session->session_objpath));
+
+	ret = TRUE;
+
+error:
+	return ret;
+}
+
+static gboolean
+ck_tracker_init_get_sessions_for_seat (CKTracker *tracker, CKSeat *seat)
+{
+	gboolean ret;
+	DBusError error;
+	DBusMessage *message;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	DBusMessageIter iter_array;
+
+	ret = FALSE;
+
+	message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", 
+						seat->seat_objpath,
+						"org.freedesktop.ConsoleKit.Seat",
+						"GetSessions");
+	dbus_error_init (&error);
+	reply = dbus_connection_send_with_reply_and_block (tracker->dbus_connection, message, -1, &error);
+	if (reply == NULL || dbus_error_is_set (&error)) {
+		HAL_ERROR (("Error doing GetSeats on ConsoleKit: %s: %s", error.name, error.message));
+		dbus_message_unref (message);
+		if (reply != NULL)
+			dbus_message_unref (reply);
+		goto error;
+	}
+
+	dbus_message_iter_init (reply, &iter);
+	if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) {
+		HAL_WARNING (("Expecting an array from GetSessions on ConsoleKit."));
+		dbus_message_unref (message);
+		dbus_message_unref (reply);
+		goto error;
+	}
+	dbus_message_iter_recurse (&iter, &iter_array);
+	while (dbus_message_iter_get_arg_type (&iter_array) == DBUS_TYPE_OBJECT_PATH) {
+		const char *session_objpath;
+		CKSession *session;
+
+		dbus_message_iter_get_basic (&iter_array, &session_objpath);
+		HAL_INFO (("got session '%s' for seat '%s'", session_objpath, seat->seat_objpath));
+
+		session = ck_session_new (session_objpath);
+
+		/* get information: is_active etc. */
+		if (!ck_session_get_info (tracker, session)) {
+			HAL_ERROR (("Could not get information for session '%s'", session_objpath));
+			dbus_message_unref (message);
+			dbus_message_unref (reply);
+			goto error;
+		}
+
+		ck_seat_attach_session (seat, session);
+
+		tracker->sessions = g_slist_prepend (tracker->sessions, session);
+
+		dbus_message_iter_next (&iter_array);
+	}
+	dbus_message_unref (message);
+	dbus_message_unref (reply);
+
+	HAL_INFO (("Got all sessions on seat '%s'", seat->seat_objpath));
+
+	ret = TRUE;
+
+error:
+	return ret;
+}
+
+static gboolean
+ck_tracker_init_get_seats_and_sessions (CKTracker *tracker)
+{
+	gboolean ret;
+	DBusError error;
+	DBusMessage *message;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	DBusMessageIter iter_array;
+
+	ret = FALSE;
+
+	/* first build array of existing seats and sessions */
+
+	message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", 
+						"/org/freedesktop/ConsoleKit/Manager",
+						"org.freedesktop.ConsoleKit.Manager",
+						"GetSeats");
+	dbus_error_init (&error);
+	reply = dbus_connection_send_with_reply_and_block (tracker->dbus_connection, message, -1, &error);
+	if (reply == NULL || dbus_error_is_set (&error)) {
+		HAL_ERROR (("Error doing GetSeats on ConsoleKit: %s: %s", error.name, error.message));
+		dbus_message_unref (message);
+		if (reply != NULL)
+			dbus_message_unref (reply);
+		goto error;
+	}
+
+	dbus_message_iter_init (reply, &iter);
+	if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) {
+		HAL_WARNING (("Expecting an array from GetSeats on ConsoleKit."));
+		dbus_message_unref (message);
+		dbus_message_unref (reply);
+		goto error;
+	}
+	dbus_message_iter_recurse (&iter, &iter_array);
+	while (dbus_message_iter_get_arg_type (&iter_array) == DBUS_TYPE_OBJECT_PATH) {
+		const char *seat_objpath;
+		CKSeat *seat;
+
+		dbus_message_iter_get_basic (&iter_array, &seat_objpath);
+		HAL_INFO (("got seat '%s'", seat_objpath));
+
+		seat = ck_seat_new (seat_objpath);
+
+		/* get information: is_local etc. */
+		if (!ck_seat_get_info (tracker, seat)) {
+			HAL_ERROR (("Could not get information for seat '%s'", seat_objpath));
+			dbus_message_unref (message);
+			dbus_message_unref (reply);
+			goto error;
+		}
+
+		/* for each seat, get the sessions */
+		if (!ck_tracker_init_get_sessions_for_seat (tracker, seat)) {
+			HAL_ERROR (("Could not get sessions for seat '%s'", seat_objpath));
+			dbus_message_unref (message);
+			dbus_message_unref (reply);
+			goto error;
+		}
+
+		tracker->seats = g_slist_prepend (tracker->seats, seat);
+
+		dbus_message_iter_next (&iter_array);
+	}
+	dbus_message_unref (message);
+	dbus_message_unref (reply);
+
+	HAL_INFO (("Got seats"));
+
+	ret = TRUE;
+error:
+	return ret;
+}
+
+void
+ck_tracker_ref (CKTracker *tracker)
+{
+	tracker->refcount++;
+}
+
+void
+ck_tracker_unref (CKTracker *tracker)
+{
+	tracker->refcount--;
+
+	if (tracker->refcount == 0) {
+		GSList *i;
+
+		for (i = tracker->sessions; i != NULL; i = g_slist_next (i)) {
+			CKSession *session = (CKSession *) i->data;
+			ck_session_unref (session);
+		}
+		
+		for (i = tracker->seats; i != NULL; i = g_slist_next (i)) {
+			CKSeat *seat = (CKSeat *) i->data;
+			ck_seat_unref (seat);
+		}
+		
+		tracker->dbus_connection = NULL;
+	}
+}
+
+void
+ck_tracker_set_system_bus_connection (CKTracker *tracker, DBusConnection *system_bus_connection)
+{
+	tracker->dbus_connection = system_bus_connection;
+}
+
+void
+ck_tracker_set_user_data (CKTracker *tracker, void *user_data)
+{
+	tracker->user_data = user_data;
+}
+
+void
+ck_tracker_set_session_added_cb (CKTracker *tracker, CKSessionAddedCB cb)
+{
+	tracker->session_added_cb = cb;
+}
+
+void
+ck_tracker_set_session_removed_cb (CKTracker *tracker, CKSessionRemovedCB cb)
+{
+	tracker->session_removed_cb = cb;
+}
+
+void
+ck_tracker_set_session_active_changed_cb (CKTracker *tracker, CKSessionActiveChangedCB cb)
+{
+	tracker->session_active_changed_cb = cb;
+}
+
+
+void
+ck_tracker_process_system_bus_message (CKTracker *tracker, DBusMessage *message)
+{
+	const char *seat_objpath;
+	const char *session_objpath;
+	dbus_bool_t session_is_active;
+	GSList *i;
+	CKSeat *seat;
+	CKSession *session;
+
+	HAL_INFO (("In ck_tracker_process_system_bus_message objpath=%s interface=%s method=%s", 
+		   dbus_message_get_path (message), 
+		   dbus_message_get_interface (message),
+		   dbus_message_get_member (message)));
+
+	/* TODO: also handle SeatRemoved and SeatAdded */
+
+	if (dbus_message_is_signal (message, "org.freedesktop.ConsoleKit.Seat", "SessionAdded")) {
+
+		seat_objpath = dbus_message_get_path (message);
+
+		if (!dbus_message_get_args (message, NULL,
+					    DBUS_TYPE_STRING, &session_objpath,
+					    DBUS_TYPE_INVALID)) {
+			HAL_ERROR (("Invalid SessionAdded signal from CK"));
+			goto out;
+		}
+
+		HAL_INFO (("Received SessionAdded '%s' from CK on seat '%s'", session_objpath, seat_objpath));
+
+		for (i = tracker->seats; i != NULL; i = g_slist_next (i)) {
+			seat = (CKSeat *) i->data;
+			if (strcmp (seat->seat_objpath, seat_objpath) == 0) {
+				session = ck_session_new (session_objpath);
+
+				/* get information: is_active etc. */
+				if (!ck_session_get_info (tracker, session)) {
+					HAL_ERROR (("Could not get information for session '%s'", session_objpath));
+					goto out;
+				}
+
+				ck_seat_attach_session (seat, session);
+				tracker->sessions = g_slist_prepend (tracker->sessions, session);
+
+				if (tracker->session_added_cb != NULL) {
+					tracker->session_added_cb (tracker, session, tracker->user_data);
+				}
+				break;
+			}
+		}
+		if (i == NULL) {
+			HAL_ERROR (("No seat '%s for session '%s'", seat_objpath, session_objpath));
+		}
+
+
+	} else if (dbus_message_is_signal (message, "org.freedesktop.ConsoleKit.Seat", "SessionRemoved")) {
+
+		seat_objpath = dbus_message_get_path (message);
+
+		if (!dbus_message_get_args (message, NULL,
+					    DBUS_TYPE_STRING, &session_objpath,
+					    DBUS_TYPE_INVALID)) {
+			HAL_ERROR (("Invalid SessionRemoved signal from CK"));
+			goto out;
+		}
+
+		HAL_INFO (("Received SessionRemoved '%s' from CK on seat '%s'", session_objpath, seat_objpath));
+
+		for (i = tracker->sessions; i != NULL; i = g_slist_next (i)) {
+			session = (CKSession *) i->data;
+			if (strcmp (session->session_objpath, session_objpath) == 0) {
+
+				if (tracker->session_removed_cb != NULL) {
+					tracker->session_removed_cb (tracker, session, tracker->user_data);
+				}
+
+				if (session->seat == NULL) {
+					HAL_ERROR (("Session '%s' to be removed is not attached to a seat", 
+						    session_objpath));
+				} else {
+					ck_seat_detach_session (session->seat, session);
+				}
+				tracker->sessions = g_slist_remove (tracker->sessions, session);
+				ck_session_unref (session);
+
+				break;
+			}
+		}
+		if (i == NULL) {
+			HAL_ERROR (("No such session '%s'", session_objpath));
+		}
+
+	} else if (dbus_message_is_signal (message, "org.freedesktop.ConsoleKit.Session", "ActiveChanged")) {
+
+		session_objpath = dbus_message_get_path (message);
+
+		if (!dbus_message_get_args (message, NULL,
+					    DBUS_TYPE_BOOLEAN, &session_is_active,
+					    DBUS_TYPE_INVALID)) {
+			HAL_ERROR (("Invalid SessionRemoved signal from CK"));
+			goto out;
+		}
+
+		HAL_INFO (("Received ActiveChanged to %s from CK on session '%s'", 
+			   session_is_active ? "ACTIVE" : "INACTIVE", session_objpath));
+
+
+		for (i = tracker->sessions; i != NULL; i = g_slist_next (i)) {
+			session = (CKSession *) i->data;
+			if (strcmp (session->session_objpath, session_objpath) == 0) {
+
+				session->is_active = session_is_active;
+
+				if (tracker->session_active_changed_cb != NULL) {
+					tracker->session_active_changed_cb (tracker, session, tracker->user_data);
+				}
+				break;
+			}
+		}
+		if (i == NULL) {
+			HAL_ERROR (("No such session '%s'", session_objpath));
+		}
+
+	}
+out:
+	;
+}
+
+GSList *
+ck_tracker_get_seats (CKTracker *tracker)
+{
+	return tracker->seats;
+}
+
+GSList *
+ck_tracker_get_sessions (CKTracker *tracker)
+{
+	return tracker->sessions;
+}
+
+gboolean
+ck_seat_is_local (CKSeat *seat)
+{
+	return seat->is_local;
+}
+
+GSList *
+ck_seat_get_sessions (CKSeat *seat)
+{
+	return seat->sessions;
+}
+
+const char *
+ck_seat_get_id (CKSeat *seat)
+{
+	return seat->seat_objpath;
+}
+
+gboolean
+ck_session_is_active (CKSession *session)
+{
+	return session->is_active;
+}
+
+CKSeat *
+ck_session_get_seat (CKSession *session)
+{
+	return session->seat;
+}
+
+const char *
+ck_session_get_id (CKSession *session)
+{
+	return session->session_objpath;
+}
+
+uid_t
+ck_session_get_user (CKSession *session)
+{
+	return session->user;
+}
+
+gboolean
+ck_tracker_init (CKTracker *tracker)
+{
+	dbus_bool_t ret;
+
+	ret = FALSE;
+
+	if (!ck_tracker_init_get_seats_and_sessions (tracker)) {
+		HAL_ERROR (("Could not get seats and sessions"));
+		goto out;
+	}
+	
+	HAL_INFO (("Got seats and sessions"));
+
+	ret = TRUE;
+
+out:
+	return ret;
+}
+
+CKTracker *
+ck_tracker_new (void)
+{
+	CKTracker *tracker;
+
+	tracker = g_new0 (CKTracker, 1);
+	tracker->refcount = 1;
+	return tracker;
+}
diff --git a/hald/ck-tracker.h b/hald/ck-tracker.h
new file mode 100644
index 0000000..6c3147b
--- /dev/null
+++ b/hald/ck-tracker.h
@@ -0,0 +1,86 @@
+/***************************************************************************
+ * CVSID: $Id$
+ *
+ * ck-tracker.h : Track seats and sessions via ConsoleKit
+ *
+ * Copyright (C) 2007 David Zeuthen, <david at fubar.dk>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ **************************************************************************/
+
+#ifndef CK_TRACKER_H
+#define CK_TRACKER_H
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <dbus/dbus.h>
+#include <glib.h>
+
+struct CKTracker_s;
+typedef struct CKTracker_s CKTracker;
+struct CKSeat_s;
+typedef struct CKSeat_s CKSeat;
+struct CKSession_s;
+typedef struct CKSession_s CKSession;
+
+typedef void (*CKSessionAddedCB) (CKTracker *tracker, CKSession *session, void *user_data);
+typedef void (*CKSessionRemovedCB) (CKTracker *tracker, CKSession *session, void *user_data);
+typedef void (*CKSessionActiveChangedCB) (CKTracker *tracker, CKSession *session, void *user_data);
+
+CKTracker  *ck_tracker_new                        (void);
+void        ck_tracker_set_system_bus_connection     (CKTracker *tracker, DBusConnection *system_bus_connection);
+void        ck_tracker_set_user_data                 (CKTracker *tracker, void *user_data);
+void        ck_tracker_set_session_added_cb          (CKTracker *tracker, CKSessionAddedCB cb);
+void        ck_tracker_set_session_removed_cb        (CKTracker *tracker, CKSessionRemovedCB cb);
+void        ck_tracker_set_session_active_changed_cb (CKTracker *tracker, CKSessionActiveChangedCB cb);
+/* TODO: also handle seat_added, seat_removed */
+gboolean    ck_tracker_init                          (CKTracker *tracker);
+
+/* Forward DBusMessage signals for 
+ *
+ *  org.freedesktop.ConsoleKit.Seat.SessionAdded
+ *  org.freedesktop.ConsoleKit.Seat.SessionRemoved
+ *  org.freedesktop.ConsoleKit.Session.ActiveChanged
+ *
+ * on all objects on ConsoleKit to this function. 
+ *
+ *  TODO: need org.freedesktop.DBus.NameOwnerChanged from D-Bus to notice CK going away
+ *
+ * TODO: provide convenience method for letting CKTracker setup matches
+ * with the bus here via dbus_connection_add_filter() and
+ * dbus_bus_add_match(). E.g. just like libhal.
+ */
+void        ck_tracker_process_system_bus_message (CKTracker *tracker, DBusMessage *message);
+
+void        ck_tracker_ref                        (CKTracker *tracker);
+void        ck_tracker_unref                      (CKTracker *tracker);
+
+GSList     *ck_tracker_get_seats                  (CKTracker *tracker);
+GSList     *ck_tracker_get_sessions               (CKTracker *tracker);
+
+gboolean    ck_seat_is_local                      (CKSeat *seat);
+GSList     *ck_seat_get_sessions                  (CKSeat *seat);
+const char *ck_seat_get_id                        (CKSeat *seat);
+
+gboolean    ck_session_is_active                  (CKSession *session);
+CKSeat     *ck_session_get_seat                   (CKSession *session);
+const char *ck_session_get_id                     (CKSession *session);
+uid_t       ck_session_get_user                   (CKSession *session);
+
+
+#endif /* CK_TRACKER_H */
diff --git a/hald/hald.c b/hald/hald.c
index 4e4f1c6..2918558 100644
--- a/hald/hald.c
+++ b/hald/hald.c
@@ -597,6 +597,10 @@ main (int argc, char *argv[])
 	if (!hald_dbus_local_server_init ())
 		return 1;
 
+	if (!hald_dbus_init_preprobe ()) {
+		return 1;
+	}
+
 	/* Start the runner helper daemon */
 	if (!hald_runner_start_runner ()) {
 		return 1;
diff --git a/hald/hald_dbus.c b/hald/hald_dbus.c
index ddd6b8e..08c5367 100644
--- a/hald/hald_dbus.c
+++ b/hald/hald_dbus.c
@@ -48,9 +48,12 @@
 #include "util.h"
 #include "hald_runner.h"
 
+#include "ck-tracker.h"
+
 #define HALD_DBUS_ADDRESS "unix:tmpdir=" HALD_SOCKET_DIR
 
 static DBusConnection *dbus_connection = NULL;
+static CKTracker *ck_tracker = NULL;
 
 static void
 raise_error (DBusConnection *connection,
@@ -576,7 +579,7 @@ manager_send_signal_device_added (HalDev
 	DBusMessage *message;
 	DBusMessageIter iter;
 
-	if (dbus_connection == NULL)
+	if (dbus_connection == NULL || hald_is_initialising)
 		goto out;
 
 	HAL_TRACE (("entering, udi=%s", udi));
@@ -609,7 +612,7 @@ manager_send_signal_device_removed (HalD
 	DBusMessage *message;
 	DBusMessageIter iter;
 
-	if (dbus_connection == NULL)
+	if (dbus_connection == NULL || hald_is_initialising)
 		goto out;
 
 	HAL_TRACE (("entering, udi=%s", udi));
@@ -644,7 +647,7 @@ manager_send_signal_new_capability (HalD
 	DBusMessage *message;
 	DBusMessageIter iter;
 
-	if (dbus_connection == NULL)
+	if (dbus_connection == NULL || hald_is_initialising)
 		goto out;
 
 	HAL_TRACE (("entering, udi=%s, cap=%s", udi, capability));
@@ -931,7 +934,8 @@ caller_info_free (CallerInfo *ci)
 	g_free (ci);
 }
 
-GHashTable *connection_name_to_caller_info;
+static GHashTable *connection_name_to_caller_info;
+
 
 static void
 ci_tracker_init (void)
@@ -2364,7 +2368,7 @@ device_send_signal_property_modified (Ha
 		DBusMessageIter iter_struct;
 		DBusMessageIter iter_array;
 
-		if (dbus_connection == NULL)
+		if (dbus_connection == NULL || hald_is_initialising)
 			goto out;
 		
 		message = dbus_message_new_signal (udi,
@@ -2431,7 +2435,7 @@ device_send_signal_condition (HalDevice 
 	DBusMessage *message;
 	DBusMessageIter iter;
 
-	if (dbus_connection == NULL)
+	if (dbus_connection == NULL || hald_is_initialising)
 		goto out;
 
 	message = dbus_message_new_signal (udi,
@@ -4159,7 +4163,8 @@ no_caller:
 }
 
 /** Message handler for method invocations. All invocations on any object
- *  or interface is routed through this function.
+ *  or interface is routed through this function. *ONLY* messages from the
+ *  system bus goes through this method.
  *
  *  @param  connection          D-BUS connection
  *  @param  message             Message
@@ -4170,6 +4175,13 @@ DBusHandlerResult
 hald_dbus_filter_function (DBusConnection * connection,
 			   DBusMessage * message, void *user_data)
 {
+#ifdef HAVE_CONKIT
+	/* TODO: only push the appropriate messages to the tracker; see ck-tracker.h */
+	if (ck_tracker != NULL) {
+		ck_tracker_process_system_bus_message (ck_tracker, message);
+	}
+#endif
+
 	if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected") &&
 	    strcmp (dbus_message_get_path (message), DBUS_PATH_LOCAL) == 0) {
 
@@ -4388,12 +4400,37 @@ hald_dbus_local_server_shutdown (void)
 	}
 }
 
+static void 
+hald_dbus_session_added (CKTracker *tracker, CKSession *session, void *user_data)
+{
+	HAL_INFO (("In hald_dbus_session_added for session '%s' on seat '%s'", 
+		   ck_session_get_id (session),
+		   ck_session_get_seat (session) != NULL ? ck_seat_get_id (ck_session_get_seat (session)) : "(NONE)"));
+}
+
+static void 
+hald_dbus_session_removed (CKTracker *tracker, CKSession *session, void *user_data)
+{
+	HAL_INFO (("In hald_dbus_session_removed for session '%s' on seat '%s'", 
+		   ck_session_get_id (session),
+		   ck_session_get_seat (session) != NULL ? ck_seat_get_id (ck_session_get_seat (session)) : "(NONE)"));
+}
+
+static void 
+hald_dbus_session_active_changed (CKTracker *tracker, CKSession *session, void *user_data)
+{
+	HAL_INFO (("In hald_dbus_session_active_changed for session '%s': %s", 
+		   ck_session_get_id (session),
+		   ck_session_is_active (session) ? "ACTIVE" : "INACTIVE"));
+}
+
 gboolean
-hald_dbus_init (void)
+hald_dbus_init_preprobe (void)
 {
+	gboolean ret;
 	DBusError dbus_error;
 
-	HAL_INFO (("entering"));
+	ret = FALSE;
 
 	dbus_connection_set_change_sigpipe (TRUE);
 
@@ -4401,22 +4438,15 @@ hald_dbus_init (void)
 	dbus_connection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbus_error);
 	if (dbus_connection == NULL) {
 		HAL_ERROR (("dbus_bus_get(): %s", dbus_error.message));
-		return FALSE;
+		goto out;
 	}
 
 	dbus_connection_setup_with_g_main (dbus_connection, NULL);
 	dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE);
 
-	dbus_bus_request_name (dbus_connection, "org.freedesktop.Hal",
-				  0, &dbus_error);
-	if (dbus_error_is_set (&dbus_error)) {
-		HAL_ERROR (("dbus_bus_request_name(): %s",
-			    dbus_error.message));
-		return FALSE;
-	}
-
 	dbus_connection_add_filter (dbus_connection, hald_dbus_filter_function, NULL, NULL);
 
+
 	dbus_bus_add_match (dbus_connection,
 			    "type='signal'"
 			    ",interface='"DBUS_INTERFACE_DBUS"'"
@@ -4431,10 +4461,54 @@ hald_dbus_init (void)
 			    ",sender='org.freedesktop.ConsoleKit'"
 			    ",member='ActiveChanged'",
 			    NULL);
+	dbus_bus_add_match (dbus_connection,
+			    "type='signal'"
+			    ",interface='org.freedesktop.ConsoleKit.Seat'"
+			    ",sender='org.freedesktop.ConsoleKit'"
+			    ",member='SessionAdded'",
+			    NULL);
+	dbus_bus_add_match (dbus_connection,
+			    "type='signal'"
+			    ",interface='org.freedesktop.ConsoleKit.Seat'"
+			    ",sender='org.freedesktop.ConsoleKit'"
+			    ",member='SessionRemoved'",
+			    NULL);
+
+	ck_tracker = ck_tracker_new ();
+	ck_tracker_set_system_bus_connection (ck_tracker, dbus_connection);
+	ck_tracker_set_session_added_cb (ck_tracker, hald_dbus_session_added);
+	ck_tracker_set_session_removed_cb (ck_tracker, hald_dbus_session_removed);
+	ck_tracker_set_session_active_changed_cb (ck_tracker, hald_dbus_session_active_changed);
+	if (!ck_tracker_init (ck_tracker)) {
+		ck_tracker_unref (ck_tracker);
+		DIE (("Could not initialize seats and sessions from ConsoleKit"));
+	}
+
 #endif /* HAVE_CONKIT */
 
 	ci_tracker_init ();
 
+	ret = TRUE;
+
+out:
+	return ret;
+}
+
+gboolean
+hald_dbus_init (void)
+{
+	DBusError dbus_error;
+
+	HAL_INFO (("entering"));
+
+	dbus_error_init (&dbus_error);
+	dbus_bus_request_name (dbus_connection, "org.freedesktop.Hal", 0, &dbus_error);
+	if (dbus_error_is_set (&dbus_error)) {
+		HAL_ERROR (("dbus_bus_request_name(): %s",
+			    dbus_error.message));
+		return FALSE;
+	}
+
 	return TRUE;
 }
 
diff --git a/hald/hald_dbus.h b/hald/hald_dbus.h
index 439f451..79442be 100644
--- a/hald/hald_dbus.h
+++ b/hald/hald_dbus.h
@@ -87,6 +87,8 @@ void device_send_signal_condition (HalDe
 void device_property_atomic_update_begin (void);
 void device_property_atomic_update_end   (void);
 
+gboolean hald_dbus_init_preprobe (void);
+
 gboolean hald_dbus_init (void);
 
 gboolean hald_dbus_local_server_init (void);
diff --git a/hald/util.c b/hald/util.c
index 6ad4fcf..eaf3b09 100644
--- a/hald/util.c
+++ b/hald/util.c
@@ -942,9 +942,9 @@ callout_do_next (Callout *c)
 		callback (d, userdata1, userdata2);
 
 	} else {
-    hald_runner_run(c->d, c->programs[c->next_program], c->extra_env,
-                    HAL_HELPER_TIMEOUT, callout_terminated,
-                    (gpointer)c, NULL);
+		hald_runner_run(c->d, c->programs[c->next_program], c->extra_env,
+				HAL_HELPER_TIMEOUT, callout_terminated,
+				(gpointer)c, NULL);
 		c->next_program++;
 	}
 }
diff --git a/tools/Makefile.am b/tools/Makefile.am
index d820cc8..037b4aa 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -58,6 +58,15 @@ libexec_PROGRAMS =                      
 	hal-storage-cleanup-all-mountpoints \
 	hal-system-power-pmu
 
+if HAVE_ACLMGMT
+libexec_PROGRAMS += hal-acl-add hal-acl-remove
+
+hal_acl_add_SOURCES = hal-acl-add.c
+hal_acl_remove_SOURCES = hal-acl-remove.c
+endif
+
+
+
 hal_storage_mount_SOURCES = hal-storage-mount.c hal-storage-shared.c hal-storage-shared.h
 hal_storage_mount_LDADD = @GLIB_LIBS@ @POLKIT_LIBS@ @DBUS_LIBS@ $(top_builddir)/libhal/libhal.la $(top_builddir)/libhal-storage/libhal-storage.la
 
diff --git a/tools/hal-acl-add.c b/tools/hal-acl-add.c
new file mode 100644
index 0000000..2767773
--- /dev/null
+++ b/tools/hal-acl-add.c
@@ -0,0 +1,91 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/file.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <glib.h>
+
+#if 0
+static int lock_acl_fd = -1;
+
+static gboolean
+lock_hal_acl (void)
+{
+	if (lock_acl_fd >= 0)
+		return TRUE;
+
+	printf ("%d: attempting to get lock on /var/lib/hal/acl-list\n", getpid ());
+
+	lock_acl_fd = open ("/var/lib/hal/acl-list", O_CREAT | O_RDWR);
+
+	if (lock_acl_fd < 0)
+		return FALSE;
+
+tryagain:
+#if sun
+	if (lockf (lock_acl_fd, F_LOCK, 0) != 0) {
+#else
+	if (flock (lock_acl_fd, LOCK_EX) != 0) {
+#endif
+		if (errno == EINTR)
+			goto tryagain;
+		return FALSE;
+	}
+	
+	printf ("%d: got lock on /var/lib/hal/acl-list\n", getpid ());
+	
+	
+	return TRUE;
+}
+	
+static void
+unlock_hal_acl (void)
+{
+#if sun
+	lockf (lock_acl_fd, F_ULOCK, 0);
+#else
+	flock (lock_acl_fd, LOCK_UN);
+#endif
+	close (lock_acl_fd);
+	lock_acl_fd = -1;
+	printf ("%d: released lock on /var/lib/hal/acl-list\n", getpid ());
+}
+
+/* Each entry here represents a line in the acl-list file 
+ *
+ *   <device-file>\t<hal-udi>\t<uid-as-number>\t<gid-as-number>\t<session-id>
+ *
+ * example:
+ *
+ *   /dev/snd/controlC0\t/org/freedesktop/Hal/devices/pci_8086_27d8_alsa_control__1\t500\t\t/org/freedesktop/ConsoleKit/Session0
+ *
+ * This means that the 
+ */
+typedef struct HalACL_s {
+	const char *device;
+	const char *uid;
+	uid_t uid;           /* 0 if unset */
+	gid_t gid;           /* 0 if unset */
+	const char *session; /* NULL if unset */
+} HalACL;
+
+/* hal-acl-grant can run in two modes of operation;
+ *
+ * 1) as a hal callout via info.callouts.add - this will set ACL's on the device file pointed to by acl.file
+ *    using the information provided by the other acl.* properties to determine what ACL's to add to the given
+ *    device file
+ *
+ * 2) 
+ *
+ */
+#endif
+
+int 
+main (int argc, char *argv[])
+{
+	fprintf (stderr, "hal-acl-add\n");
+	return 0;
+}
diff --git a/tools/hal-acl-remove.c b/tools/hal-acl-remove.c
new file mode 100644
index 0000000..3f9278b
--- /dev/null
+++ b/tools/hal-acl-remove.c
@@ -0,0 +1,15 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int 
+main (int argc, char *argv[])
+{
+	int i;
+
+	fprintf (stderr, "hal-acl-remove %d\n", argc);
+	for (i = 0; i < argc; i++) {
+		fprintf (stderr, " arg %2d: %s\n", i, argv[i]);		
+	}
+	return 0;
+}


More information about the hal-commit mailing list