chiark / gitweb /
add $links substitution
authorKay Sievers <kay.sievers@vrfy.org>
Mon, 21 Apr 2008 15:43:12 +0000 (17:43 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Mon, 21 Apr 2008 15:43:12 +0000 (17:43 +0200)
udev.7
udev.xml
udev_rules.c

diff --git a/udev.7 b/udev.7
index 3bc04b7..1cad58d 100644 (file)
--- a/udev.7
+++ b/udev.7
@@ -378,7 +378,12 @@ The node name of the parent device\.
 .PP
 \fB$name\fR
 .RS 4
-The name of the device node\. The value is only set if an earlier rule assigned a value, or during a remove events\.
+The current name of the device node\. If not changed by a rule, it is the name of the kernel device\.
+.RE
+.PP
+\fB$links\fR
+.RS 4
+The current list of symlinks, separated by a space character\. The value is only set if an earlier rule assigned a value, or during a remove events\.
 .RE
 .PP
 \fB$root\fR, \fB%r\fR
index e432965..15651e0 100644 (file)
--- a/udev.xml
+++ b/udev.xml
             <varlistentry>
               <term><option>$name</option></term>
               <listitem>
-                <para>The name of the device node. The value is only set if an earlier
-                rule assigned a value, or during a remove events.</para>
+                <para>The current name of the device node. If not changed by a rule, it is the
+                name of the kernel device.</para>
+              </listitem>
+            </varlistentry>
+
+            <varlistentry>
+              <term><option>$links</option></term>
+              <listitem>
+                <para>The current list of symlinks, separated by a space character. The value is
+                only set if an earlier rule assigned a value, or during a remove events.</para>
               </listitem>
             </varlistentry>
 
index 884cb70..d476e69 100644 (file)
@@ -658,6 +658,7 @@ void udev_rules_apply_format(struct udevice *udev, char *string, size_t maxsize)
                SUBST_PARENT,
                SUBST_TEMP_NODE,
                SUBST_NAME,
+               SUBST_LINKS,
                SUBST_ROOT,
                SUBST_SYS,
                SUBST_ENV,
@@ -680,6 +681,7 @@ void udev_rules_apply_format(struct udevice *udev, char *string, size_t maxsize)
                { .name = "parent",     .fmt = 'P',     .type = SUBST_PARENT },
                { .name = "tempnode",   .fmt = 'N',     .type = SUBST_TEMP_NODE },
                { .name = "name",       .fmt = 'D',     .type = SUBST_NAME },
+               { .name = "links",      .fmt = 'L',     .type = SUBST_LINKS },
                { .name = "root",       .fmt = 'r',     .type = SUBST_ROOT },
                { .name = "sys",        .fmt = 'S',     .type = SUBST_SYS },
                { .name = "env",        .fmt = 'E',     .type = SUBST_ENV },
@@ -899,8 +901,26 @@ found:
                        dbg("substitute temporary device node name '%s'\n", udev->tmp_node);
                        break;
                case SUBST_NAME:
-                       strlcat(string, udev->name, maxsize);
-                       dbg("substitute udev->name '%s'\n", udev->name);
+                       if (udev->name[0] == '\0') {
+                               strlcat(string, udev->dev->kernel, maxsize);
+                               dbg("substitute udev->kernel '%s'\n", udev->name);
+                       } else {
+                               strlcat(string, udev->name, maxsize);
+                               dbg("substitute udev->name '%s'\n", udev->name);
+                       }
+                       break;
+               case SUBST_LINKS:
+                       if (!list_empty(&udev->symlink_list)) {
+                               struct name_entry *name_loop;
+                               char symlinks[PATH_SIZE] = "";
+
+                               list_for_each_entry(name_loop, &udev->symlink_list, node) {
+                                       strlcat(symlinks, name_loop->name, sizeof(symlinks));
+                                       strlcat(symlinks, " ", sizeof(symlinks));
+                               }
+                               remove_trailing_chars(symlinks, ' ');
+                               strlcat(string, symlinks, maxsize);
+                       }
                        break;
                case SUBST_ROOT:
                        strlcat(string, udev_root, maxsize);