Skip to contentSkip to conversation

allow udev to process all symlink rules for a device

PATCH In review Kevin P. Fleming 2 participants 3 messages May 8, 2004 – May 20, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 allow udev to process all symlink rules for a device

This patch changes udev's behavior to scan all rules for every device. Only the first NAME rule is accepted, but all SYMLINK rules are accepted. This means that SYMLINK rules can be added in any position to a udev.rules file (or in the rules.d directory) without concern for where they are in relation to the NAME rule for the same device.

namedev.c +17 -9
@@ -780,6 +780,7 @@
 	struct perm_device *perm;
 	struct sysinfo info;
 	char *pos;
+	int name_rule_found = 0;
 
 	udev->mode = 0;
 
@@ -805,7 +806,9 @@
 	strfieldcpy(udev->kernel_number, pos);
 	dbg("kernel_number='%s'", udev->kernel_number);
 
-	/* look for a matching rule to apply */
+	/* look for matching rules to apply */
+	/* only the first matching NAME rule will be used */
+	/* all matching SYMLINK rules will be used */
 	list_for_each_entry(dev, &config_device_list, node) {
 		dbg("process rule");
 		if (match_rule(dev, class_dev, udev, sysfs_device) == 0) {
@@ -827,6 +830,9 @@
 				strfieldcat(udev->symlink, temp);
 			}
 
+			if (name_rule_found)
+			  continue;
+
 			if (dev->name[0] != '\0') {
 				/* apply all_partitions flag only at a main block device */
 				if (dev->partitions > 0 &&
@@ -836,18 +842,20 @@
 				info("configured rule in '%s' at line %i applied, '%s' becomes '%s'",
 				     dev->config_file, dev->config_line, udev->kernel_name, dev->name);
 				strfieldcpy(udev->name, dev->name);
-				goto found;
+				name_rule_found = 1;
 			}
 		}
 	}
-	/* no rule was found so we use the kernel name */
-	strfieldcpy(udev->name, udev->kernel_name);
-	if (udev->type == 'n')
-		goto done;
-	else
-		goto perms;
 
-found:
+	if (!name_rule_found) {
+		/* no NAME rule was found so we use the kernel name */
+		strfieldcpy(udev->name, udev->kernel_name);
+		if (udev->type == 'n')
+			goto done;
+		else
+			goto perms;
+	}
+
 	apply_format(udev, udev->name, sizeof(udev->name), class_dev, sysfs_device);
 	strfieldcpy(udev->config_file, dev->config_file);
 	udev->config_line = dev->config_line;
#1 lore raw
Quoted 5 lines · Kevin P. Fleming

This patch changes udev's behavior to scan all rules for every device. Only the first NAME rule is accepted, but all SYMLINK rules are accepted. This means that SYMLINK rules can be added in any position to a udev.rules file (or in the rules.d directory) without concern for where they are in relation to the NAME rule for the same device.

I like the idea, unfortunatly your patch breaks a number of the regression tests. Can you try fixing it so that the udev-test.pl script in the test directory does not fail?

thanks,

greg k-h

-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id149&alloc_id�66&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#2 lore raw
In reply to Kevin P. Fleming
Quoted 3 lines · Greg KH

I like the idea, unfortunatly your patch breaks a number of the regression tests. Can you try fixing it so that the udev-test.pl script in the test directory does not fail?

I will make the attempt :-)

-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id149&alloc_id�66&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel