hal/libhal libhal.c,1.27,1.28

David Zeuthen david at freedesktop.org
Mon Sep 27 07:49:48 PDT 2004


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

Modified Files:
	libhal.c 
Log Message:
2004-09-27  David Zeuthen  <david at fubar.dk>

	* libhal/libhal.c:
	(struct LibHalContext_s): add is_shutdown field
	(filter_func): if ctx->is_shutdown is TRUE don't process the message.
	Return NOT_YET_HANDLED instead of HANDLED on all messages as several
	libhal contexts may want to process them.
	(hal_initialize): Set ctx->is_shutdown to FALSE
	(hal_shutdown): Remove the matching rule on the Manager object and
	set is_shutdown to TRUE. Don't fix the leak on the DBusConnection
	because leaking it means that the application will terminate. Hence
	introduce a leak of the LibHalContext since shutdown is async. Add
	a few TODO comments about that this needs fixing (probably needs
	dbus_bus_get_dedicated).

	* hald/hald_dbus.c (sender_has_superuser_privileges): New function
	(device_set_property): Require superuser
	(device_add_capability): Require superuser

	* hald/linux/block_class_device.c (block_class_pre_process): Add checks
	for SATA disks - code snippet from Alan Cox <alan at redhat.com>



Index: libhal.c
===================================================================
RCS file: /cvs/hal/hal/libhal/libhal.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- libhal.c	23 Sep 2004 18:13:45 -0000	1.27
+++ libhal.c	27 Sep 2004 14:49:45 -0000	1.28
@@ -123,6 +123,7 @@
 struct LibHalContext_s {
 	DBusConnection *connection;           /**< D-BUS connection */
 	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 */
 	const LibHalFunctions *functions;     /**< Callback functions */
 	void *user_data;                      /**< User data */
@@ -451,6 +452,9 @@
 	DBusError error;
 	LibHalContext *ctx = (LibHalContext *) user_data;
 
+	if (ctx->is_shutdown)
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
 	dbus_error_init (&error);
 
 	object_path = dbus_message_get_path (message);
@@ -468,7 +472,7 @@
 			}
 			dbus_free (udi);
 		}
-		return DBUS_HANDLER_RESULT_HANDLED;
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 	} else
 	    if (dbus_message_is_signal
 		(message, "org.freedesktop.Hal.Manager",
@@ -482,7 +486,7 @@
 			}
 			dbus_free (udi);
 		}
-		return DBUS_HANDLER_RESULT_HANDLED;
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 	} else
 	    if (dbus_message_is_signal
 		(message, "org.freedesktop.Hal.Manager",
@@ -501,7 +505,7 @@
 			dbus_free (udi);
 			dbus_free (capability);
 		}
-		return DBUS_HANDLER_RESULT_HANDLED;
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 	} else
 	    if (dbus_message_is_signal
 		(message, "org.freedesktop.Hal.Device", "Condition")) {
@@ -520,7 +524,7 @@
 
 			dbus_free (condition_name);
 		}
-		return DBUS_HANDLER_RESULT_HANDLED;
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 	} else
 	    if (dbus_message_is_signal
 		(message, "org.freedesktop.Hal.Device",
@@ -559,7 +563,7 @@
 			}
 
 		}
-		return DBUS_HANDLER_RESULT_HANDLED;
+		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 	}
 
 	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@ -618,6 +622,9 @@
 		return NULL;
 	}
 
+	ctx->is_initialized = FALSE;
+	ctx->is_shutdown = FALSE;
+
 	ctx->cache_enabled = use_cache;
 
 	ctx->functions = cb_functions;
@@ -664,6 +671,7 @@
 	}
 
 	ctx->is_initialized = TRUE;
+	ctx->is_shutdown = TRUE;
 
 	return ctx;
 }
@@ -680,8 +688,36 @@
 	if (!ctx->is_initialized)
 		return 1;
 
-	/** @todo cleanup */
-	free (ctx);
+	/* unsubscribe the match rule we added in initialize; this is safe even with multiple
+	 * instances of libhal running - see the dbus docs */
+	dbus_bus_remove_match (ctx->connection,
+			       "type='signal',"
+			       "interface='org.freedesktop.Hal.Manager',"
+			       "sender='org.freedesktop.Hal',"
+			       "path='/org/freedesktop/Hal/Manager'", &error);
+	if (dbus_error_is_set (&error)) {
+		fprintf (stderr, "%s %d : Error removing match rule, error=%s\r\n",
+			 __FILE__, __LINE__, error.message);
+	}
+
+	/* TODO: remove all other match rules */
+
+	/* set a flag so we don't propagte callbacks from this context anymore */
+	ctx->is_shutdown = TRUE;
+
+	/* yikes, it's dangerous to unref the connection since it will terminate the process
+	 * because this connection may be shared so we cannot set the exit_on_disconnect flag
+	 *
+	 * so we don't do that right now 
+	 *
+	 */
+	/*dbus_connection_unref (ctx->connection);*/
+
+	/* we also refuse to free the resources as filter_function may reference these 
+	 * 
+	 * should free async when our connection goes away.
+	 */
+	/* free (ctx); */
 	return 0;
 }
 




More information about the hal-commit mailing list