hal: Branch 'master'

Joe Marcus Clarke marcus at kemper.freedesktop.org
Sat Mar 22 12:15:37 PDT 2008


 hald/freebsd/addons/addon-storage.c |   91 +++++++++++++++++++++++++++---------
 1 file changed, 69 insertions(+), 22 deletions(-)

New commits:
commit 3eac1d8399a7e7d1eb76873c10a29e0fea94ad6c
Author: Joe Marcus Clarke <marcus at FreeBSD.org>
Date:   Sat Mar 22 15:15:46 2008 -0400

    add support for the CheckForMedia message
    
    Handle requests for CheckForMedia especially for floppy disk devices.

diff --git a/hald/freebsd/addons/addon-storage.c b/hald/freebsd/addons/addon-storage.c
index 07e667e..dcd9cdc 100644
--- a/hald/freebsd/addons/addon-storage.c
+++ b/hald/freebsd/addons/addon-storage.c
@@ -150,6 +150,34 @@ hf_addon_storage_update (void)
   return has_media;
 }
 
+static boolean
+poll_for_media (void)
+{
+  boolean has_media;
+
+  has_media = hf_addon_storage_update();
+  if (has_media != addon.had_media)
+    {
+      /*
+       * FIXME: if the media was removed, we should force-unmount
+       * all its child volumes (see linux2/addons/addon-storage.c).
+       * However, currently (FreeBSD 6.0) umount -f is broken and
+       * can cause kernel panics. When I tried to umount -f a
+       * flash card after removing it, it failed with EAGAIN. It
+       * continued to fail after I inserted the card. The system
+       * then hung while rebooting and did not unmount my other
+       * filesystems.
+       */
+
+      libhal_device_rescan(hfp_ctx, hfp_udi, &hfp_error);
+      dbus_error_free(&hfp_error);
+      addon.had_media = has_media;
+
+      return TRUE;
+    }
+  return FALSE;
+}
+
 static void
 update_proc_title (const char *device, boolean polling_enabled)
 {
@@ -159,6 +187,29 @@ update_proc_title (const char *device, boolean polling_enabled)
     setproctitle("no polling on %s because it is explicitly disabled", device);
 }
 
+static DBusHandlerResult
+filter_function (DBusConnection *connection, DBusMessage *message, void *user_data)
+{
+  if (dbus_message_is_method_call(message,
+			  	  "org.freedesktop.Hal.Device.Storage.Removable",
+				  "CheckForMedia"))
+    {
+      DBusMessage *reply;
+      dbus_bool_t had_effect;
+
+      hfp_info("Forcing poll for media becusse CheckForMedia() was called");
+
+      had_effect = poll_for_media();
+
+      reply = dbus_message_new_method_return (message);
+      dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &had_effect, DBUS_TYPE_INVALID);
+      dbus_connection_send(connection, reply, NULL);
+      dbus_message_unref(reply);
+    }
+
+  return DBUS_HANDLER_RESULT_HANDLED;
+}
+
 int
 main (int argc, char **argv)
 {
@@ -202,17 +253,30 @@ main (int argc, char **argv)
     ! strcmp(driver, "cd")))) && ! strcmp(removable, "true");
   addon.had_media = hf_addon_storage_update();
 
-  if (!libhal_device_addon_is_ready(hfp_ctx, hfp_udi, &hfp_error))
+  if (! libhal_device_addon_is_ready(hfp_ctx, hfp_udi, &hfp_error))
     goto end;
   dbus_error_free(&hfp_error);
 
   connection = libhal_ctx_get_dbus_connection(hfp_ctx);
   assert(connection != NULL);
+  dbus_connection_set_exit_on_disconnect(connection, 0);
+  dbus_connection_add_filter(connection, filter_function, NULL, NULL);
+
+  if (! libhal_device_claim_interface(hfp_ctx,
+			 	      hfp_udi,
+				      "org.freedesktop.Hal.Device.Storage.Removable",
+				      "    <method name=\"CheckForMedia\">\n"
+				      "      <arg name=\"call_had_sideeffect\" direction=\"out\" type=\"b\"/>\n"
+				      "    </method>\n",
+				      &hfp_error))
+    {
+      hfp_critical("Cannot claim interface 'org.freedesktop.Hal.Device.Storage.Removable'");
+      goto end;
+    }
+  dbus_error_free(&hfp_error);
 
   while (TRUE)
     {
-      boolean has_media;
-
       /* process dbus traffic until update interval has elapsed */
       while (TRUE)
 	{
@@ -229,7 +293,7 @@ main (int argc, char **argv)
 	      if (timeout.tv_sec < 0) /* current time went backwards */
 		timeout = addon.update_interval;
 
-	      dbus_connection_read_write(connection, timeout.tv_sec * 1000 + timeout.tv_usec / 1000);
+	      dbus_connection_read_write_dispatch(connection, timeout.tv_sec * 1000 + timeout.tv_usec / 1000);
 	      if (! dbus_connection_get_is_connected(connection))
 		goto end;
 	    }
@@ -243,24 +307,7 @@ main (int argc, char **argv)
 
       if (should_poll)
         {
-          has_media = hf_addon_storage_update();
-          if (has_media != addon.had_media)
-	    {
-	      /*
-	       * FIXME: if the media was removed, we should force-unmount
-	       * all its child volumes (see linux2/addons/addon-storage.c).
-	       * However, currently (FreeBSD 6.0) umount -f is broken and
-	       * can cause kernel panics. When I tried to umount -f a
-	       * flash card after removing it, it failed with EAGAIN. It
-	       * continued to fail after I inserted the card. The system
-	       * then hung while rebooting and did not unmount my other
-	       * filesystems.
-	       */
-
-	      libhal_device_rescan(hfp_ctx, hfp_udi, &hfp_error);
-	      dbus_error_free(&hfp_error);
-	      addon.had_media = has_media;
-	    }
+          poll_for_media();
         }
       else
         {


More information about the hal-commit mailing list