Do substitition processing in MODE field, similar to substitution in OWNER, GROUP etc fields. Add test case for normal and overflow behaviour. Document in manpage and XML. --- test/udev-test.pl | 21 +++++++++++++++++++++ udev.7 | 3 ++- udev.xml | 2 +- udev_rules.c | 5 ++++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/test/udev-test.pl b/test/udev-test.pl index fee62a6..8f1030d 100755 --- a/test/udev-test.pl +++ b/test/udev-test.pl @@ -1617,6 +1617,27 @@ EOF KERNEL=="sda", MODE="0000" EOF }, + { + desc => "TEST PROGRAM feeds MODE", + subsys => "block", + devpath => "/block/sda", + exp_name => "sda", + exp_perms => "0:0:0400", + rules => <<EOF +KERNEL=="sda", PROGRAM=="/bin/echo 0 0 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}" +EOF + }, + { + desc => "TEST PROGRAM feeds MODE with overflow", + subsys => "block", + devpath => "/block/sda", + exp_name => "sda", + exp_perms => "0:0:0400", + rules => <<EOF +KERNEL=="sda", PROGRAM=="/bin/echo 0 0 0400letsdoabuffferoverflow0123456789012345789012345678901234567890", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}" +EOF + }, + ); # set env diff --git a/udev.7 b/udev.7 index 096bf38..79e61ea 100644 --- a/udev.7 +++ b/udev.7 @@ -307,7 +307,8 @@ The \fBSYMLINK\fR, \fBPROGRAM\fR, \fBOWNER\fR, -\fBGROUP\fR +\fBGROUP\fR, +\fBMODE\fR and \fBRUN\fR fields support simple printf\-like string substitutions\. The diff --git a/udev.xml b/udev.xml index ac3676e..184457a 100644 --- a/udev.xml +++ b/udev.xml @@ -462,7 +462,7 @@ </variablelist> <para>The <option>NAME</option>, <option>SYMLINK</option>, <option>PROGRAM</option>, - <option>OWNER</option>, <option>GROUP</option> and <option>RUN</option> + <option>OWNER</option>, <option>GROUP</option>, <option>MODE</option> and <option>RUN</option> fields support simple printf-like string substitutions. The <option>RUN</option> format chars gets applied after all rules have been processed, right before the program is executed. It allows the use of the complete environment set by earlier matching diff --git a/udev_rules.c b/udev_rules.c index 55a079b..f4ee11a 100644 --- a/udev_rules.c +++ b/udev_rules.c @@ -1412,7 +1412,10 @@ int udev_rules_get_name(struct udev_rules *rules, struct udevice *udev) if (!udev->mode_final && rule->mode.operation != KEY_OP_UNSET) { if (rule->mode.operation == KEY_OP_ASSIGN_FINAL) udev->mode_final = 1; - udev->mode = strtol(key_val(rule, &rule->mode), NULL, 8); + char buf[20]; + strlcpy(buf, key_val(rule, &rule->mode), sizeof(buf)); + udev_rules_apply_format(udev, buf, sizeof(buf)); + udev->mode = strtol(buf, NULL, 8); dbg("applied mode=%#o to '%s'\n", udev->mode, udev->dev->kernel); } if (!udev->owner_final && rule->owner.operation != KEY_OP_UNSET) { -- 1.5.5.1.g1fbb5 -- To unsubscribe from this list: send the line "unsubscribe linux-hotplug" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html