From: kay.sievers@vrfy.org Date: Thu, 11 Mar 2004 09:37:18 +0000 (-0800) Subject: [PATCH] callout part selector tweak X-Git-Tag: 022~16 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=558f80ba649fb5b8c2ac2a51e464f1aa07aa791d;p=systemd [PATCH] callout part selector tweak Martin Schwenke 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. --- diff --git a/namedev.c b/namedev.c index a9142374..7305676d 100644 --- a/namedev.c +++ b/namedev.c @@ -190,6 +190,7 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize, int i; char c; char *spos; + char *rest; int slen; struct sysfs_attribute *tmpattr; @@ -244,7 +245,7 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize, /* 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 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize, 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 { diff --git a/test/udev-test.pl b/test/udev-test.pl index dadec568..7db92691 100644 --- a/test/udev-test.pl +++ b/test/udev-test.pl @@ -304,6 +304,15 @@ EOF expected => "link1" , conf => < "program result substitution (numbered part of+)", + subsys => "block", + devpath => "block/sda/sda3", + expected => "link3" , + conf => <