hal/hald hald.c, 1.10, 1.11 hald_dbus.c, 1.7, 1.8 hald_dbus.h, 1.2, 1.3 osspec.h, 1.3, 1.4

Joe Shaw joe at freedesktop.org
Fri Jul 30 10:00:44 PDT 2004


Update of /cvs/hal/hal/hald
In directory pdx:/tmp/cvs-serv16448/hald

Modified Files:
	hald.c hald_dbus.c hald_dbus.h osspec.h 
Log Message:
2004-07-30  Joe Shaw  <joeshaw at novell.com>

	* hald/hald.c (main): Update for the change to hald_dbus_init():
	don't get a DBusConnection from there, exit() if it fails.  Also
	update for the change to osspec_init(): don't pass in any
	arguments.

	* hald/hald_dbus.c (hald_dbus_init): Don't exit() anywhere here;
	instead return FALSE.  Tell dbus not to exit if we're disconnected
	from the bus.  Return TRUE on success, not a DBusConnection.
	(filter_function): Listen for the "Disconnected" signal on the
	"Local" dbus interface and if so, unref the connection and try to
	reconnect to the system bus every 3 seconds.
	(reinit_dbus): Try to reconnect to the system bus.

	* hald/osspec.h: Change osspec_init() to not take any parameters;
	the only backend (the Linux 2.6 one) wasn't using it.

	* hald/linux/osspec.c (osspec_init): Take void instead of a
	DBusConnection.

Index: hald.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- hald.c	21 Jul 2004 17:14:54 -0000	1.10
+++ hald.c	30 Jul 2004 17:00:42 -0000	1.11
@@ -226,7 +226,6 @@
 int
 main (int argc, char *argv[])
 {
-	DBusConnection *dbus_connection;
 	GMainLoop *loop;
 	guint sigterm_iochn_listener_source_id;
 
@@ -325,7 +324,8 @@
 	g_type_init ();
 
 	/* set up the dbus services */
-	dbus_connection = hald_dbus_init ();
+	if (!hald_dbus_init ())
+		exit (1);
 
 	loop = g_main_loop_new (NULL, FALSE);
 
@@ -334,7 +334,7 @@
 		hal_pstore_init (PACKAGE_LOCALSTATEDIR "/lib/hal/uuid");
 
 	/* initialize operating system specific parts */
-	osspec_init (dbus_connection);
+	osspec_init ();
 	/* and detect devices */
 	osspec_probe ();
 

Index: hald_dbus.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald_dbus.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- hald_dbus.c	23 Jun 2004 21:34:51 -0000	1.7
+++ hald_dbus.c	30 Jul 2004 17:00:42 -0000	1.8
@@ -1742,6 +1742,15 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
+static gboolean
+reinit_dbus (gpointer user_data)
+{
+	if (hald_dbus_init ())
+		return FALSE;
+	else
+		return TRUE;
+}
+
 /** Message handler for method invocations. All invocations on any object
  *  or interface is routed through this function.
  *
@@ -1761,11 +1770,18 @@
     dbus_message_get_member(message)));
 */
 
-	if (dbus_message_is_method_call (message,
+	if (dbus_message_is_signal (message,
+				    DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL,
+				    "Disconnected") &&
+	    strcmp (dbus_message_get_path (message),
+		    DBUS_PATH_ORG_FREEDESKTOP_LOCAL) == 0) {
+		dbus_connection_unref (dbus_connection);
+		g_timeout_add (3000, reinit_dbus, NULL);
+	} else if (dbus_message_is_method_call (message,
 					 "org.freedesktop.Hal.Manager",
 					 "GetAllDevices") &&
-	    strcmp (dbus_message_get_path (message),
-		    "/org/freedesktop/Hal/Manager") == 0) {
+		   strcmp (dbus_message_get_path (message),
+			   "/org/freedesktop/Hal/Manager") == 0) {
 		return manager_get_all_devices (connection, message);
 	} else if (dbus_message_is_method_call (message,
 						"org.freedesktop.Hal.Manager",
@@ -1893,7 +1909,7 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-DBusConnection *
+gboolean
 hald_dbus_init (void)
 {
 	DBusError dbus_error;
@@ -1904,23 +1920,24 @@
 	dbus_connection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbus_error);
 	if (dbus_connection == NULL) {
 		HAL_ERROR (("dbus_bus_get(): %s", dbus_error.message));
-		exit (1);
+		return FALSE;
 	}
 
 	dbus_connection_setup_with_g_main (dbus_connection, NULL);
+	dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE);
 
 	dbus_bus_acquire_service (dbus_connection, "org.freedesktop.Hal",
 				  0, &dbus_error);
 	if (dbus_error_is_set (&dbus_error)) {
 		HAL_ERROR (("dbus_bus_acquire_service(): %s",
 			    dbus_error.message));
-		exit (1);
+		return FALSE;
 	}
 
 	dbus_connection_add_filter (dbus_connection, filter_function, NULL,
 				    NULL);
 
-	return dbus_connection;
+	return TRUE;
 }
 
 /** @} */

Index: hald_dbus.h
===================================================================
RCS file: /cvs/hal/hal/hald/hald_dbus.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- hald_dbus.h	3 Apr 2004 07:46:33 -0000	1.2
+++ hald_dbus.h	30 Jul 2004 17:00:42 -0000	1.3
@@ -83,6 +83,6 @@
 void device_property_atomic_update_begin (void);
 void device_property_atomic_update_end   (void);
 
-DBusConnection *hald_dbus_init (void);
+gboolean hald_dbus_init (void);
 
 #endif /* HAL_DBUS_H */

Index: osspec.h
===================================================================
RCS file: /cvs/hal/hal/hald/osspec.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- osspec.h	21 Jul 2004 17:14:54 -0000	1.3
+++ osspec.h	30 Jul 2004 17:00:42 -0000	1.4
@@ -33,20 +33,19 @@
 
 /** Initialize the OS specific parts of the daemon
  *
- *  @param  dbus_connection     The D-BUS connection the HAL daemon got,
  */
-void osspec_init (DBusConnection * dbus_connection);
+void osspec_init (void);
 
 /** Probe all hardware present in the system and synchronize with the
  *  device list
  *
  */
-void osspec_probe ();
+void osspec_probe (void);
 
 /** Prepare shutdown
  *
  */
-void osspec_shutdown ();
+void osspec_shutdown (void);
 
 DBusHandlerResult osspec_filter_function (DBusConnection * connection,
 					  DBusMessage * message,




More information about the hal-commit mailing list