linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] namedev.c %c{N+} capability + buglet with SYMLINK
@ 2004-03-08  1:49 Martin Schwenke
  2004-03-08  2:44 ` Kay Sievers
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Martin Schwenke @ 2004-03-08  1:49 UTC (permalink / raw)
  To: linux-hotplug

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.

The only gotcha is that the rule won't apply when SYMLINK gets an
empty value (that is, there is only 1 word).  This seems kind-of
broken, since it stops you using a general rule to do the symlinks,
and I think the semantics of an empty SYMLINK value are pretty clear
(i.e. no symlinks please).

peace & happiness,
martin

--- udev-021.orig/namedev.c	2004-03-03 11:01:33.000000000 +1100
+++ udev-021/namedev.c	2004-03-05 12:25:55.000000000 +1100
@@ -223,6 +223,8 @@
 	int len;
 	int i;
 	char c;
+	char c2;
+	int rest;
 	struct sysfs_attribute *tmpattr;
 
 	pos = string;
@@ -276,26 +278,31 @@
 			/* get part part of the result string */
 			i = 0;
 			if (attr != NULL)
-				i = atoi(attr);
-			if (i > 0) {
-				strfieldcpy(temp1, udev->program_result);
-				pos2 = temp1;
-				while (i) {
+				i = strtol(attr, &pos2, 10);
+			if ((pos2 != attr) && (i > 0))
+				rest = (*pos2 = '+');
+			else {
+				i = rest = 1;
+			}
+			pos2 = udev->program_result;
+			while ((pos2 != NULL) && (i > 1)) {
+				pos2 = strchr(pos2, ' ');
+				if (pos2) {
 					i--;
-					pos3 = strsep(&pos2, " ");
-					if (pos3 = NULL) {
-						dbg("requested part of result string not found");
-						break;
-					}
+					pos2++;
 				}
-				if (pos3) {
-					strnfieldcat(string, pos3, maxsize);
-					dbg("substitute part of result string '%s'", pos3);
-				}
-			} else {
-				strnfieldcat(string, udev->program_result, maxsize);
-				dbg("substitute result string '%s'", udev->program_result);
 			}
+			if (pos2 != NULL) {
+				c2 = rest ? '\0' : ' ';
+				pos3 = temp1;
+				while (*pos2 != c2)
+					*pos3++ = *pos2++;
+				*pos3 = '\0';
+			} else
+				*temp1 = '\0';
+			
+			strnfieldcat(string, temp1, maxsize);
+			dbg("substitute (part of) result string '%s'", temp1);
 			break;
 		case 's':
 			if (attr != NULL) {



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
_______________________________________________
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] 5+ messages in thread

end of thread, other threads:[~2004-03-09  4:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-08  1:49 [PATCH] namedev.c %c{N+} capability + buglet with SYMLINK Martin Schwenke
2004-03-08  2:44 ` Kay Sievers
2004-03-08  5:02 ` Martin Schwenke
2004-03-08 13:04 ` Kay Sievers
2004-03-09  4:37 ` Martin Schwenke

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).