linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kay Sievers <kay.sievers@vrfy.org>
To: linux-hotplug@vger.kernel.org
Subject: Re: [PATCH] namedev.c %c{N+} capability + buglet with SYMLINK
Date: Mon, 08 Mar 2004 02:44:24 +0000	[thread overview]
Message-ID: <20040308024424.GA24782@vrfy.org> (raw)
In-Reply-To: <16459.53560.188318.971393@martins.ozlabs.org>

[-- Attachment #1: Type: text/plain, Size: 1352 bytes --]

On Mon, Mar 08, 2004 at 12:49:44PM +1100, Martin Schwenke wrote:
> I want to be able to use naming callouts that follow a convention of
> providing the canonical device name as the first word, and
> aliases/symlinks as subsequent words.  That is, my callout might
> print:
> 
>   hdc cdrom bert ernie
> 
> so the canonical name will be "hdc", and "cdrom, "bert" and "ernie"
> will be aliases/symlinks.  I can probably implement this is in
> slightly gross fashion by having the result match against the number
> spaces in the result, and then do the appropriate number of
> substitutions.
> 
> 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 "give
> me the second and later words".  I thought of implementing something
> more complex (involving arbitrary ranges of words), but I think the
> implementation below provides all the functionality that is needed.

Nice idea, but the code you've patched is gone:

  http://linuxusb.bkbits.net:8080/udev/anno/namedev.c@1.125?nav=index.html|src/

Hey, it was too ugly and you try to make it more ugly :)

Here is a patch for the current version, but there are more patches
pending and we need to change it again.

thanks,
Kay

[-- Attachment #2: 06-result-selector-plus.patch --]
[-- Type: text/plain, Size: 1450 bytes --]

===== namedev.c 1.125 vs edited =====
--- 1.125/namedev.c	Thu Mar  4 14:38:53 2004
+++ edited/namedev.c	Mon Mar  8 03:22:43 2004
@@ -222,6 +222,7 @@
 	int i;
 	char c;
 	char *spos;
+	char *rest;
 	int slen;
 	struct sysfs_attribute *tmpattr;
 
@@ -276,7 +277,7 @@
 			/* 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--;
@@ -287,7 +288,10 @@
 					dbg("requested part of result string not found");
 					break;
 				}
-				strnfieldcpy(temp2, spos, slen+1);
+				if (rest[0] == '+')
+					strfieldcpy(temp2, spos);
+				else
+					strnfieldcpy(temp2, spos, slen+1);
 				strnfieldcat(string, temp2, maxsize);
 				dbg("substitute part of result string '%s'", temp2);
 			} else {
===== test/udev-test.pl 1.42 vs edited =====
--- 1.42/test/udev-test.pl	Thu Mar  4 14:38:53 2004
+++ edited/test/udev-test.pl	Mon Mar  8 03:24:57 2004
@@ -289,6 +289,15 @@
 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
+	},
+	{
 		desc     => "invalid program for device with no bus",
 		subsys   => "tty",
 		devpath  => "class/tty/console",

  reply	other threads:[~2004-03-08  2:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-08  1:49 [PATCH] namedev.c %c{N+} capability + buglet with SYMLINK Martin Schwenke
2004-03-08  2:44 ` Kay Sievers [this message]
2004-03-08  5:02 ` Martin Schwenke
2004-03-08 13:04 ` Kay Sievers
2004-03-09  4:37 ` Martin Schwenke

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=20040308024424.GA24782@vrfy.org \
    --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).