* [PATCH] conditional remove of trailing sysfs whitespace
@ 2004-03-04 12:42 Kay Sievers
2004-03-04 17:07 ` Richard Troth
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Kay Sievers @ 2004-03-04 12:42 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 537 bytes --]
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
[-- Attachment #2: 03-trailing-attr-spaces.patch --]
[-- Type: text/plain, Size: 2790 bytes --]
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 => <<EOF
+BUS="scsi", SYSFS{whitespace_test}="WHITE SPACE", NAME="ignored"
+EOF
+ },
+ {
+ desc => "do not ignore SYSFS attribute whitespace",
+ subsys => "block",
+ devpath => "block/sda",
+ expected => "matched-with-space",
+ conf => <<EOF
+BUS="scsi", SYSFS{whitespace_test}="WHITE SPACE ", NAME="wrong-to-ignore"
+BUS="scsi", SYSFS{whitespace_test}="WHITE SPACE ", NAME="matched-with-space"
+EOF
+ },
);
# set env
diff -Nru a/udev.8 b/udev.8
--- a/udev.8 Thu Mar 4 13:38:53 2004
+++ b/udev.8 Thu Mar 4 13:38:53 2004
@@ -178,6 +178,9 @@
Match sysfs device attribute like label, vendor, USB serial number, SCSI UUID
or file system label. Up to 5 different sysfs files can be checked, with
all of the values being required in order to match the rule.
+.br
+Trailing whitespace characters in the sysfs attribute value are ignored, if
+the key doesn't have any trailing whitespace characters by itself.
.TP
.B PROGRAM
Call external program. This key is valid if the program returns successful.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] conditional remove of trailing sysfs whitespace
2004-03-04 12:42 [PATCH] conditional remove of trailing sysfs whitespace Kay Sievers
@ 2004-03-04 17:07 ` Richard Troth
2004-03-04 19:03 ` Greg KH
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Richard Troth @ 2004-03-04 17:07 UTC (permalink / raw)
To: linux-hotplug
> 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.
THANK YOU!
That is (IMHO) the right way to do it.
But I deeply agree with your first phrase:
> Hey, it may never happen, that one wants to distinguish attributes by
> trailing spaces, ...
Amen!
-- R;
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&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] 5+ messages in thread
* Re: [PATCH] conditional remove of trailing sysfs whitespace
2004-03-04 12:42 [PATCH] conditional remove of trailing sysfs whitespace Kay Sievers
2004-03-04 17:07 ` Richard Troth
@ 2004-03-04 19:03 ` Greg KH
2004-03-04 20:05 ` Raf D'Halleweyn
2004-03-04 20:11 ` Greg KH
3 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2004-03-04 19:03 UTC (permalink / raw)
To: linux-hotplug
On Thu, Mar 04, 2004 at 01:42:23PM +0100, Kay Sievers wrote:
> 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.
Very nice solution. This should make everyone happen, as it will "just
work" for whatever people want it to do, no config option needed.
thanks so much,
greg k-h
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&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] 5+ messages in thread
* Re: [PATCH] conditional remove of trailing sysfs whitespace
2004-03-04 12:42 [PATCH] conditional remove of trailing sysfs whitespace Kay Sievers
2004-03-04 17:07 ` Richard Troth
2004-03-04 19:03 ` Greg KH
@ 2004-03-04 20:05 ` Raf D'Halleweyn
2004-03-04 20:11 ` Greg KH
3 siblings, 0 replies; 5+ messages in thread
From: Raf D'Halleweyn @ 2004-03-04 20:05 UTC (permalink / raw)
To: linux-hotplug
Except if you have two devices with "Vendor" and "Vendor "...
Raf.
On Thu, 2004-03-04 at 14:03, Greg KH wrote:
> On Thu, Mar 04, 2004 at 01:42:23PM +0100, Kay Sievers wrote:
> > 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.
>
> Very nice solution. This should make everyone happen, as it will "just
> work" for whatever people want it to do, no config option needed.
>
> thanks so much,
>
> greg k-h
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&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] 5+ messages in thread
* Re: [PATCH] conditional remove of trailing sysfs whitespace
2004-03-04 12:42 [PATCH] conditional remove of trailing sysfs whitespace Kay Sievers
` (2 preceding siblings ...)
2004-03-04 20:05 ` Raf D'Halleweyn
@ 2004-03-04 20:11 ` Greg KH
3 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2004-03-04 20:11 UTC (permalink / raw)
To: linux-hotplug
On Thu, Mar 04, 2004 at 03:05:27PM -0500, Raf D'Halleweyn wrote:
>
> Except if you have two devices with "Vendor" and "Vendor "...
Have you ever seen such a thing?
thanks,
greg k-h
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&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] 5+ messages in thread
end of thread, other threads:[~2004-03-04 20:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-04 12:42 [PATCH] conditional remove of trailing sysfs whitespace Kay Sievers
2004-03-04 17:07 ` Richard Troth
2004-03-04 19:03 ` Greg KH
2004-03-04 20:05 ` Raf D'Halleweyn
2004-03-04 20:11 ` 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).