hal/hald hald.c,1.31,1.32 util.c,1.7,1.8 util.h,1.6,1.7

David Zeuthen david at freedesktop.org
Mon Feb 28 11:43:31 PST 2005


Update of /cvs/hal/hal/hald
In directory gabe:/tmp/cvs-serv31423/hald

Modified Files:
	hald.c util.c util.h 
Log Message:
2005-02-28  David Zeuthen  <davidz at redhat.com>

	* tools/linux/hal_hotplug.c (main): Use "hal.hotplug" instead of 
	"hal.hotplug2" for syslog. Don't write a message for every entry.

	* hald/linux2/probing/probe-volume.c (main): Only probe for fs on
	optical disc if there is indeed data on the disc

	* hald/linux2/probing/probe-storage.c (main): Fix up debug outputs;
	don't read fs on cdrom's, only check if there is a disc. Don't use
	O_NONBLOCK on non-cdrom's.

	* hald/linux2/classdev.c (add_classdev_probing_helper_done): Handle
	that HalDevice object is already unreffed

	* hald/linux2/blockdev.c (add_blockdev_probing_helper_done): Handle
	that HalDevice object is already unreffed
	(block_rescan_storage_done): -do-

	* hald/util.h (struct HalHelperData_s): Add already_issued_kill field

	* hald/util.c (hal_util_terminate_helper): Don't kill helpers twice
	and don't callback more than once
	(helper_child_timeout): Don't callback more than once
	(helper_device_object_finalized): Finalized; being called when
	a HalDevice object is finalized; use this as hint to terminate
	the helper
	(helper_child_exited): Remove the weak reference to the HalDevice
	object
	(hal_util_helper_invoke): Create a weak reference to the HalDevice
	object so we get a callback when it's finalized

	* hald/hald.c (main): Bah, put LIBEXECDIR at the end so we get
	the local helpers when running via run-hald.sh



Index: hald.c
===================================================================
RCS file: /cvs/hal/hal/hald/hald.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- hald.c	28 Feb 2005 04:53:15 -0000	1.31
+++ hald.c	28 Feb 2005 19:43:29 -0000	1.32
@@ -416,12 +416,15 @@
 	else
 		hald_is_verbose = FALSE;
 
-	/* our helpers are installed into libexec, so adjust out $PATH to include this */
+	/* our helpers are installed into libexec, so adjust out $PATH
+	 * to include this at the end (since we want to overide in
+	 * run-hald.sh and friends)
+	 */
 	path = getenv ("PATH");
-	g_strlcpy (newpath, PACKAGE_LIBEXEC_DIR, sizeof (newpath));
+	g_strlcpy (newpath, path, sizeof (newpath));
 	if (path != NULL) {
 		g_strlcat (newpath, ":", sizeof (newpath));
-		g_strlcat (newpath, path, sizeof (newpath));
+		g_strlcat (newpath, PACKAGE_LIBEXEC_DIR, sizeof (newpath));
 	}
 	setenv ("PATH", newpath, TRUE);
 

Index: util.c
===================================================================
RCS file: /cvs/hal/hal/hald/util.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- util.c	28 Feb 2005 01:16:47 -0000	1.7
+++ util.c	28 Feb 2005 19:43:29 -0000	1.8
@@ -425,23 +425,31 @@
 void
 hal_util_terminate_helper (HalHelperData *ed)
 {
-	HAL_INFO (("killing %d for udi %s", ed->pid, ed->d->udi));
+	if (ed->already_issued_kill) {
+		HAL_INFO (("Already issued SIGTERM for pid %d, udi %s",
+			   ed->pid, ed->d != NULL ? ed->d->udi : "(finalized object)"));
+		goto out;
+	}
+
+	HAL_INFO (("killing %d for udi %s", ed->pid, ed->d != NULL ? ed->d->udi : "(finalized object)"));
 
 	/* kill kenny! kill it!! */
+	ed->already_issued_kill = TRUE;
 	kill (ed->pid, SIGTERM);
-	/* TODO: yikes; what about removing the zombie? */
 
 	if (ed->timeout_watch_id != (guint) -1) {
 		g_source_remove (ed->timeout_watch_id);
 		ed->timeout_watch_id = -1;
 	}
 
-	ed->already_issued_callback = TRUE;
-
-	ed->cb (ed->d, TRUE, -1, ed->data1, ed->data2, ed);
+	if (!ed->already_issued_callback) {
+		ed->already_issued_callback = TRUE;
+		ed->cb (ed->d, TRUE, -1, ed->data1, ed->data2, ed);
+	}
 
 	/* ed will be cleaned up when helper_child_exited reaps the child */
-	return;
+out:
+	;
 }
 
 static gboolean
