[systemd-devel] Counting mechanism in udev rules

Kay Sievers kay at vrfy.org
Fri Dec 14 02:30:05 PST 2012


On Fri, Dec 14, 2012 at 9:11 AM, Robert Milasan <rmilasan at suse.com> wrote:
> Is there some kind of a counting mechanism which can be used in a udev
> rule?
>
> I got this rule:
>
> ACTION=="add", SUBSYSTEM=="3270", KERNEL=="tty0.0.[0-9]*",
> SYMLINK+="3270/ttycons-%n"
>
> and the result of this rule looks like this:
>
> lrwxrwxrwx 1 root root 14 Dec 13 15:28 ttycons-0500 -> ../tty0.0.0500
> lrwxrwxrwx 1 root root 14 Dec 13 15:28 ttycons-0501 -> ../tty0.0.0501
> lrwxrwxrwx 1 root root 14 Dec 13 15:28 ttycons-0502 -> ../tty0.0.0502
> lrwxrwxrwx 1 root root 14 Dec 13 15:28 ttycons-0503 -> ../tty0.0.0503
>
> But I would like instead of '%n' to use a counting variable that would
> make the result look something like this:
>
> lrwxrwxrwx 1 root root 14 Dec 13 15:28 ttycons0 -> ../tty0.0.0500
> lrwxrwxrwx 1 root root 14 Dec 13 15:28 ttycons1 -> ../tty0.0.0501
> lrwxrwxrwx 1 root root 14 Dec 13 15:28 ttycons2 -> ../tty0.0.0502
> lrwxrwxrwx 1 root root 14 Dec 13 15:28 ttycons3 -> ../tty0.0.0503
>
> Would this be possible in udev, if so what '%' option can I use?

There is intentionally no enumeration facility in udev. Udev-provided
enumeration would not be much better than the kernel-provided
enumeration.

In general, all sorts of device inter-dependencies in device names
should be avoided, and names should be provided by properties derived
from the device itself, the bus location it is connected to, or be
supported by the firmware, and not by unreliable enumeration.

"Inventing" new numbers in a device hotplug path cannot really work,
and udev does not want to give the impression it could.

Kay


More information about the systemd-devel mailing list