hal/tools/linux hal_dev.c,1.6,1.7 hal_hotplug.c,1.21,1.22

Kay Sievers kay at freedesktop.org
Tue Sep 14 05:26:26 PDT 2004


Update of /cvs/hal/hal/tools/linux
In directory gabe:/tmp/cvs-serv2334/tools/linux

Modified Files:
	hal_dev.c hal_hotplug.c 
Log Message:
2004-09-14  Kay Sievers  <kay.sievers at vrfy.org>

        Change Hotplug handling to better match the kernel. The next kernel
        version will have a u64 hotplug sequence number starting at 1.
        We can't be sure, that an ACTION != "add" is everytime a "remove" event,
        change that to pass the action string around instead of the flag.

        * hald/linux/hald_helper.h:
        * hald/linux/osspec.c:
        * tools/linux/hal_dev.c:
        * tools/linux/hal_hotplug.c:
        Change the hal_message structure to carry the u64 sequence number
        and the ACTION as a string. Change message type to an enum. Rename
        devnode to devname to match the udev name.
        Use the u64 sequence number and change the logic not to rely on
        negative numbers. The first sequence number will never be 0 in the
        kernel, so we use it if we don't get one from udev.



Index: hal_dev.c
===================================================================
RCS file: /cvs/hal/hal/tools/linux/hal_dev.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- hal_dev.c	29 Aug 2004 15:57:41 -0000	1.6
+++ hal_dev.c	14 Sep 2004 12:26:24 -0000	1.7
@@ -65,10 +65,9 @@
 	socklen_t addrlen;
 	char *subsystem;
 	char *devpath;
-	char *devnode;
+	char *devname;
 	char *action;
 	char *seqnum_str;
-	int is_add;
 	int seqnum;
 
 	openlog ("hal.dev", LOG_PID, LOG_USER);
@@ -92,8 +91,8 @@
 		goto out;
 	}
 
-	devnode = getenv ("DEVNAME");
-	if (devnode == NULL) {
+	devname = getenv ("DEVNAME");
+	if (devname == NULL) {
 		syslog (LOG_ERR, "DEVNAME is not set");
 		goto out;
 	}
@@ -103,16 +102,12 @@
 		syslog (LOG_ERR, "ACTION is not set");
 		goto out;
 	}
-	if (strcmp (action, "add") == 0)
-		is_add = 1;
-	else
-		is_add = 0;
 
 	seqnum_str = getenv ("SEQNUM");
 	if (seqnum_str == NULL) {
-		seqnum = -1;
+		seqnum = 0;
 	} else {
-		seqnum = atoi (seqnum_str);
+		seqnum = strtoull (seqnum_str, NULL, 10);
 	}
 
 
@@ -130,12 +125,12 @@
 
 	memset (&msg, 0x00, sizeof (msg));
 	msg.magic = HALD_HELPER_MAGIC; 
-	msg.is_hotplug_or_dev = 0;
-	msg.is_add = is_add;
+	msg.type = HALD_DEVD;
 	msg.seqnum = seqnum;
-	strncpy (msg.subsystem, subsystem, HALD_HELPER_STRLEN);
-	strncpy (msg.sysfs_path, devpath, HALD_HELPER_STRLEN);
-	strncpy (msg.device_node, devnode, HALD_HELPER_STRLEN);
+	strncpy (msg.action, action, HALD_HELPER_STRLEN-1);
+	strncpy (msg.subsystem, subsystem, HALD_HELPER_STRLEN-1);
+	strncpy (msg.sysfs_path, devpath, HALD_HELPER_STRLEN-1);
+	strncpy (msg.device_name, devname, HALD_HELPER_STRLEN-1);
 
 	if (sendto (fd, &msg, sizeof(struct hald_helper_msg), 0,
 		    (struct sockaddr *)&saddr, addrlen) == -1) {

Index: hal_hotplug.c
===================================================================
RCS file: /cvs/hal/hal/tools/linux/hal_hotplug.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- hal_hotplug.c	31 Aug 2004 22:55:44 -0000	1.21
+++ hal_hotplug.c	14 Sep 2004 12:26:24 -0000	1.22
@@ -241,7 +241,7 @@
 
 		if (rc != 0)
 			goto try_again;
-	}	
+	}
 	return 0;
 }
 
@@ -263,8 +263,7 @@
 	char *devpath;
 	char *action;
 	char *seqnum_str;
-	int is_add;
-	int seqnum;
+	unsigned long long seqnum;
 
 	if (argc != 2)
 		return 1;
@@ -299,22 +298,17 @@
 		syslog (LOG_ERR, "ACTION is not set");
 		goto out;
 	}
-	if (strcmp (action, "add") == 0)
-		is_add = 1;
-	else
-		is_add = 0;
 
 	seqnum_str = getenv ("SEQNUM");
 	if (seqnum_str == NULL) {
 		syslog (LOG_ERR, "SEQNUM is not set");
 		goto out;
 	}
-	seqnum = atoi (seqnum_str);
+	seqnum = strtoull (seqnum_str, NULL, 10);
 
-	if (is_add) {
-		/* wait for information to be published in sysfs */
+	/* wait for information to be published in sysfs */
+	if (strcmp (action, "add") == 0)
 		wait_for_sysfs_info (devpath, subsystem);
-	}
 
 	memset (&saddr, 0x00, sizeof(struct sockaddr_un));
 	saddr.sun_family = AF_LOCAL;
@@ -324,11 +318,11 @@
 
 	memset (&msg, 0x00, sizeof (msg));
 	msg.magic = HALD_HELPER_MAGIC; 
-	msg.is_hotplug_or_dev = 1;
-	msg.is_add = is_add;
+	msg.type = HALD_HOTPLUG;
 	msg.seqnum = seqnum;
-	strncpy (msg.subsystem, subsystem, HALD_HELPER_STRLEN);
-	strncpy (msg.sysfs_path, devpath, HALD_HELPER_STRLEN);
+	strncpy (msg.action, action, HALD_HELPER_STRLEN-1);
+	strncpy (msg.subsystem, subsystem, HALD_HELPER_STRLEN-1);
+	strncpy (msg.sysfs_path, devpath, HALD_HELPER_STRLEN-1);
 
 	if (sendto (fd, &msg, sizeof(struct hald_helper_msg), 0,
 		    (struct sockaddr *)&saddr, addrlen) == -1) {
@@ -339,4 +333,3 @@
 out:
 	return 0;
 }
-




More information about the hal-commit mailing list