hal/hald callout.c,1.15.2.2,1.15.2.3

David Zeuthen david at freedesktop.org
Wed Jan 12 09:38:46 PST 2005


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

Modified Files:
      Tag: hal-0_4-stable-branch
	callout.c 
Log Message:
2005-01-12  David Zeuthen  <davidz at redhat.com>

	* hald/linux/osspec.c (HOTPLUG_TIMEOUT): Increase to 25 seconds
	to better cope with callouts timeout of 10 seconds

	* hald/callout.c (iochn_data): Cope with callouts terminating
	and free timeout handler
	(callout_timeout_handler): New function; kill callouts if they
	time out
	(process_next_callout): Setup timeout for callouts - set to
	ten seconds



Index: callout.c
===================================================================
RCS file: /cvs/hal/hal/hald/callout.c,v
retrieving revision 1.15.2.2
retrieving revision 1.15.2.3
diff -u -d -r1.15.2.2 -r1.15.2.3
--- callout.c	11 Jan 2005 06:45:00 -0000	1.15.2.2
+++ callout.c	12 Jan 2005 17:38:44 -0000	1.15.2.3
@@ -56,6 +56,7 @@
 	int envp_index;
 	pid_t pid;
 	gboolean last_of_device;
+	guint timeout_id;
 } Callout;
 
 static void process_next_callout (void);
@@ -144,6 +145,7 @@
 	gchar data[1];
 	GError *err = NULL;
 	pid_t child_pid;
+	Callout *previous_callout;
 
 	/* Empty the pipe; one character per dead child */
 	if (G_IO_STATUS_NORMAL != 
@@ -170,24 +172,32 @@
 
 		HAL_INFO (("Child pid %d terminated", child_pid));
 
+		if (active_callout == NULL) {
+			HAL_ERROR (("No active callout for child with pid %d - did it timeout?", child_pid));
+			goto out;
+		}
+
 		if (active_callout->pid != child_pid) {
 			/* this should never happen */
-			HAL_ERROR (("Cannot find callout for terminated "
-				    "child with pid %d", child_pid));
+			HAL_ERROR (("Cannot find callout for terminated child with pid %d", child_pid));
 			goto out;
 		}
 
-		if (active_callout->last_of_device) {
-			hal_device_callouts_finished (active_callout->device);
-			HAL_INFO (("fooo!"));
+		previous_callout = active_callout;
+		active_callout = NULL;
+
+		g_source_remove (previous_callout->timeout_id);
+
+		if (previous_callout->last_of_device) {
+			hal_device_callouts_finished (previous_callout->device);
+			HAL_INFO (("Callouts done for %s", previous_callout->device->udi));
 		}
 		
-		g_free (active_callout->filename);
-		g_strfreev (active_callout->envp);
-		g_object_unref (active_callout->device);
-		g_free (active_callout);
 
-		active_callout = NULL;
+		g_free (previous_callout->filename);
+		g_strfreev (previous_callout->envp);
+		g_object_unref (previous_callout->device);
+		g_free (previous_callout);
 		
 		process_next_callout ();
 	}
@@ -196,6 +206,38 @@
 	return TRUE;
 }
 
+#define CALLOUT_TIMEOUT 10000
+
+static gboolean
+callout_timeout_handler (gpointer data)
+{
+	Callout *callout;
+
+	callout = (Callout *) data;
+	
+	HAL_WARNING (("Timeout (%d ms) for callout %s", CALLOUT_TIMEOUT, callout->filename));
+
+	/* kill the child.. kill it! */
+	kill (callout->pid, SIGTERM);
+
+	active_callout = NULL;
+
+	if (callout->last_of_device) {
+		hal_device_callouts_finished (callout->device);
+		HAL_INFO (("Callouts done for %s", callout->device->udi));
+	}
+	
+	
+	g_free (callout->filename);
+	g_strfreev (callout->envp);
+	g_object_unref (callout->device);
+	g_free (callout);
+
+	process_next_callout ();
+
+	return FALSE;
+}
+
 static void
 process_next_callout (void)
 {
@@ -270,6 +312,9 @@
 	 */
 	callout->envp[callout->envp_index] = NULL;
 
+	/* Setup timer for timeouts - ten seconds */
+	callout->timeout_id = g_timeout_add (CALLOUT_TIMEOUT, callout_timeout_handler, (gpointer) callout);
+
 	HAL_INFO (("Invoking %s/%s", callout->working_dir, argv[0]));
 
 	if (!g_spawn_async (callout->working_dir, argv, callout->envp,
@@ -278,6 +323,7 @@
 		HAL_WARNING (("Couldn't invoke %s: %s", argv[0],
 			      err->message));
 		g_error_free (err);
+		g_source_remove (callout->timeout_id);
 		active_callout = NULL;
 		goto next_callout;
 	} else {




More information about the hal-commit mailing list