[systemd-devel] Passing variables from udev to unit
Peter Hutterer
peter.hutterer at who-t.net
Sun Mar 16 00:23:58 PDT 2014
On 15/03/2014 07:11 , Lennart Poettering wrote:
> On Fri, 14.03.14 08:53, Peter Hutterer (peter.hutterer at who-t.net) wrote:
>
>> Hey,
>>
>> I have a service file wacom-inputattach at .service that is started from a udev
>> rule:
>>
>> SUBSYSTEM=="tty|pnp", KERNEL=="ttyS[0-9]*", ATTRS{id}=="WACf*",
>> TAG+="systemd", ENV{SYSTEMD_WANTS}+="wacom-inputattach@%k.service"
>>
>> and the service file then runs:
>>
>> ExecStart=/usr/bin/inputattach -w8001 /dev/%I
>>
>> That works fine, but now I need to pass a second parameter into the service
>> file. Ideally I want to run something like:
>>
>> ExecStart=/usr/bin/inputattach --baud $BAUD -w8001 /dev/%I
>>
>> I can set the baud rate based on ATTRS{id} in the udev rule, I just don't
>> know if there is a way to pass this to the service file. Is there a way to
>> do this or do I need to write a wrapper?
>
> No this is currently not possible, instances can only have one instance
> identifier. Any chance you can maybe adapt inputattach to use simple
> libudev calls to read the props from the device on its own? That way the
> thing would always work, even if people call it from the command line?
> Should be like 10 lines of code or so.
>
> fstat(tty_fd, &st);
> udev = udev_new();
> d = udev_device_new_from_devnum(udev, 'c', st.st_rdev);
> baud_str = udev_device_get_property_value(d, "WACOM_BAUDRATE");
> baud = atoi(bau_str);
> udev_device_unref(d);
> udev_unref(udev);
>
> And then set WACOM_BAUDRATE from an udev rule.
yeah, no worries, that's easy enough to do, I just wanted to know if
there was an even easier way. thanks for the answers.
Cheers,
Peter
More information about the systemd-devel
mailing list