summaryrefslogtreecommitdiff
path: root/namedev.c
diff options
context:
space:
mode:
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>2004-03-04 18:59:13 -0800
committerGreg KH <gregkh@suse.de>2005-04-26 21:35:08 -0700
commitd5f91372dd3241f8b4bbe2a99aaaeda541a76bad (patch)
tree196ca6a32c2c9ba4b6fb4b2cedfe4abb309e8aa5 /namedev.c
parentebc39fefd5cb8249cd09d4b3d1b8c72c9e48bab1 (diff)
[PATCH] conditional remove of trailing sysfs whitespace
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.
Diffstat (limited to 'namedev.c')
-rw-r--r--namedev.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/namedev.c b/namedev.c
index 9182ed1fdc..dfeadee18a 100644
--- a/namedev.c
+++ b/namedev.c
@@ -525,6 +525,8 @@ attr_found:
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;
@@ -533,6 +535,18 @@ static int compare_sysfs_attribute(struct sysfs_class_device *class_dev, struct
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);
if (strcmp_pattern(pair->value, tmpattr->value) != 0)