]> err.no Git - systemd/commitdiff
[PATCH] get part of callout return string
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Tue, 16 Dec 2003 06:54:38 +0000 (22:54 -0800)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 04:13:07 +0000 (21:13 -0700)
Try this patch if you like, to get special parts of the callout output.
This beast works now:
CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n node link1 link2", ID="node *", NAME="%1c", SYMLINK="%2c %3c"

The callout returned string is separated by spaces and is
addressed by the "len" value of the 'c' format char.
Since we support symlinks, this my be useful for other uses of callout too.

  introduce 'len number' for format chars
  the first use is 'c'-the callout return to select a part of the output string like:
  CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n node link1 link2", ID="node *", NAME="%1c", SYMLINK="%2c %3c"
  (note: first part is requested by len=1, len=0 will return the whole string)
  add a test to udev-test.pl

namedev.c
test/udev-test.pl

index 74a411799b9c96db4d8ad619b306c0e5413327da..212d6bb68d93d5774b95ef38cf3806a8dd5a690f 100644 (file)
--- a/namedev.c
+++ b/namedev.c
@@ -200,15 +200,30 @@ static void build_kernel_number(struct sysfs_class_device *class_dev, struct ude
 static void apply_format(struct udevice *udev, unsigned char *string)
 {
        char name[NAME_SIZE];
+       char temp[NAME_SIZE];
+       char *tail;
        char *pos;
+       char *pos2;
+       char *pos3;
+       int num;
 
        while (1) {
+               num = 0;
                pos = strchr(string, '%');
 
                if (pos) {
-                       strfieldcpy(name, pos+2);
-                       *pos = 0x00;
-                       switch (pos[1]) {
+                       *pos = '\0';
+                       tail = pos+1;
+                       if (isdigit(tail[0])) {
+                               num = (int) strtoul(&pos[1], &tail, 10);
+                               if (tail == NULL) {
+                                       dbg("format parsing error '%s'", pos+1);
+                                       break;
+                               }
+                       }
+                       strfieldcpy(name, tail+1);
+
+                       switch (tail[0]) {
                        case 'b':
                                if (strlen(udev->bus_id) == 0)
                                        break;
@@ -241,8 +256,24 @@ static void apply_format(struct udevice *udev, unsigned char *string)
                        case 'c':
                                if (strlen(udev->callout_value) == 0)
                                        break;
-                               strcat(pos, udev->callout_value);
-                               dbg("substitute callout output '%s'", udev->callout_value);
+                               if (num) {
+                                       /* get part of return string */
+                                       strncpy(temp, udev->callout_value, sizeof(temp));
+                                       pos2 = temp;
+                                       while (num) {
+                                               num--;
+                                               pos3 = strsep(&pos2, " ");
+                                               if (pos3 == NULL) {
+                                                       dbg("requested part of callout string not found");
+                                                       break;
+                                               }
+                                       }
+                                       strcat(pos, pos3);
+                                       dbg("substitute partial callout output '%s'", pos3);
+                               } else {
+                                       strcat(pos, udev->callout_value);
+                                       dbg("substitute callout output '%s'", udev->callout_value);
+                               }
                                break;
                        default:
                                dbg("unknown substitution type '%%%c'", pos[1]);
index 3dfbaa2530e148995ca5d2db36ca5c517d3856a2..1a35e3da82e446be17c0b5f52ff64ccd35b79181 100644 (file)
@@ -150,6 +150,15 @@ EOF
                expected => "test-0:0:0:0" ,
                conf     => <<EOF
 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n test-%b", ID="test-*", NAME="%c"
+EOF
+       },
+       {
+               desc     => "callout program substitution (numbered part of)",
+               subsys   => "block",
+               devpath  => "block/sda/sda3",
+               expected => "link1" ,
+               conf     => <<EOF
+CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n node link1 link2", ID="node *", NAME="%1c", SYMLINK="%2c %3c"
 EOF
        },
        {