hal/libhal libhal.c,1.46,1.47 libhal.h,1.25,1.26

David Zeuthen david at freedesktop.org
Fri Apr 8 11:10:22 PDT 2005


Update of /cvs/hal/hal/libhal
In directory gabe:/tmp/cvs-serv32581/libhal

Modified Files:
	libhal.c libhal.h 
Log Message:
2005-04-08  David Zeuthen  <davidz at redhat.com>

	Make all hal helpers use a direct connection to hald rather than
	going through the bus. This is for both performance and security
	reasons. Also, fix the reconnect issue and don't connect to the
	system message bus before probing is done.

	* configure.in: Require dbus 0.33; that, for now, means D-BUS CVS
	HEAD since it requires the patch in fd.o bug #2889 and D-BUS made
	a post-release version bump. I'll look into doing a D-BUS release
	soon.

	* libhal/libhal.h: Export prototype for libhal_ctx_init_direct()

	* libhal/libhal.c (libhal_ctx_init_direct): New convenience function
	for connecting directly to hald instead of going through the message
	bus (requires the address in the HALD_DIRECT_ADDR environment variable)

	* hald/util.c (hal_util_helper_invoke): Export the local hald dbus
	server address in HALD_DIRECT_ADDR

	* hald/hald_dbus.c (manager_send_signal_device_added): Handle the
	case where we're not connected to the system message bus
	(manager_send_signal_device_removed): -do-
	(manager_send_signal_new_capability): -do-
	(device_property_atomic_update_end): -do-
	(device_send_signal_property_modified): -do-
	(device_send_signal_condition): -do-
	(device_set_property): Always allow local interface
	(device_add_capability): -do-
	(device_remove_property): -do-
	(device_rescan): -do-
	(device_reprobe): -do-
	(device_emit_condition): -do-
	(hald_dbus_filter_handle_methods): New function
	(hald_dbus_filter_function): Move bulk of functionality to the new
	hald_dbus_filter_handle_methods() and pass local_interface==FALSE.
	Handle Disconnect from local libdbus properly and attempt to
	reconnect to the system message bus every so often (every 3 secs)
	(local_server_message_handler): New function
	(local_server_unregister_handler): New function
	(local_server_handle_connection): New function
	(hald_dbus_local_server_addr): New function
	(hald_dbus_local_server_init): New function

	* hald/hald.c (main): Register a local dbus server instead of
	connection to the system bus as startup
	(osspec_probe_done): Only connect to the system bus once probing
	is done

	* tools/fstab-sync.c (main): Use direct connection

	* hald/linux2/probing/probe-volume.c (main): Use direct connection

	* hald/linux2/probing/probe-storage.c (main): Use direct connection

	* hald/linux2/probing/probe-smbios.c (main): Use direct connection

	* hald/linux2/probing/probe-printer.c (main): Use direct connection

	* hald/linux2/probing/probe-hiddev.c (main): Use direct connection

	* hald/linux2/probing/probe-input.c (main): Use direct connection

	* hald/linux2/addons/addon-usb-csr.c (main): Use direct connection

	* hald/linux2/addons/addon-storage.c (main): Use direct connection

	* hald/linux2/addons/addon-hid-ups.c (main): Use direct connection

	* hald/linux2/addons/addon-acpi.c (main): Use direct connection

	* hald/linux2/probing/probe-pc-floppy.c (main): Remove all references
	to hal and dbus since this program just returns the result in the
	exit code



Index: libhal.c
===================================================================
RCS file: /cvs/hal/hal/libhal/libhal.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- libhal.c	25 Mar 2005 03:24:51 -0000	1.46
+++ libhal.c	8 Apr 2005 18:10:20 -0000	1.47
@@ -191,6 +191,7 @@
 	dbus_bool_t is_initialized;           /**< Are we initialised */
 	dbus_bool_t is_shutdown;              /**< Have we been shutdown */
 	dbus_bool_t cache_enabled;            /**< Is the cache enabled */
+	dbus_bool_t is_direct;                /**< Whether the connection to hald is direct */
 
 	/** Device added */
 	LibHalDeviceAdded device_added;
@@ -2709,6 +2710,7 @@
 	ctx->is_initialized = FALSE;
 	ctx->is_shutdown = FALSE;
 	ctx->connection = NULL;
+	ctx->is_direct = FALSE;
 
 	return ctx;
 }
@@ -2763,30 +2765,69 @@
 		return FALSE;
 	}
 	ctx->is_initialized = TRUE;
+	ctx->is_direct = FALSE;
 
 	return TRUE;
 }
 
+LibHalContext *
+libhal_ctx_init_direct (DBusError *error)
+{
+	char *hald_addr;
+	LibHalContext *ctx;
+	DBusError _error;
+
+	ctx = libhal_ctx_new ();
+	if (ctx == NULL)
+		goto out;
+
+	if (((hald_addr = getenv ("HALD_DIRECT_ADDR"))) == NULL) {
+		libhal_ctx_free (ctx);
+		ctx = NULL;
+		goto out;
+	}
+
+	dbus_error_init (&_error);
+	ctx->connection = dbus_connection_open (hald_addr, &_error);
+	dbus_move_error (&_error, error);
+	if (error != NULL && dbus_error_is_set (error)) {
+		libhal_ctx_free (ctx);
+		ctx = NULL;
+		goto out;
+	}
+
+	ctx->is_initialized = TRUE;
+	ctx->is_direct = TRUE;
+
+out:
+	return ctx;
+}
+
 dbus_bool_t    
 libhal_ctx_shutdown (LibHalContext *ctx, DBusError *error)
 {
 	DBusError myerror;
 
-	dbus_error_init (&myerror);
-	dbus_bus_add_match (ctx->connection, 
-			    "type='signal',"
-			    "interface='org.freedesktop.Hal.Manager',"
-			    "sender='org.freedesktop.Hal',"
-			    "path='/org/freedesktop/Hal/Manager'", &myerror);
-	if (dbus_error_is_set (&myerror)) {
-		fprintf (stderr, "%s %d : Error unsubscribing to signals, error=%s\n", 
-			 __FILE__, __LINE__, error->message);
-		/** @todo  clean up */
-	}
+	if (ctx->is_direct) {
+		/* for some reason dbus_connection_set_exit_on_disconnect doesn't work yet so don't unref */
+		/*dbus_connection_unref (ctx->connection);*/
+	} else {
+		dbus_error_init (&myerror);
+		dbus_bus_remove_match (ctx->connection, 
+				       "type='signal',"
+				       "interface='org.freedesktop.Hal.Manager',"
+				       "sender='org.freedesktop.Hal',"
+				       "path='/org/freedesktop/Hal/Manager'", &myerror);
+		if (dbus_error_is_set (&myerror)) {
+			fprintf (stderr, "%s %d : Error unsubscribing to signals, error=%s\n", 
+				 __FILE__, __LINE__, error->message);
+			/** @todo  clean up */
+		}
 
-	/* TODO: remove other matches */
+		/* TODO: remove other matches */
 
-	dbus_connection_remove_filter (ctx->connection, filter_func, ctx);
+		dbus_connection_remove_filter (ctx->connection, filter_func, ctx);
+	}
 
 	ctx->is_initialized = FALSE;
 

Index: libhal.h
===================================================================
RCS file: /cvs/hal/hal/libhal/libhal.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- libhal.h	2 Mar 2005 19:19:13 -0000	1.25
+++ libhal.h	8 Apr 2005 18:10:20 -0000	1.26
@@ -152,6 +152,8 @@
 dbus_bool_t    libhal_ctx_shutdown                     (LibHalContext *ctx, DBusError *error);
 dbus_bool_t    libhal_ctx_free                         (LibHalContext *ctx);
 
+LibHalContext *libhal_ctx_init_direct                  (DBusError *error);
+
 
 char        **libhal_get_all_devices (LibHalContext *ctx, int *num_devices, DBusError *error);
 dbus_bool_t   libhal_device_exists   (LibHalContext *ctx, const char *udi,  DBusError *error);




More information about the hal-commit mailing list