From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Thu, 04 Mar 2004 12:42:23 +0000 Subject: [PATCH] conditional remove of trailing sysfs whitespace Message-Id: <20040304124223.GA16249@vrfy.org> MIME-Version: 1 Content-Type: multipart/mixed; boundary="zhXaljGHf11kAtnf" List-Id: To: linux-hotplug@vger.kernel.org --zhXaljGHf11kAtnf Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hey, it may never happen, that one wants to distinguish attributes by trailing spaces, but we should not lose the control over it, just for being lazy :) Here we remove the trailing spaces of the sysfs attribute only if the configured value to match doesn't have any trailing spaces by itself. So if you put a attribute in a rule with spaces at the end, the sysfs attribute _must_ match exactly. Is that cool for everyone? As usual, 2 tests are added for it with a artificial sysfs file and a few words to the man page. thanks, Kay --zhXaljGHf11kAtnf Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="03-trailing-attr-spaces.patch" diff -Nru a/namedev.c b/namedev.c --- a/namedev.c Thu Mar 4 13:38:53 2004 +++ b/namedev.c Thu Mar 4 13:38:53 2004 @@ -525,6 +525,8 @@ static int compare_sysfs_attribute(struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device, struct sysfs_pair *pair) { struct sysfs_attribute *tmpattr; + int i; + int len; if ((pair == NULL) || (pair->file[0] == '\0') || (pair->value == '\0')) return -ENODEV; @@ -532,6 +534,18 @@ tmpattr = find_sysfs_attribute(class_dev, sysfs_device, pair->file); if (tmpattr == NULL) return -ENODEV; + + /* strip trailing whitespace of value, if not asked to match for it */ + if (! isspace(pair->value[strlen(pair->value)-1])) { + i = len = strlen(tmpattr->value); + while (i > 0 && isspace(tmpattr->value[i-1])) + i--; + if (i < len) { + tmpattr->value[i] = '\0'; + dbg("remove %i trailing whitespace chars from '%s'", + len - i, tmpattr->value); + } + } dbg("compare attribute '%s' value '%s' with '%s'", pair->file, tmpattr->value, pair->value); diff -Nru a/test/sys/devices/pci0000:00/0000:00:1e.0/0000:02:05.0/host0/0:0:0:0/whitespace_test b/test/sys/devices/pci0000:00/0000:00:1e.0/0000:02:05.0/host0/0:0:0:0/whitespace_test --- /dev/null Wed Dec 31 16:00:00 1969 +++ b/test/sys/devices/pci0000:00/0000:00:1e.0/0000:02:05.0/host0/0:0:0:0/whitespace_test Thu Mar 4 13:38:53 2004 @@ -0,0 +1 @@ +WHITE SPACE diff -Nru a/test/udev-test.pl b/test/udev-test.pl --- a/test/udev-test.pl Thu Mar 4 13:38:53 2004 +++ b/test/udev-test.pl Thu Mar 4 13:38:53 2004 @@ -467,6 +467,25 @@ BUS="scsi", ID="0:0:0:0", NAME="bad" EOF }, + { + desc => "ignore SYSFS attribute whitespace", + subsys => "block", + devpath => "block/sda", + expected => "ignored", + conf => < "do not ignore SYSFS attribute whitespace", + subsys => "block", + devpath => "block/sda", + expected => "matched-with-space", + conf => <