summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--namedev.c8
-rw-r--r--test/udev-test.pl9
-rw-r--r--udev.85
3 files changed, 19 insertions, 3 deletions
diff --git a/namedev.c b/namedev.c
index a9142374f4..7305676d42 100644
--- a/namedev.c
+++ b/namedev.c
@@ -190,6 +190,7 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
int i;
char c;
char *spos;
+ char *rest;
int slen;
struct sysfs_attribute *tmpattr;
@@ -244,7 +245,7 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
/* get part part of the result string */
i = 0;
if (attr != NULL)
- i = atoi(attr);
+ i = strtoul(attr, &rest, 10);
if (i > 0) {
foreach_strpart(udev->program_result, " \n\r", spos, slen) {
i--;
@@ -255,7 +256,10 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
dbg("requested part of result string not found");
break;
}
- strfieldcpymax(temp2, spos, slen+1);
+ if (rest[0] == '+')
+ strfieldcpy(temp2, spos);
+ else
+ strfieldcpymax(temp2, spos, slen+1);
strfieldcatmax(string, temp2, maxsize);
dbg("substitute part of result string '%s'", temp2);
} else {
diff --git a/test/udev-test.pl b/test/udev-test.pl
index dadec568ba..7db92691d3 100644
--- a/test/udev-test.pl
+++ b/test/udev-test.pl
@@ -307,6 +307,15 @@ BUS="scsi", PROGRAM="/bin/echo -n node link1 link2", RESULT="node *", NAME="%c{1
EOF
},
{
+ desc => "program result substitution (numbered part of+)",
+ subsys => "block",
+ devpath => "block/sda/sda3",
+ expected => "link3" ,
+ conf => <<EOF
+BUS="scsi", PROGRAM="/bin/echo -n node link1 link2 link3 link4", RESULT="node *", NAME="%c{1}", SYMLINK="%c{2+}"
+EOF
+ },
+ {
desc => "invalid program for device with no bus",
subsys => "tty",
devpath => "class/tty/console",
diff --git a/udev.8 b/udev.8
index d5d9549113..b367d39813 100644
--- a/udev.8
+++ b/udev.8
@@ -253,7 +253,10 @@ field for the obvious reason.)
.br
A single part of the string, separated by a space character
may be selected by specifying the part number as a attribute:
-.BI %c{ part }
+.BI %c{ N }
+If the number is followed by the + char this part plus
+all remaining parts of the result string are substituted:
+.BI %c{ N+ }
.TP
.BI %s{ filename }
The content of a sysfs attribute.