@@ -452,12 +460,15 @@
 	HAL_INFO (("child timeout for pid %d", ed->pid));
 
 	/* kill kenny! kill it!! */
+	ed->already_issued_kill = TRUE;
 	kill (ed->pid, SIGTERM);
 
 	ed->timeout_watch_id = -1;
-	ed->already_issued_callback = TRUE;
 
-	ed->cb (ed->d, TRUE, -1, ed->data1, ed->data2, ed);
+	if (!ed->already_issued_callback) {
+		ed->already_issued_callback = TRUE;
+		ed->cb (ed->d, TRUE, -1, ed->data1, ed->data2, ed);
+	}
 
 	/* ed will be cleaned up when helper_child_exited reaps the child */
 	return FALSE;
@@ -466,6 +477,17 @@
 static GSList *running_helpers = NULL;
 
 static void 
+helper_device_object_finalized (gpointer data, GObject *where_the_object_was)
+{
+	HalHelperData *ed = (HalHelperData *) data;
+
+	HAL_INFO (("device object finalized for helper with pid %d", ed->pid));
+
+	ed->d = NULL;
+	hal_util_terminate_helper (ed);
+}
+
+static void 
 helper_child_exited (GPid pid, gint status, gpointer data)
 {
 	HalHelperData *ed = (HalHelperData *) data;
@@ -476,10 +498,14 @@
 		g_source_remove (ed->timeout_watch_id);
 	g_spawn_close_pid (ed->pid);
 
+	if (ed->d != NULL)
+		g_object_weak_unref (G_OBJECT (ed->d), helper_device_object_finalized, ed);
+
 	if (!ed->already_issued_callback)
 		ed->cb (ed->d, FALSE, WEXITSTATUS (status), ed->data1, ed->data2, ed);
 
-	running_helpers = g_slist_remove (running_helpers, ed);		
+	running_helpers = g_slist_remove (running_helpers, ed);
+
 	g_free (ed);
 }
 
@@ -513,7 +539,6 @@
 	return TRUE;
 }
 
-
 HalHelperData *
 hal_util_helper_invoke (const gchar *command_line, gchar **extra_env, HalDevice *d, 
 			gpointer data1, gpointer data2, HalHelperTerminatedCB cb, guint timeout)
@@ -534,6 +559,8 @@
 	ed->data2 = data2;
 	ed->d = d;
 	ed->cb = cb;
+	ed->already_issued_callback = FALSE;
+	ed->already_issued_kill = FALSE;
 
 	num_properties = hal_device_num_properties (d);
 	if (extra_env == NULL)
@@ -588,6 +615,11 @@
 				ed->timeout_watch_id = (guint) -1;
 
 			running_helpers = g_slist_prepend (running_helpers, ed);
+			/* device object may disappear from underneath us - this is
+			 * used to terminate the helper and pass d=NULL in the
+			 * HalHelperTerminatedCB callback
+			 */
+			g_object_weak_ref (G_OBJECT (d), helper_device_object_finalized, ed);
 		}
 	}
 

Index: util.h
===================================================================
RCS file: /cvs/hal/hal/hald/util.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- util.h	28 Feb 2005 01:16:47 -0000	1.6
+++ util.h	28 Feb 2005 19:43:29 -0000	1.7
@@ -93,6 +93,7 @@
 	HalDevice *d;
 
 	gboolean already_issued_callback;
+	gboolean already_issued_kill;
 };
 
 unsigned int hal_util_kill_all_helpers (void);




More information about the hal-commit mailing list