From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Patterson Date: Wed, 13 Oct 2004 23:13:12 +0000 Subject: Re: Problem parsing %s in udev rules Message-Id: <1097709193.13774.69.camel@bluto.andrew> MIME-Version: 1 Content-Type: multipart/mixed; boundary="=-1y5tSakYGvzUlMfJuNde" List-Id: References: <1097105584.9273.9.camel@bluto.andrew> In-Reply-To: <1097105584.9273.9.camel@bluto.andrew> To: linux-hotplug@vger.kernel.org --=-1y5tSakYGvzUlMfJuNde Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Tue, 2004-10-12 at 16:58 -0700, Greg KH wrote: > On Tue, Oct 12, 2004 at 05:04:21PM -0600, Andrew Patterson wrote: > > Kay, > >=20 > > On Thu, 2004-10-07 at 02:30 +0200, Kay Sievers wrote: > > > On Wed, Oct 06, 2004 at 06:23:05PM -0600, Andrew Patterson wrote: > > > > On Thu, 2004-10-07 at 01:50 +0200, Kay Sievers wrote: > > > > > On Wed, Oct 06, 2004 at 05:33:04PM -0600, Andrew Patterson wrote: > > > > > > Udev seems to be chopping off anything seen in a rule after a %= s. For > > > > > > example, if I have the following rule: > > > > > >=20 > > > > > > BUS=3D"scsi", KERNEL=3D"sd*", PROGRAM=3D"/sbin/scsi_id", NAME= =3D"%k", > > > > > > SYMLINK=3D"scsi_disks/some-proceeding-stuff-%s{model}-some-foll= owing- > > > > > > stuff" > > > > > >=20 > > > > > > Everything after the %s{model} is ignored. > > > > > >=20 > > > > > > Furthermore, everything in model following whitespace is ignore= d as > > > > > > well. I.e, if model contains "HP 34.7G", the resulting device = file > > > > > > created is /dev/scsi_disks/some-proceeding-stuff-HP. > > > > > >=20 > > > > > > I used the following command to run this test: > > > > > >=20 > > > > > > # DEVPATH=3D/block/sda ACTION=3Dadd ./udev block > > > > > >=20 > > > > > > I also get the same behavior when using udevstart (patched to f= ix > > > > > > parameter passing problems). > > > > >=20 > > > > > If your sysfs value contains spaces, which is the delimiter for m= ultiple > > > > > symlinks, it will not work. > > > > >=20 > > > > > udev can't do this now, you need to wrap the call with an externa= l script, > > > > > which ensures sane values. > > > > >=20 > > > >=20 > > > > That explains the spaces. What about stuff trailing %s, if %s does= not > > > > contain spaces. I.e, in the above example, model is ST336753LC and= the > > > > resulting device file is /dev/scsi_disks/some-proceding-stuff- > > > > ST336753LC. > > >=20 > > > I expect the model value has trailing spaces. > > >=20 > > > You may look with: > > > udevinfo -a -p /block/sdX > >=20 > > Yes it does, and it seems for most SCSI devices, vendor and model will > > have trailing spaces. >=20 > It all depends on the vendor and model :) >=20 > > I have included a patch to udev-036 to deal with > > this issue. It trims off trailing whitespace for all sysfs attributes. > > It might be better to trim off leading whitespace as well. =20 >=20 > We already trim it off when matching, but we also allow matching if you > do put the spaces in there. This patch breaks that, right? Correct, I have a new patch that trims after the comparison, so it should work in both cases.=20 >=20 > > I also wonder if it might be a good idea to do some sort of > > transformation for characters in an attribute that are illegal in a fil= e > > system, rather than just chopping everything off. e.g, spaces that are > > not leading or trailing would be changed to underscores. >=20 > ick, no. Really? Care to elaborate?=20 Do you not like any transformation (besides the "let's chop off everything after anything illegal") or just the underscores for spaces one? Perhaps a configuration value to make it optional? This sort of thing might relieve a lot of the script writing that must be done to handle cases that may be common. Andrew diff -Nur udev-036.orig/namedev.c udev-036/namedev.c --- udev-036.orig/namedev.c 2004-10-12 14:52:18.000000000 -0600 +++ udev-036/namedev.c 2004-10-13 17:04:51.000000000 -0600 @@ -307,6 +307,17 @@ dbg("sysfa attribute '%s' not found", attr); break; } + /* strip trailing whitespace of matching value */ + if (isspace(tmpattr->value[strlen(tmpattr->value)-1])) { + i =3D len =3D strlen(tmpattr->value); + while (i > 0 && isspace(tmpattr->value[i-1])) + i--; + if (i < len) { + tmpattr->value[i] =3D '\0'; + dbg("remove %i trailing whitespace chars from '%s'", + len - i, tmpattr->value); + } + } strfieldcatmax(string, tmpattr->value, maxsize); dbg("substitute sysfs value '%s'", tmpattr->value); } else { > thanks, >=20 > greg k-h >=20 --=20 Andrew Patterson =20 Hewlett-Packard --=-1y5tSakYGvzUlMfJuNde Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) iD8DBQBBbbaIoKXgdXvblSgRAsdvAKCjb5Ltt35BK19SWHI7nXsKXjsHEwCg6gcY 9eukfyiIK3t3dv4VoJmqHM4= =89JB -----END PGP SIGNATURE----- --=-1y5tSakYGvzUlMfJuNde-- ------------------------------------------------------- This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more http://productguide.itmanagersjournal.com/guidepromo.tmpl _______________________________________________ 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