linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [udev] a bug / pattern match for label method
@ 2003-12-04  1:58 Kay Sievers
  0 siblings, 0 replies; 2+ messages in thread
From: Kay Sievers @ 2003-12-04  1:58 UTC (permalink / raw)
  To: linux-hotplug

[-- Attachment #1: Type: text/plain, Size: 1757 bytes --]

While I was adding pattern match to the LABEL method i hit a bug.
We modify a string returned from libsysfs, so with every iteration is is
truncated by one char:

Dec  4 02:27:16 pim udev[23307]: do_label: dev->bus='scsi' sysfs_device->bus='scsi'
Dec  4 02:27:16 pim udev[23307]: do_label: look for device attribute 'vendor'
Dec  4 02:27:16 pim udev[23307]: do_label: xxx 'IBM-ESXS '
Dec  4 02:27:16 pim udev[23307]: do_label: compare attribute 'vendor' value 'IBM-ESX' with '?IBM-ESXS'
Dec  4 02:27:16 pim udev[23307]: do_label: dev->bus='scsi' sysfs_device->bus='scsi'
Dec  4 02:27:16 pim udev[23307]: do_label: look for device attribute 'vendor'
Dec  4 02:27:16 pim udev[23307]: do_label: xxx 'IBM-ESX'
Dec  4 02:27:16 pim udev[23307]: do_label: compare attribute 'vendor' value 'IBM-ES' with 'IBM-ESXS?'
Dec  4 02:27:16 pim udev[23307]: do_label: dev->bus='scsi' sysfs_device->bus='scsi'
Dec  4 02:27:16 pim udev[23307]: do_label: look for device attribute 'vendor'
Dec  4 02:27:16 pim udev[23307]: do_label: xxx 'IBM-ES'
Dec  4 02:27:16 pim udev[23307]: do_label: compare attribute 'vendor' value 'IBM-E' with 'IBM-ES??'
Dec  4 02:27:16 pim udev[23307]: do_label: dev->bus='scsi' sysfs_device->bus='scsi'
Dec  4 02:27:16 pim udev[23307]: do_label: look for device attribute 'vendor'
Dec  4 02:27:16 pim udev[23307]: do_label: xxx 'IBM-E'
Dec  4 02:27:16 pim udev[23307]: do_label: compare attribute 'vendor' value 'IBM-' with 'IBM-ESXSS'

I changed the behavior to remove only the line feed.

thanks,
Kay




03-bug-in-linefeed-removal.diff
  remove only the line feed from string not every last char


04-patternmatch-for-label.diff
  switch LABEL search to pattern match
  add a test for pattern match in LABEL
  remove useless rule from udev.rules


[-- Attachment #2: 03-bug-in-linefeed-removal.diff --]
[-- Type: text/plain, Size: 1002 bytes --]

diff -Nru a/namedev.c b/namedev.c
--- a/namedev.c	Thu Dec  4 02:37:43 2003
+++ b/namedev.c	Thu Dec  4 02:37:43 2003
@@ -378,6 +378,7 @@
 	struct sysfs_attribute *tmpattr = NULL;
 	struct config_device *dev;
 	struct list_head *tmp;
+	char *c;
 
 	list_for_each(tmp, &config_device_list) {
 		dev = list_entry(tmp, struct config_device, node);
@@ -406,7 +407,9 @@
 		continue;
 
 label_found:
-		tmpattr->value[strlen(tmpattr->value)-1] = 0x00;
+		c = tmpattr->value + strlen(tmpattr->value)-1;
+		if (*c == '\n')
+			*c = 0x00;
 		dbg("compare attribute '%s' value '%s' with '%s'",
 			  dev->sysfs_file, tmpattr->value, dev->sysfs_value);
 		if (strcmp(dev->sysfs_value, tmpattr->value) != 0)
@@ -578,7 +581,7 @@
 			}
 		}
 	}
