* [PATCH] udev - introduce format escape char
@ 2004-01-13 2:19 Kay Sievers
2004-01-13 18:42 ` Greg KH
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Kay Sievers @ 2004-01-13 2:19 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 224 bytes --]
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 :)
thanks,
Kay
[-- Attachment #2: 05-escape-format-char.diff --]
[-- Type: text/plain, Size: 1973 bytes --]
diff -Nru a/namedev.c b/namedev.c
--- a/namedev.c Tue Jan 13 03:13:14 2004
+++ b/namedev.c Tue Jan 13 03:13:14 2004
@@ -151,20 +151,21 @@
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 @@
break;
}
}
- strfieldcpy(name, tail+1);
+ strfieldcpy(temp, tail+1);
switch (tail[0]) {
case 'b':
@@ -217,8 +218,8 @@
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 @@
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 -Nru a/test/udev-test.pl b/test/udev-test.pl
--- a/test/udev-test.pl Tue Jan 13 03:13:14 2004
+++ b/test/udev-test.pl Tue Jan 13 03:13:14 2004
@@ -206,6 +206,15 @@
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",
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] udev - introduce format escape char
2004-01-13 2:19 [PATCH] udev - introduce format escape char Kay Sievers
@ 2004-01-13 18:42 ` Greg KH
2004-01-13 19:25 ` Kay Sievers
2004-01-13 19:32 ` Greg KH
2 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2004-01-13 18:42 UTC (permalink / raw)
To: linux-hotplug
On Tue, Jan 13, 2004 at 03:19:32AM +0100, Kay Sievers wrote:
> 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 :)
Hm, does this mean that we can't pass a "%n" to a program as it is
something we intrepret (your test seems to verify this)?
Is that ok?
Anyway, I've applied this.
thanks,
greg k-h
-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] udev - introduce format escape char
2004-01-13 2:19 [PATCH] udev - introduce format escape char Kay Sievers
2004-01-13 18:42 ` Greg KH
@ 2004-01-13 19:25 ` Kay Sievers
2004-01-13 19:32 ` Greg KH
2 siblings, 0 replies; 4+ messages in thread
From: Kay Sievers @ 2004-01-13 19:25 UTC (permalink / raw)
To: linux-hotplug
On Tue, Jan 13, 2004 at 10:42:35AM -0800, Greg KH wrote:
> On Tue, Jan 13, 2004 at 03:19:32AM +0100, Kay Sievers wrote:
> > 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 :)
>
> Hm, does this mean that we can't pass a "%n" to a program as it is
> something we intrepret (your test seems to verify this)?
No, it wasn't possible before. That's why we have the escape now.
If you want to pass any '%' down to a program, you need to ecape it
by '%%', otherwise we try to expand it with our own format char list.
I will put in the man page, later today.
In my stupid test, the program returns a '%n' and this is expanded
inside the '%c' to the kernel number. I found it funny... :)
thanks,
Kay
-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] udev - introduce format escape char
2004-01-13 2:19 [PATCH] udev - introduce format escape char Kay Sievers
2004-01-13 18:42 ` Greg KH
2004-01-13 19:25 ` Kay Sievers
@ 2004-01-13 19:32 ` Greg KH
2 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2004-01-13 19:32 UTC (permalink / raw)
To: linux-hotplug
On Tue, Jan 13, 2004 at 08:25:50PM +0100, Kay Sievers wrote:
> On Tue, Jan 13, 2004 at 10:42:35AM -0800, Greg KH wrote:
> > On Tue, Jan 13, 2004 at 03:19:32AM +0100, Kay Sievers wrote:
> > > 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 :)
> >
> > Hm, does this mean that we can't pass a "%n" to a program as it is
> > something we intrepret (your test seems to verify this)?
>
> No, it wasn't possible before. That's why we have the escape now.
> If you want to pass any '%' down to a program, you need to ecape it
> by '%%', otherwise we try to expand it with our own format char list.
>
> I will put in the man page, later today.
>
> In my stupid test, the program returns a '%n' and this is expanded
> inside the '%c' to the kernel number. I found it funny... :)
Ah, that makes more sense now, thanks.
I need to wake up today...
greg k-h
-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-01-13 19:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-13 2:19 [PATCH] udev - introduce format escape char Kay Sievers
2004-01-13 18:42 ` Greg KH
2004-01-13 19:25 ` Kay Sievers
2004-01-13 19:32 ` Greg KH
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.