hal/hald/linux hald_helper.h,1.5,1.6 osspec.c,1.48,1.49

David Zeuthen david at freedesktop.org
Mon Oct 18 15:52:07 PDT 2004


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

Modified Files:
	hald_helper.h osspec.c 
Log Message:
2004-10-18  David Zeuthen  <davidz at redhat.com>

	* hald/hald.c (main): Do openlog() so we can log to the syslog
	
	* hald/linux/hald_helper.h: Add a timestamp field
	
	* hald/linux/osspec.c:
	(osspec_timer_handler): Call hotplug_timeout_handler
	(hotplug_timeout_handler): New function
	(hald_helper_hotplug_process_queue): Set last timestamp and add
	 uncommented test code for dropping every 16th hotplug event
	(hald_helper_first_hotplug_event): Update last timestamp
	
	* tools/linux/hal_dev.c (main): Set timestamp
	
	* tools/linux/hal_hotplug.c (main): Set timestamp



Index: hald_helper.h
===================================================================
RCS file: /cvs/hal/hal/hald/linux/hald_helper.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- hald_helper.h	16 Sep 2004 22:04:15 -0000	1.5
+++ hald_helper.h	18 Oct 2004 22:52:05 -0000	1.6
@@ -44,7 +44,8 @@
 	char subsystem[HALD_HELPER_STRLEN];	/**< subsystem e.g. usb, pci (only for hotplug msg) */
 	char sysfs_path[HALD_HELPER_STRLEN];	/**< path into sysfs without sysfs mountpoint, e.g. /block/sda */
 	char device_name[HALD_HELPER_STRLEN];	/**< absolute path of device node (only for device msg) */
-	int net_ifindex;                       /**< For networking class devices only; the value of the ifindex file */
+	int net_ifindex;                        /**< For networking class devices only; the value of the ifindex file*/
+	time_t time_stamp;                      /**< Time of day we received the hotplug event */
 };
 
 #endif /* HALD_HELPER_H */

Index: osspec.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/osspec.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- osspec.c	14 Oct 2004 18:37:28 -0000	1.48
+++ osspec.c	18 Oct 2004 22:52:05 -0000	1.49
@@ -37,10 +37,12 @@
 #include <unistd.h>
 #include <stdarg.h>
 #include <errno.h>
+#include <syslog.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <sys/utsname.h>
+#include <time.h>
 
 #include <glib.h>
 #include <dbus/dbus.h>
@@ -60,8 +62,12 @@
 
 #include "libsysfs/libsysfs.h"
 
+/** How many ms to sleep on first hotplug event (to queue up other hotplug events) */
 #define FIRST_HOTPLUG_SLEEP 3500
 
+/** How many seconds before we discard a missing hotplug event and move on to the next one */
+#define HOTPLUG_TIMEOUT 15
+
 extern ClassDeviceHandler input_class_handler;
 extern ClassDeviceHandler net_class_handler;
 extern ClassDeviceHandler printer_class_handler;
@@ -133,6 +139,8 @@
 
 static HalDevice *add_device (const char *sysfs_path, const char *subsystem, struct hald_helper_msg *msg);
 
+static void hotplug_timeout_handler (void);
+
 /** Mount path for sysfs */
 char sysfs_mount_path[SYSFS_PATH_MAX];
 
@@ -156,6 +164,8 @@
 		ch->tick (ch);
 	}
 
+	hotplug_timeout_handler ();
+
 	return TRUE;
 }
 
@@ -1394,6 +1404,9 @@
 /** Last hotplug sequence number */
 static guint64 last_hotplug_seqnum = 0;
 
+/** Timestamp of last hotplug */
+static time_t last_hotplug_time_stamp = 0;
+
 /** Hotplug semaphore */
 static gint hotplug_counter = 0;
 
@@ -1435,6 +1448,7 @@
 		if (msg->seqnum == last_hotplug_seqnum + 1) {
 			/* yup, found it */
 			last_hotplug_seqnum = msg->seqnum;
+			last_hotplug_time_stamp = msg->time_stamp;
 			hald_helper_hotplug (msg->action, msg->seqnum, g_strdup (msg->subsystem), 
 					     g_strdup (msg->sysfs_path), msg);
 			g_free (msg);
@@ -1444,6 +1458,32 @@
 	}
 }
 
+/** Check the queue and do timeout handling on missing hotplug events */
+static void 
+hotplug_timeout_handler (void)
+{
+	time_t now;
+
+	now = time (NULL);
+
+	/* See if there was a last hotplug event */
+	if (last_hotplug_time_stamp > 0) {
+		/* See if it's too long ago we processed */
+		if (now - last_hotplug_time_stamp > HOTPLUG_TIMEOUT) {
+			/* And if anything is actually waiting to be processed */
+			if (hotplug_queue != NULL) {
+				/* also log this to syslog */
+				syslog (LOG_ERR, "Timed out waiting for hotplug event %lld", last_hotplug_seqnum + 1);
+				HAL_ERROR (("Timed out waiting for hotplug event %lld", last_hotplug_seqnum + 1));
+				
+				/* Go to next seqnum and try again */
+				last_hotplug_seqnum++;
+				hald_helper_hotplug_process_queue ();
+			}
+		}
+	}
+}
+
 /** Increment the hotplug semaphore; useful when not wanting to process
  *  hotplug events for a while, like when e.g. adding a hal device
  *  object (which is an asynchronous operation).
@@ -1505,6 +1545,7 @@
 		msg = (struct hald_helper_msg *) i->data;
 		HAL_INFO (("*** msg->seqnum = %lld", msg->seqnum));
 		last_hotplug_seqnum = msg->seqnum;
+		last_hotplug_time_stamp = msg->time_stamp;
 	}
 
 	/* Done sleeping on the first hotplug event */
@@ -1576,6 +1617,20 @@
 		goto out;
 	}
 
+	HAL_INFO (("SEQNUM=%lld, TIMESTAMP=%d", msg.seqnum, msg.time_stamp));
+
+	/* For DEBUG: Drop every 16th hotplug event */
+#if 0
+	if ((msg.seqnum&0x0f) == 0x00) {
+		HAL_INFO (("=========================================="));
+		HAL_INFO (("=========================================="));
+		HAL_INFO (("NOTE NOTE: For debugging, deliberately ignoring hotplug event with SEQNUM=%d", msg.seqnum));
+		HAL_INFO (("=========================================="));
+		HAL_INFO (("=========================================="));
+		goto out;
+	}
+#endif
+
 	switch (msg.type) {
 	case HALD_DEVD:
 		hald_helper_device_name (msg.action, msg.seqnum, g_strdup (msg.subsystem),
@@ -1608,6 +1663,7 @@
 
 			/* so we only setup one timer */
 			last_hotplug_seqnum = msg.seqnum;
+			last_hotplug_time_stamp = msg.time_stamp;
 
 			goto out;
 		}




More information about the hal-commit mailing list