chiark / gitweb /
[PATCH] callout part selector tweak
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Thu, 11 Mar 2004 09:37:18 +0000 (01:37 -0800)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 04:35:09 +0000 (21:35 -0700)
Martin Schwenke <martin@meltin.net> asked for this feature and posted a
patch:

 The following patch almost let's me have the following configuration:

  PROGRAM="/sbin/aliaser %b %k %n %M %m", RESULT="?*", NAME="%c{1}", SYMLINK="%c{2+}"

 allowing me to specify an arbitrary number of symlinks by saying
 "giveme the second and later words"."

Here is the actual version with tests and a few words in the man page.

namedev.c
test/udev-test.pl
udev.8

index a9142374f4c1400e6737974795b083fe99633ec9..7305676d427644f6af545552c8cc969de7e13246 100644 (file)
--- 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 {
index dadec568ba907034e396f70963998db6a4f35f00..7db92691d31bddb25f24f07ba3d181842acb8e5c 100644 (file)
@@ -304,6 +304,15 @@ EOF
                expected => "link1" ,
                conf     => <<EOF
 BUS="scsi", PROGRAM="/bin/echo -n node link1 link2", RESULT="node *", NAME="%c{1}", SYMLINK="%c{2} %c{3}"
+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
        },
        {
diff --git a/udev.8 b/udev.8
index d5d95491136f86fc3688e7e8fbccf899666ef408..b367d3981391327652dfd6e996691411fbd68af4 100644 (file)
--- 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.