From 1fa26490e0d3b0df595fc7d327be46e4d9586bf7 Mon Sep 17 00:00:00 2001 From: "andrew.patterson@hp.com" Date: Thu, 14 Oct 2004 00:47:38 -0700 Subject: [PATCH] [PATCH] Problem parsing %s in udev rules > > > > 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. > > > > > > I expect the model value has trailing spaces. > > > > > > You may look with: > > > udevinfo -a -p /block/sdX > > > > Yes it does, and it seems for most SCSI devices, vendor and model will > > have trailing spaces. > > It all depends on the vendor and model :) > > > 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. > > 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. --- namedev.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/namedev.c b/namedev.c index 9276b0cb..8a443636 100644 --- a/namedev.c +++ b/namedev.c @@ -306,6 +306,17 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize, dbg("sysfa attribute '%s' not found", attr); break; } + /* strip trailing whitespace of matching value */ + if (isspace(tmpattr->value[strlen(tmpattr->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); + } + } strfieldcatmax(string, tmpattr->value, maxsize); dbg("substitute sysfs value '%s'", tmpattr->value); } else { -- 2.39.5