Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Services asked for by UDEV do not get triggered #7109

Closed
tillkamppeter opened this issue Oct 16, 2017 · 20 comments
Closed

Services asked for by UDEV do not get triggered #7109

tillkamppeter opened this issue Oct 16, 2017 · 20 comments
Labels
needs-reporter-feedback ❓ There's an unanswered question, the reporter needs to answer pid1 udev

Comments

@tillkamppeter
Copy link

Submission type

  • Bug report

systemd version the issue has been seen with

234

Used distribution

Ubuntu Artful, 17.10

In case of bug report: Expected behaviour you didn't see

Setting TAG+="systemd" and ENV{SYSTEMD_WANTS}+="..." should make the requested systemd service to be started. See Ubuntu bug report linked below.

In case of bug report: Unexpected behaviour you saw

Service does not get started, but one can start it manually using sudo systemd start ....

In case of bug report: Steps to reproduce the problem

Connect a USB printer. This triggers the UDEV rule file /lib/udev/rules.d/70-printers.rules as shown in the Ubuntu bug report. The printer setup service (and if needed ippusbxd) do not get started. Manually starting the service (exact name in the SYSTEMD_WANTS line of the udevadm monitor --environment) output) with sudo systemd start ... starts the service correctly.

Please see all files, commands, configurations, and discussion up to now in the following Ubuntu bug report:

https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1721839

Especially note that the first assumption was a character escaping problem but fixing the UDEV rules file does not solve the problem. The problem stays as it is.

I will not copy all files and comments to here, see the Ubuntu bug report for them.

@poettering
Copy link
Member

is the dependency from the device unit onto the service unit shown in the "systemctl show" output of the device unit?

@poettering poettering added needs-reporter-feedback ❓ There's an unanswered question, the reporter needs to answer pid1 udev labels Oct 23, 2017
@tillkamppeter
Copy link
Author

Which is the device unit in my case? And which is the service unit?

@tillkamppeter
Copy link
Author

Attached: Output of

systemctl show 'sys-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.device' > systemctl-show-deskjet2540.txt

systemctl-show-deskjet2540.txt

@tillkamppeter
Copy link
Author

Found the device unit name by some tinkering:

till@till-x1carbon:~$ systemctl list-dependencies 'udev-configure-printer@-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.service'
udev-configure-printer@-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.service
● ├─cups.socket
● ├─system-udev\x2dconfigure\x2dprinter.slice
● └─sysinit.target
●   ├─apparmor.service
●   ├─console-setup.service
●   ├─dev-hugepages.mount
●   ├─dev-mqueue.mount
●   ├─friendly-recovery.service
●   ├─keyboard-setup.service
●   ├─kmod-static-nodes.service
●   ├─lvm2-lvmetad.socket
●   ├─lvm2-lvmpolld.socket
●   ├─lvm2-monitor.service
●   ├─plymouth-read-write.service
●   ├─plymouth-start.service
●   ├─proc-sys-fs-binfmt_misc.automount
●   ├─resolvconf.service
●   ├─rpcbind.service
●   ├─setvtrgb.service
●   ├─sys-fs-fuse-connections.mount
●   ├─sys-kernel-config.mount
●   ├─sys-kernel-debug.mount
till@till-x1carbon:~$ systemctl list-dependencies --reverse cups.service
cups.service
● ├─cups-browsed.service
● └─printer.target
●   └─sys-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.device
till@till-x1carbon:~$

@poettering
Copy link
Member

So, the relevant line in the "systemctl show" output is this one:

Wants=printer.target udev-configure-printer@-devices-pci0000:00-0000:00:14.0-usb2-2x2d2.service

Which doesn't really match what you are expecting, right? Because that is udev-configure-printer@-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.service

@tillkamppeter
Copy link
Author

And I got the above result with the corrected 70-printers.rules file:

# Low-level USB device add trigger
ACTION=="add", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{ID_USB_INTERFACES}=="*:0701??:*", TAG+="udev-configure-printer", TAG+="systemd", PROGRAM="/bin/systemd-escape --template=udev-configure-printer@.service %p", ENV{SYSTEMD_WANTS}+="'%c'"
# Low-level USB device remove trigger
ACTION=="remove", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{ID_USB_INTERFACES}=="*:0701*:*", RUN+="udev-configure-printer remove %p"

See the

ENV{SYSTEMD_WANTS}+="'%c'"

at the end of the first rule.

@poettering
Copy link
Member

