Bug 1020887 - RFE: add escaped form of $devnode for use in udev rules
RFE: add escaped form of $devnode for use in udev rules
Status: CLOSED WONTFIX
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: systemd (Show other bugs)
7.0
All Linux
medium Severity high
: rc
: ---
Assigned To: systemd-maint
qe-baseos-daemons
: FutureFeature
Depends On:
Blocks: 1297395
  Show dependency treegraph
 
Reported: 2013-10-18 08:52 EDT by Peter Rajnoha
Modified: 2016-11-09 08:50 EST (History)
6 users (show)

See Also:
Fixed In Version:
Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2016-11-09 08:39:53 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Peter Rajnoha 2013-10-18 08:52:50 EDT
Systemd normally escapes '/' characters with '-' character when used for instantiated service names.

But the '-' character is allowed in device names (e.g. dm-0) and such escape could cause the information about the original name to be lost when trying to translate it back.


A practical example:

- the udev rule (69-dm-lvm-metad.rules):
   
    ENV{SYSTEMD_WANTS}="lvm2-pvscan@$devnode.service"

- the line from systemd service (lvm2-pvscan@.service):

    ExecStart=/usr/sbin/pvscan --cache --activate ay %I

Now, for example, if the $devnode is "dm-0", then instantiating the lvm2-pvscan@.service will result in:

    lvm2-pvscan@-dev-dm-0.service

Now, trying to use the instance name with "%I" in the ExecStart will result in:

   /usr/sbin/pvscan --cache --activate ay /dev/dm/0

While expected one is:

   /usr/sbin/pvscan --cache --activate ay /dev/dm-0

Which is caused by the information to be lost during character escape.
The escape character itself should haven been escaped for this to work correctly.
Comment 2 Michal Schmidt 2013-10-18 09:15:53 EDT
There may be a confusion about which strings are supposed to be raw and which are escaped.

Unit names are escaped strings, because some unit names are generated from path names. That's why I have a unit called "sys-devices-virtual-block-dm\x2d0.device" here (just an example).

But if that's the case, shouldn't a name such as "lvm2-pvscan@/dev/dm-0.service" be considered invalid? The "/" character should not appear in an escaped string.
An escaped name would be "lvm2-pvscan@dev-dm\x2d0.service". But I don't think we provide a tool to perform easy (un-)escaping in shell scripts.

As a RFE, systemd-udev could provide not only $devnode, but also an escaped form of the same.
Comment 3 Harald Hoyer 2013-10-29 09:21:04 EDT
(In reply to Michal Schmidt from comment #2)
> An escaped name would be "lvm2-pvscan@dev-dm\x2d0.service". But I don't
> think we provide a tool to perform easy (un-)escaping in shell scripts.

bash:

dev_unit_name()
{
    _name="${1%%/}"
    _name="${_name##/}"
    _name="${_name//-/\x2d}"
    _name="${_name//\//-}"
    echo "$_name"
}

$ dev_unit_name /dev/dm/0
dev-dm-0

$ dev_unit_name /dev/dm-0
dev-dm\x2d0
Comment 4 Harald Hoyer 2013-10-29 09:22:34 EDT
(In reply to Michal Schmidt from comment #2)
> As a RFE, systemd-udev could provide not only $devnode, but also an escaped
> form of the same.

I agree
Comment 5 Peter Rajnoha 2013-10-30 11:16:33 EDT
Finally, I've changed major:minor instead of device name for the instantiated service. But still, please, provide the escaped form of $devnode in udev as well for anybody else who could hit this problem again...
Comment 6 Lennart Poettering 2013-11-27 08:56:10 EST
Note that SYSTEMD_WANTS in udev rules expects properly escape unit names, but also takes unescaped ones, which when that is detected are automatically escaped. This follows the same rules as "systemctl status <foobar>" will automatically escape <foobar> if it is detected not to be already escaped.

Then, from inside the unit files there is %i and %I, one to access the escpaed, ant the other to access the unescaped instance part of the name.
Comment 7 RHEL Product and Program Management 2014-03-22 02:35:22 EDT
This request was not resolved in time for the current release.
Red Hat invites you to ask your support representative to
propose this request, if still desired, for consideration in
the next release of Red Hat Enterprise Linux.
Comment 8 Harald Hoyer 2015-03-24 06:14:38 EDT
(In reply to Lennart Poettering from comment #6)
> Note that SYSTEMD_WANTS in udev rules expects properly escape unit names,
> but also takes unescaped ones, which when that is detected are automatically
> escaped. This follows the same rules as "systemctl status <foobar>" will
> automatically escape <foobar> if it is detected not to be already escaped.
> 
> Then, from inside the unit files there is %i and %I, one to access the
> escpaed, ant the other to access the unescaped instance part of the name.

Does not work for "-" in the original name, because that will be converted to "/" in the unescaped "%I" version.

Note You need to log in before you can comment on or make changes to this bug.