Bug 1020887
| Summary: | RFE: add escaped form of $devnode for use in udev rules | ||
|---|---|---|---|
| Product: | Red Hat Enterprise Linux 7 | Reporter: | Peter Rajnoha <prajnoha> |
| Component: | systemd | Assignee: | systemd-maint |
| Status: | CLOSED WONTFIX | QA Contact: | qe-baseos-daemons |
| Severity: | high | Docs Contact: | |
| Priority: | medium | ||
| Version: | 7.0 | CC: | agk, harald, jsynacek, lnykryn, mschmidt, systemd-maint-list |
| Target Milestone: | rc | Keywords: | FutureFeature |
| Target Release: | --- | ||
| Hardware: | All | ||
| OS: | Linux | ||
| Whiteboard: | |||
| Fixed In Version: | Doc Type: | Enhancement | |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2016-11-09 13:39:53 UTC | Type: | Bug |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
| Embargoed: | |||
| Bug Depends On: | |||
| Bug Blocks: | 1297395 | ||
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. (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 (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 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... 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. 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. (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. |
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.