btw, you really should use systemd-escape's --path argument for cases like this

@tillkamppeter
Copy link
Author

I tried adding --path now. The /lib/udev/rules.d/70-printers.rules looks like this now:

# Low-level USB device add trigger
ACTION=="add", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{ID_USB_INTERFACES}=="*:0701??:*", TAG+="udev-configure-printer", TAG+="systemd", PROGRAM="/bin/systemd-escape --path --template=udev-configure-printer@.service %p", ENV{SYSTEMD_WANTS}+="'%c'"
# Low-level USB device remove trigger
ACTION=="remove", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{ID_USB_INTERFACES}=="*:0701*:*", RUN+="udev-configure-printer remove %p"

As this also removes the leading slash from the path inserted in the service name I counteract this by adding a slash at the appropriate place in the udev-configure-printer command line in /lib/systemd/system/udev-configure-printer@.service making the file look like this:

[Unit]
Description=Automatic USB/Bluetooth printer setup (%i)
Requires=cups.socket
After=cups.socket

[Service]
#Type=simple
Type=forking
GuessMainPID=true
ExecStart=/lib/udev/udev-configure-printer add /%I
# This ExecStop would be useful to disable the print queue when ippusbxd
# crashes or gets killed, but in the case that ippusbxd does not get started
# at all during the process run by ExecStart (printer does not support
# IPP-over-USB) ExecStop gets run immediately making a printer getting
# disabled again right after it getting enabled or set up
# ExecStop=/lib/udev/udev-configure-printer remove %I

Result is the same. Service does not start when plugging the printer but with printer plugged one can start it manually with sudo systemctl start ....

Problem is still with the escaping and unescaping. udevadm monitor --environment while plugging contains correct

SYSTEMD_WANTS='udev-configure-printer@devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.service' printer.target

(note that service name has changed slightly, no - between @ and devices, used this device name when successfully started the service manually).
systemctl show 'sys-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.device' > systemctl-show-deskjet2540-2.txt still shows the wrong unescaping:

SysFSPath=/sys/devices/pci0000:00/0000:00:14.0/usb2/2-2
Id=sys-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.device
Names=sys-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.device
Wants=printer.target udev-configure-printer@devices-pci0000:00-0000:00:14.0-usb2-2x2d2.service
Description=Deskjet_2540_series
LoadState=loaded
ActiveState=active
SubState=plugged
StateChangeTimestamp=Wed 2017-10-25 08:21:54 -02
StateChangeTimestampMonotonic=3690016
InactiveExitTimestamp=Wed 2017-10-25 08:21:54 -02
InactiveExitTimestampMonotonic=3690016
ActiveEnterTimestamp=Wed 2017-10-25 08:21:54 -02
ActiveEnterTimestampMonotonic=3690016
ActiveExitTimestampMonotonic=0
InactiveEnterTimestampMonotonic=0
CanStart=no
CanStop=no
CanReload=no
CanIsolate=no
StopWhenUnneeded=no
RefuseManualStart=no
RefuseManualStop=no
AllowIsolate=no
DefaultDependencies=yes
OnFailureJobMode=replace
IgnoreOnIsolate=yes
NeedDaemonReload=no
JobTimeoutUSec=infinity
JobRunningTimeoutUSec=1min 30s
JobTimeoutAction=none
ConditionResult=no
AssertResult=no
ConditionTimestampMonotonic=0
AssertTimestampMonotonic=0
Transient=no
Perpetual=no
StartLimitIntervalSec=10000000
StartLimitBurst=5
StartLimitAction=none
InvocationID=4ed24799e889439cbb5a929fdbaa8189

Relevant line:

Wants=printer.target udev-configure-printer@devices-pci0000:00-0000:00:14.0-usb2-2x2d2.service

@poettering
Copy link
Member

Use %f in unit files, to undo the escaping systemd-escape --path does

@tillkamppeter
Copy link
Author

%f also does not work, same result as before.

poettering added a commit to poettering/systemd that referenced this issue Oct 26, 2017
…e it with sysfs path

This should make cases like the user's setup in systemd#7109 a lot easier to
handle, as in that case we'll do the right escaping automatically.
@tillkamppeter
Copy link
Author

I have applied the patch now and tried again, without success. The /lib/udev/rules.d/70-printers.rules looks like this now:

# Low-level USB device add trigger
ACTION=="add", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{ID_USB_INTERFACES}=="*:0701??:*", TAG+="udev-configure-printer", TAG+="systemd", PROGRAM="/bin/systemd-escape --path --template=udev-configure-printer@.service %p", ENV{SYSTEMD_WANTS}+="'%c'"
# Low-level USB device remove trigger
ACTION=="remove", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{ID_USB_INTERFACES}=="*:0701*:*", RUN+="udev-configure-printer remove %p"

The /lib/systemd/system/udev-configure-printer@.service contains:

[Unit]
Description=Automatic USB/Bluetooth printer setup (%f)
Requires=cups.socket
After=cups.socket

[Service]
#Type=simple
Type=forking
GuessMainPID=true
ExecStart=/lib/udev/udev-configure-printer add /%f
# This ExecStop would be useful to disable the print queue when ippusbxd
# crashes or gets killed, but in the case that ippusbxd does not get started
# at all during the process run by ExecStart (printer does not support
# IPP-over-USB) ExecStop gets run immediately making a printer getting
# disabled again right after it getting enabled or set up
# ExecStop=/lib/udev/udev-configure-printer remove /%f

In this file I also tried %I and %i instead of %f, with the same unsuccessful result.
In the output of udevadm monitor --environment I get

DEVPATH=/devices/pci0000:00/0000:00:14.0/usb2/2-2
SYSTEMD_WANTS='udev-configure-printer@devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.service' printer.target

With

systemctl show 'sys-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.device' > systemctl-show-deskjet2540-6.txt

I get

SysFSPath=/sys/devices/pci0000:00/0000:00:14.0/usb2/2-2
Id=sys-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.device
Names=sys-devices-pci0000:00-0000:00:14.0-usb2-2\x2d2.device
Wants=printer.target udev-configure-printer@devices-pci0000:00-0000:00:14.0-usb2-2x2d2.service
[...]

and in /var/log/syslog the following appears:

Oct 26 17:52:56 till-x1carbon systemd[1]: Starting Automatic USB/Bluetooth printer setup (/devices/pci0000:00/0000:00:14.0/usb2/2x2d2)...
Oct 26 17:52:56 till-x1carbon udev-configure-printer[6479]: add //devices/pci0000:00/0000:00:14.0/usb2/2x2d2
Oct 26 17:52:56 till-x1carbon udev-configure-printer[6479]: unable to access /sys//devices/pci0000:00/0000:00:14.0/usb2/2x2d2
Oct 26 17:52:56 till-x1carbon systemd[1]: udev-configure-printer@devices-pci0000:00-0000:00:14.0-usb2-2x2d2.service: Control process exited, code=exited status=1
Oct 26 17:52:56 till-x1carbon systemd[1]: Failed to start Automatic USB/Bluetooth printer setup (/devices/pci0000:00/0000:00:14.0/usb2/2x2d2).
Oct 26 17:52:56 till-x1carbon systemd[1]: udev-configure-printer@devices-pci0000:00-0000:00:14.0-usb2-2x2d2.service: Unit entered failed state.

This means that udev-configure-printer gets called but the backslash gets lost somewhere and so the unescaping does not work.

@lulandco
Copy link

lulandco commented Nov 5, 2017

Hi,
Same here. My service unit (without instance) is no more triggered by udev in artful on usb plug. BUT, it reworks when I plug the device in another usb port. One used usb port can't be reused to trigger the service unit except restarting the system. Could It be a udev issue ?

poettering added a commit to poettering/systemd that referenced this issue Nov 9, 2017
…e it with sysfs path

This should make cases like the user's setup in systemd#7109 a lot easier to
handle, as in that case we'll do the right escaping automatically.
poettering added a commit to poettering/systemd that referenced this issue Nov 10, 2017
…e it with sysfs path

This should make cases like the user's setup in systemd#7109 a lot easier to
handle, as in that case we'll do the right escaping automatically.
poettering added a commit to poettering/systemd that referenced this issue Nov 10, 2017
…e it with sysfs path

This should make cases like the user's setup in systemd#7109 a lot easier to
handle, as in that case we'll do the right escaping automatically.
poettering added a commit to poettering/systemd that referenced this issue Nov 10, 2017
…e it with sysfs path

This should make cases like the user's setup in systemd#7109 a lot easier to
handle, as in that case we'll do the right escaping automatically.
@tillkamppeter
Copy link
Author

@poettering, what do you want with the patches 2460091 and
2273473? They are absolutely identical with the patch
f92d2d1 from 15 days ago which I tested and which did not solve the problem for me.

@tillkamppeter
Copy link
Author

tillkamppeter commented Nov 10, 2017

Also the patches fec1261 and dcebc9b are the same as the first patch which did not work for me.

@reddevillg
Copy link

Anything news on this?

i found the device units is still exist after printer unplugged

systemctl list-units | grep Printer
sys-devices-pci0000:00-0000:00:1d.0-usb2-2\x2d1-2\x2d1.2.device             loaded active plugged   Printer
printer.target                                                              loaded active active    Printer

but there is no 2-1.2 actually

ls /sys/devices/pci0000\:00/0000\:00\:1d.0/usb2/2-1/
2-1:1.0            bcdDevice            bDeviceSubClass  bNumConfigurations  descriptors  driver     ltm_capable  quirks     subsystem
2-1.5              bConfigurationValue  bmAttributes     bNumInterfaces      dev          ep_00      maxchild     removable  uevent
authorized         bDeviceClass         bMaxPacketSize0  busnum              devnum       idProduct  port         remove     urbnum
avoid_reset_quirk  bDeviceProtocol      bMaxPower        configuration       devpath      idVendor   power        speed      version

@buczek
Copy link
Contributor

buczek commented Apr 7, 2018

@lulandco , @tillkamppeter : Devices units not going away after unplug, same as #7587,#8221 ? Please verify with udevadm monitor -p systemd.

@hadess
Copy link
Contributor

hadess commented Apr 18, 2018

I ran into a similar problem with usbmuxd. This is the rules file for it:
https://cgit.sukimashita.com/usbmuxd.git/tree/udev/39-usbmuxd.rules.in
(@udev_activation_rule@ is ENV{SYSTEMD_WANTS}="usbmuxd.service" on most systems)

When plugging it in (truncated for readability):

UDEV  [5484.796621] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.1/3-3.1.1 (usb)
ACTION=add
ID_MODEL=iPhone
SYSTEMD_WANTS=usbmuxd.service
USBMUX_SUPPORTED=1

UDEV  [5484.802387] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.1/3-3.1.1/3-3.1.1:1.0 (usb)
ACTION=add

UDEV  [5484.807653] bind     /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.1/3-3.1.1 (usb)
ACTION=bind
ID_MODEL=iPhone

The SYSTEMD_WANTS, and USBMUX_SUPPORTED attributes are just gone. There's a single event for a sub-device between the add and bind events.

nikias pushed a commit to libimobiledevice/usbmuxd that referenced this issue Apr 18, 2018
Make sure that udev doesn't lose our properties when bind events come
in, as implemented in kernels 4.12+.

See systemd/systemd#8221
and systemd/systemd#7109
@Alexander-Shukaev
Copy link

See https://superuser.com/a/1401322/166253 for workaround.

sde1000 added a commit to sde1000/daliserver that referenced this issue Feb 5, 2019
Useful references:
 - systemd/systemd#7109
 - systemd/systemd#10321
 - systemd/systemd@dcebc9b

Quick summary: there are still escaping-related misfeatures in systemd
that can't be worked around using systemd-escape.  For our particular
use-case, @poettering has implemented a workaround that happens to do
what we want; this commit switches over to using it (although this
introduces a requirement that we use systemd version 236 or later).  The
general case is still broken.
@poettering
Copy link
Member

So my educated guess is that this is just another issue triggered by this kernel fuck-up: #7587

THis is all about usb devices after all, i.e. those which get bvind/unbind events...

awilliam added a commit to mdevctl/mdevctl that referenced this issue Dec 5, 2019
The escaping of the hyphens in the UUID of the device path is getting
lost between SYSTEMD_WANTS= and the Wants= of the resulting device as
seen in 'systemctl show'.  This means that our unit templat is getting
called with 'x2d' in place of the hyphens rather than '\x2d' and the
systemd-escape unmangling falls apart resulting in failed services.
This is similar to systemd/systemd#7109,
which references a commit which became:

dcebc9bae4dc ("core: when a unit template is specified in SYSTEMD_WANTS=, instantiate it with sysfs path")

This is included since v236 and allows us to simply let systemd fill
in the escaped device path if we only supply the service template.
We can then also remove the mdevctl script code previously necessary
to generate that path.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
@poettering
Copy link
Member

Let's close this one, now that #7587 was addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-reporter-feedback ❓ There's an unanswered question, the reporter needs to answer pid1 udev
Development

No branches or pull requests

7 participants