From: Kay Sievers <kay.sievers@vrfy.org>
To: linux-hotplug@vger.kernel.org
Subject: Re: udev.rules.devfs + symlinks & a question
Date: Sat, 13 Dec 2003 15:47:48 +0000 [thread overview]
Message-ID: <marc-linux-hotplug-107133051604928@msgid-missing> (raw)
In-Reply-To: <marc-linux-hotplug-107105799027697@msgid-missing>
[-- Attachment #1: Type: text/plain, Size: 995 bytes --]
On Sat, Dec 13, 2003 at 02:17:22AM +0100, Svetoslav Slavtchev wrote:
> can a callout return several strings?
> NAME="%c1", SYMLINK="%c2 %c3"
>
> no i don't think this can be done with a callout script
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.
good luck,
Kay
02-get-part-of-callout-return-string.diff
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
[-- Attachment #2: 02-get-part-of-callout-return-string.diff --]
[-- Type: text/plain, Size: 2168 bytes --]
diff -Nru a/namedev.c b/namedev.c
--- a/namedev.c Sat Dec 13 16:19:27 2003
+++ b/namedev.c Sat Dec 13 16:19:27 2003
@@ -200,15 +200,30 @@
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 @@
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]);
diff -Nru a/test/udev-test.pl b/test/udev-test.pl
--- a/test/udev-test.pl Sat Dec 13 16:19:27 2003
+++ b/test/udev-test.pl Sat Dec 13 16:19:27 2003
@@ -153,6 +153,15 @@
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
+ },
+ {
desc => "devfs disk naming substitution",
subsys => "block",
devpath => "block/sda",
next prev parent reply other threads:[~2003-12-13 15:47 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-12-10 12:01 udev.rules.devfs + symlinks & a question Svetoslav Slavtchev
2003-12-10 12:31 ` Arnd Bergmann
2003-12-10 13:17 ` Svetoslav Slavtchev
2003-12-10 17:00 ` Marco d'Itri
2003-12-10 22:07 ` Greg KH
2003-12-10 22:45 ` Svetoslav Slavtchev
2003-12-10 23:14 ` Greg KH
2003-12-10 23:19 ` Svetoslav Slavtchev
2003-12-11 0:17 ` Greg KH
2003-12-11 1:14 ` Svetoslav Slavtchev
2003-12-11 1:31 ` Svetoslav Slavtchev
2003-12-12 22:17 ` Svetoslav Slavtchev
2003-12-12 23:42 ` Greg KH
2003-12-12 23:43 ` Greg KH
2003-12-12 23:45 ` Greg KH
2003-12-13 0:02 ` Svetoslav Slavtchev
2003-12-13 0:06 ` Greg KH
2003-12-13 0:39 ` Svetoslav Slavtchev
2003-12-13 0:57 ` Greg KH
2003-12-13 0:58 ` Svetoslav Slavtchev
2003-12-13 1:17 ` Svetoslav Slavtchev
2003-12-13 15:47 ` Kay Sievers [this message]
2003-12-13 21:33 ` Svetoslav Slavtchev
2003-12-14 3:34 ` Kay Sievers
2003-12-15 22:55 ` Greg KH
2003-12-15 22:56 ` Greg KH
2003-12-15 22:57 ` Greg KH
2003-12-17 20:16 ` Svetoslav Slavtchev
2003-12-17 20:39 ` Svetoslav Slavtchev
2003-12-17 21:13 ` Svetoslav Slavtchev
2003-12-17 22:24 ` Greg KH
2003-12-17 22:25 ` Greg KH
2003-12-17 22:27 ` Greg KH
2003-12-17 22:28 ` Greg KH
2003-12-17 22:29 ` Greg KH
2003-12-17 22:30 ` Greg KH
2003-12-17 22:51 ` Marco d'Itri
2003-12-17 22:55 ` Svetoslav Slavtchev
2003-12-17 22:59 ` Svetoslav Slavtchev
2003-12-17 23:04 ` Svetoslav Slavtchev
2003-12-17 23:06 ` Svetoslav Slavtchev
2003-12-17 23:08 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=marc-linux-hotplug-107133051604928@msgid-missing \
--to=kay.sievers@vrfy.org \
--cc=linux-hotplug@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).