-		
+
 	if (sysfs_device) {
 		dbg("sysfs_device->path='%s'", sysfs_device->path);
 		dbg("sysfs_device->bus_id='%s'", sysfs_device->bus_id);
@@ -642,7 +645,7 @@
 int namedev_init(void)
 {
 	int retval;
-	
+
 	retval = namedev_init_rules();
 	if (retval)
 		return retval;

[-- Attachment #3: 04-patternmatc~or-label.diff --]
[-- Type: text/plain, Size: 1463 bytes --]

diff -Nru a/namedev.c b/namedev.c
--- a/namedev.c	Thu Dec  4 02:38:13 2003
+++ b/namedev.c	Thu Dec  4 02:38:13 2003
@@ -412,7 +412,7 @@
 			*c = 0x00;
 		dbg("compare attribute '%s' value '%s' with '%s'",
 			  dev->sysfs_file, tmpattr->value, dev->sysfs_value);
-		if (strcmp(dev->sysfs_value, tmpattr->value) != 0)
+		if (strcmp_pattern(dev->sysfs_value, tmpattr->value) != 0)
 			continue;
 
 		strfieldcpy(udev->name, dev->name);
diff -Nru a/test/udev-test.pl b/test/udev-test.pl
--- a/test/udev-test.pl	Thu Dec  4 02:38:13 2003
+++ b/test/udev-test.pl	Thu Dec  4 02:38:13 2003
@@ -52,6 +52,18 @@
 EOF
 	},
 	{
+		desc     => "label test of pattern match",
+		subsys   => "block",
+		devpath  => "block/sda/sda1",
+		expected => "boot_disk1" ,
+		conf     => <<EOF
+LABEL, BUS="scsi", vendor="?IBM-ESXS", NAME="boot_disk%n-1"
+LABEL, BUS="scsi", vendor="IBM-ESXS?", NAME="boot_disk%n-2"
+LABEL, BUS="scsi", vendor="IBM-ES??", NAME="boot_disk%n"
+LABEL, BUS="scsi", vendor="IBM-ESXSS", NAME="boot_disk%n-3"
+EOF
+	},
+	{
 		desc     => "catch device by *",
 		subsys   => "tty",
 		devpath  => "class/tty/ttyUSB0",
diff -Nru a/udev.rules b/udev.rules
--- a/udev.rules	Thu Dec  4 02:38:13 2003
+++ b/udev.rules	Thu Dec  4 02:38:13 2003
@@ -42,7 +42,6 @@
 REPLACE, KERNEL="ttyUSB0", NAME="pl2303"
 
 # a devfs like way to name some tty devices
-#REPLACE, KERNEL="tty", NAME="tty"
 #REPLACE, KERNEL="ttyS*", NAME="tts/%n"
 #REPLACE, KERNEL="tty*", NAME="vc/%n"
 

^ permalink raw reply	[flat|nested] 2+ messages in thread
* Re: [udev] a bug / pattern match for label method
@ 2003-12-04 19:24 Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2003-12-04 19:24 UTC (permalink / raw)
  To: linux-hotplug

On Thu, Dec 04, 2003 at 02:58:42AM +0100, Kay Sievers wrote:
> While I was adding pattern match to the LABEL method i hit a bug.
> We modify a string returned from libsysfs, so with every iteration is is
> truncated by one char:

ah, nice catch.

> 03-bug-in-linefeed-removal.diff
>   remove only the line feed from string not every last char
> 
> 
> 04-patternmatch-for-label.diff
>   switch LABEL search to pattern match
>   add a test for pattern match in LABEL
>   remove useless rule from udev.rules

Both of these are now applied, thanks.

greg k-h


-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id\x1278&alloc_id371&op=click
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-12-04 19:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-12-04  1:58 [udev] a bug / pattern match for label method Kay Sievers
  -- strict thread matches above, loose matches on Subject: below --
2003-12-04 19:24 Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).