summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>2004-01-13 18:34:33 -0800
committerGreg KH <gregkh@suse.de>2005-04-26 21:13:16 -0700
commit8ffb636f013a193688b132b8512e77b0747c41a1 (patch)
tree1236ac40963c0ad6a239a872916017a7eb3ad07d
parente68faf511dd9be15a27042d1828460d3655707d8 (diff)
[PATCH] udev - introduce format escape char
This patch adds a '%' to the format char list, so that a external program may called with a non expanded '%' like: PROGRAM="/bin/date +%%s" Olaf Hering asked for the feature. A tricky test is also added :)
-rw-r--r--namedev.c19
-rw-r--r--test/udev-test.pl9
2 files changed, 21 insertions, 7 deletions
diff --git a/namedev.c b/namedev.c
index 6f7bfb6805..0e1af9385f 100644
--- a/namedev.c
+++ b/namedev.c
@@ -151,20 +151,21 @@ static mode_t get_default_mode(struct sysfs_class_device *class_dev)
static void apply_format(struct udevice *udev, unsigned char *string)
{
- char name[NAME_SIZE];
char temp[NAME_SIZE];
+ char temp1[NAME_SIZE];
char *tail;
char *pos;
char *pos2;
char *pos3;
int num;
+ pos = string;
while (1) {
num = 0;
- pos = strchr(string, '%');
+ pos = strchr(pos, '%');
if (pos) {
- *pos = '\0';
+ pos[0] = '\0';
tail = pos+1;
if (isdigit(tail[0])) {
num = (int) strtoul(&pos[1], &tail, 10);
@@ -173,7 +174,7 @@ static void apply_format(struct udevice *udev, unsigned char *string)
break;
}
}
- strfieldcpy(name, tail+1);
+ strfieldcpy(temp, tail+1);
switch (tail[0]) {
case 'b':
@@ -217,8 +218,8 @@ static void apply_format(struct udevice *udev, unsigned char *string)
break;
if (num) {
/* get part of return string */
- strncpy(temp, udev->program_result, sizeof(temp));
- pos2 = temp;
+ strncpy(temp1, udev->program_result, sizeof(temp1));
+ pos2 = temp1;
while (num) {
num--;
pos3 = strsep(&pos2, " ");
@@ -236,11 +237,15 @@ static void apply_format(struct udevice *udev, unsigned char *string)
dbg("substitute result string '%s'", udev->program_result);
}
break;
+ case '%':
+ strcat(pos, "%");
+ pos++;
+ break;
default:
dbg("unknown substitution type '%%%c'", pos[1]);
break;
}
- strcat(string, name);
+ strcat(string, temp);
} else
break;
}
diff --git a/test/udev-test.pl b/test/udev-test.pl
index ab27c74c6a..5e5756b660 100644
--- a/test/udev-test.pl
+++ b/test/udev-test.pl
@@ -206,6 +206,15 @@ BUS="scsi", PROGRAM="/bin/echo -n test-%b", RESULT="test-0:0*", NAME="%c"
EOF
},
{
+ desc => "program with escaped format char (tricky: callout returns format char!)",
+ subsys => "block",
+ devpath => "block/sda/sda3",
+ expected => "escape-3" ,
+ conf => <<EOF
+BUS="scsi", PROGRAM="/bin/echo -n escape-%%n", KERNEL="sda3", NAME="%c"
+EOF
+ },
+ {
desc => "program result substitution (numbered part of)",
subsys => "block",
devpath => "block/sda/sda3",