[systemd-devel] Counting mechanism in udev rules
Kay Sievers
kay at vrfy.org
Fri Dec 14 06:59:48 PST 2012
On Fri, Dec 14, 2012 at 3:47 PM, Robert Milasan <rmilasan at suse.com> wrote:
> On Fri, 14 Dec 2012 11:30:05 +0100
> "Kay Sievers" <kay at vrfy.org> wrote:
>
>> 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.
> OK, I understand, but if I would like to achieve what I wrote, how would
> I go and do that?
Making up numbers in the event handler, that increase one by one? You
would hook up an external tool that locks, keeps state, and prints
these numbers. But as said, it cannot really work reliably or be
really predictable.
In this specific case you might be able to just extract the number of
the kernel name with program/shell.
Kay
More information about the systemd-devel
mailing list