Skip to contentSkip to conversation

callout part selector tweak

PATCH In review Kay Sievers 2 participants 2 messages Mar 11, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 callout part selector tweak

Martin Schwenke <[email protected]> asked for this feature and posted a patch:

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 "giveme the second and later words"."

Here is the actual version with tests and a few words in the man page.

thanks,
Kay

===== namedev.c 1.128 vs edited =====

namedev.c +6 -2
@@ -190,6 +190,7 @@
 	int i;
 	char c;
 	char *spos;
+	char *rest;
 	int slen;
 	struct sysfs_attribute *tmpattr;
 
@@ -244,7 +245,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--;
@@ -255,7 +256,10 @@
 					dbg("requested part of result string not found");
 					break;
 				}
-				strfieldcpymax(temp2, spos, slen+1);
+				if (rest[0] == '+')
+					strfieldcpy(temp2, spos);
+				else
+					strfieldcpymax(temp2, spos, slen+1);
 				strfieldcatmax(string, temp2, maxsize);
 				dbg("substitute part of result string '%s'", temp2);
 			} else {

===== udev.8 1.52 vs edited =====

udev.8 +4 -1
@@ -253,7 +253,10 @@
 .br
 A single part of the string, separated by a space character
 may be selected by specifying the part number as a attribute:
-.BI %c{ part }
+.BI %c{ N }
+If the number is followed by the + char this part plus
+all remaining parts of the result string are substituted:
+.BI %c{ N+ }
 .TP
 .BI %s{ filename }
 The content of a sysfs attribute.

===== test/udev-test.pl 1.43 vs edited =====

test/udev-test.pl +9 -0
@@ -307,6 +307,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",
#1 lore raw
Quoted 5 lines · Kay Sievers

Martin Schwenke <[email protected]> asked for this feature and posted a patch:

The following patch almost let's me have the following configuration:

Quoted 7 lines

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 "giveme the second and later words"."

Here is the actual version with tests and a few words in the man page.

Cool feature. Applied, thanks.

greg k-h

-------------------------------------------------------
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_id70&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel