On Thursday 14 August 2014 at 01:55:26, Lennart Poettering wrote: > On Thu, 31.07.14 16:55, Ivan Shapovalov ([email protected]) wrote: > > > Hello all, > > > > I'm trying to start from an udev rule a templated systemd unit, whose > > instance > > should be a properly escaped device node path (so that %i.device would > > represent > > an existing unit). Which udev specifier should I use for this? > > > > Or, in more clear wording: > > > > given the rule: > > > > ACTION=="add", ..., TAG+="systemd", > > ENV{SYSTEMD_WANTS}+="foo@$some_specifier.service" > > > > and the unit [email protected]: > > > > [Unit] > > After=%i.device > > BindsTo=%i.device > > ... > > > > Which $some_specifier should I use in the udev rule to get %i.device in > > my service file to refer to the valid and corresponding device unit? > > > > The closest match I've got is "sys%p", but it does not work because dashes > > are not > > escaped, and I get > > "sys-devices-pci0000:00-0000:00:1d.0-usb4-4-1-4-1.2.device" > > instead of > > "sys-devices-pci0000:00-0000:00:1d.0-usb4-4\x2d1-4\x2d1.2.device" > > and so on. > > Can you invoke systemd-escape from the udev rule? > > Lennart > >
Yes, (built systemd from git) it seems to work.
/etc/udev/rules.d/99-foo.rules:
ACTION=="add", ..., TAG+="systemd", PROGRAM="/usr/bin/systemd-escape -p
%S%p", ENV{SYSTEMD_WANTS}+="foo@%c.service"
/etc/systemd/system/[email protected]:
[Unit]
Description=Test unit for %f
BindsTo=%i.device
After=%i.device
[Service]
Type=oneshot
RemainAfterExit=no
ExecStart=/etc/systemd/scripts/foo.sh %f
The only thing: PROGRAM="...", ENV{SYSTEMD_WANTS}+="...%c..." idiom seems a
pretty ugly way to invoke systemd-escape. This looks like a pretty common
thing to do; shouldn't there be a shorthand or something? (just a suggestion)
Thanks!
--
Ivan Shapovalov / intelfx /
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ systemd-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/systemd-devel
