RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1020887 - RFE: add escaped form of $devnode for use in udev rules
Summary: RFE: add escaped form of $devnode for use in udev rules
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: systemd
Version: 7.0
Hardware: All
OS: Linux
medium
high
Target Milestone: rc
: ---
Assignee: systemd-maint
QA Contact: qe-baseos-daemons
URL:
Whiteboard:
Depends On:
Blocks: 1297395
TreeView+ depends on / blocked
 
Reported: 2013-10-18 12:52 UTC by Peter Rajnoha
Modified: 2016-11-09 13:50 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: Enhancement
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-11-09 13:39:53 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Peter Rajnoha 2013-10-18 12:52:50 UTC
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

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 13:15:53 UTC
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 13:21:04 UTC
(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 13:22:34 UTC
(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 15:16:33 UTC
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 13:56:10 UTC
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 Program Management 2014-03-22 06:35:22 UTC
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 10:14:38 UTC
(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.