You are not logged in.

#1 2022-10-26 10:53:03

schard
Member
From: Hannover
Registered: 2016-05-06
Posts: 1,933
Website

systemd unit - wait for touch screen available

I have a systemd unit to debug touch events:

 $ cat /usr/lib/systemd/system/touchscreen-log.service 
[Unit]
Description = Log touch screen events

[Service]
ExecStart = /usr/bin/evtest /dev/input/by-id/usb-Silicon_Works_Multi-touch_Device-event-if00

[Install]
WantedBy = multi-user.target

However, the autostart does not work, since the touch device is not yet available when the unit starts:

$ journalctl -au touchscreen-log.service --follow
Okt 26 12:14:14 1545 systemd[1]: Started Log touch screen events.
Okt 26 12:14:14 1545 evtest[311]: evtest: No such file or directory
Okt 26 12:14:14 1545 systemd[1]: touchscreen-log.service: Main process exited, code=exited, status=1/FAILURE
Okt 26 12:14:14 1545 systemd[1]: touchscreen-log.service: Failed with result 'exit-code'.

When I start it manually, all is fine:

$ systemctl start touchscreen-log.service
$ systemctl status touchscreen-log.service
● touchscreen-log.service - Log touch screen events
     Loaded: loaded (/usr/lib/systemd/system/touchscreen-log.service; enabled; preset: disabled)
     Active: active (running) since Wed 2022-10-26 12:48:43 CEST; 2min 59s ago
   Main PID: 320 (evtest)
      Tasks: 1 (limit: 4519)
     Memory: 236.0K
        CPU: 3ms
     CGroup: /system.slice/touchscreen-log.service
             └─320 /usr/bin/evtest /dev/input/by-id/usb-Silicon_Works_Multi-touch_Device-event-if00

Okt 26 12:48:43 1545 evtest[320]:       Resolution     210
Okt 26 12:48:43 1545 evtest[320]:     Event code 57 (ABS_MT_TRACKING_ID)
Okt 26 12:48:43 1545 evtest[320]:       Value      0
Okt 26 12:48:43 1545 evtest[320]:       Min        0
Okt 26 12:48:43 1545 evtest[320]:       Max    65535
Okt 26 12:48:43 1545 evtest[320]:   Event type 4 (EV_MSC)
Okt 26 12:48:43 1545 evtest[320]:     Event code 5 (MSC_TIMESTAMP)
Okt 26 12:48:43 1545 evtest[320]: Properties:
Okt 26 12:48:43 1545 evtest[320]:   Property type 1 (INPUT_PROP_DIRECT)
Okt 26 12:48:43 1545 evtest[320]: Testing ... (interrupt to exit)

My question is: Which unit or target do I need to wait for (After=) for the touch device to be available?

Offline

#2 2022-10-26 13:21:44

seth
Member
Registered: 2012-09-03
Posts: 49,999

Online

#3 2022-10-28 10:25:00

schard
Member
From: Hannover
Registered: 2016-05-06
Posts: 1,933
Website

Re: systemd unit - wait for touch screen available

Yeah, I already tried that to no avail.
The udev rule does not trigger, so the service waits for the device node forever.

Offline

#4 2022-10-28 11:00:54

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,427

Re: systemd unit - wait for touch screen available

You could also create a systemd.path unit that will trigger your service once the path exists: https://www.freedesktop.org/software/sy … .path.html

Regarding the device dependencies, do you not potentially already have a device to hook on/ check

systemctl list-units --type device

Offline

#5 2022-10-28 11:04:44

schard
Member
From: Hannover
Registered: 2016-05-06
Posts: 1,933
Website

Re: systemd unit - wait for touch screen available

Excellent idea regarding the path unit.
As for the device units:

$ systemctl list-units --type device --no-pager
  UNIT                                                                                     LOAD   ACTIVE SUB     DESCRIPTION                                                                                                     
  sys-devices-pci0000:00-0000:00:02.0-drm-card0-card0\x2deDP\x2d1-intel_backlight.device   loaded active plugged /sys/devices/pci0000:00/0000:00:02.0/drm/card0/card0-eDP-1/intel_backlight
  sys-devices-pci0000:00-0000:00:13.0-ata2-host1-target1:0:0-1:0:0:0-block-sda-sda1.device loaded active plugged ADATA_IMSS316-256GD EFI
  sys-devices-pci0000:00-0000:00:13.0-ata2-host1-target1:0:0-1:0:0:0-block-sda-sda2.device loaded active plugged ADATA_IMSS316-256GD root
  sys-devices-pci0000:00-0000:00:13.0-ata2-host1-target1:0:0-1:0:0:0-block-sda.device      loaded active plugged ADATA_IMSS316-256GD
  sys-devices-pci0000:00-0000:00:1b.0-sound-card0-controlC0.device                         loaded active plugged /sys/devices/pci0000:00/0000:00:1b.0/sound/card0/controlC0
  sys-devices-pci0000:00-0000:00:1c.2-0000:03:00.0-net-enp3s0.device                       loaded active plugged RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (RTL8111/8168 PCI Express Gigabit Ethernet controller)
  sys-devices-pci0000:00-0000:00:1c.3-0000:04:00.0-net-enp4s0.device                       loaded active plugged RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (RTL8111/8168 PCI Express Gigabit Ethernet controller)
  sys-devices-platform-serial8250-tty-ttyS10.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS10
  sys-devices-platform-serial8250-tty-ttyS11.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS11
  sys-devices-platform-serial8250-tty-ttyS12.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS12
  sys-devices-platform-serial8250-tty-ttyS13.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS13
  sys-devices-platform-serial8250-tty-ttyS14.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS14
  sys-devices-platform-serial8250-tty-ttyS15.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS15
  sys-devices-platform-serial8250-tty-ttyS16.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS16
  sys-devices-platform-serial8250-tty-ttyS17.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS17
  sys-devices-platform-serial8250-tty-ttyS18.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS18
  sys-devices-platform-serial8250-tty-ttyS19.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS19
  sys-devices-platform-serial8250-tty-ttyS20.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS20
  sys-devices-platform-serial8250-tty-ttyS21.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS21
  sys-devices-platform-serial8250-tty-ttyS22.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS22
  sys-devices-platform-serial8250-tty-ttyS23.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS23
  sys-devices-platform-serial8250-tty-ttyS24.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS24
  sys-devices-platform-serial8250-tty-ttyS25.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS25
  sys-devices-platform-serial8250-tty-ttyS26.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS26
  sys-devices-platform-serial8250-tty-ttyS27.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS27
  sys-devices-platform-serial8250-tty-ttyS28.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS28
  sys-devices-platform-serial8250-tty-ttyS29.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS29
  sys-devices-platform-serial8250-tty-ttyS30.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS30
  sys-devices-platform-serial8250-tty-ttyS31.device                                        loaded active plugged /sys/devices/platform/serial8250/tty/ttyS31
  sys-devices-platform-serial8250-tty-ttyS4.device                                         loaded active plugged /sys/devices/platform/serial8250/tty/ttyS4
  sys-devices-platform-serial8250-tty-ttyS5.device                                         loaded active plugged /sys/devices/platform/serial8250/tty/ttyS5
  sys-devices-platform-serial8250-tty-ttyS6.device                                         loaded active plugged /sys/devices/platform/serial8250/tty/ttyS6
  sys-devices-platform-serial8250-tty-ttyS7.device                                         loaded active plugged /sys/devices/platform/serial8250/tty/ttyS7
  sys-devices-platform-serial8250-tty-ttyS8.device                                         loaded active plugged /sys/devices/platform/serial8250/tty/ttyS8
  sys-devices-platform-serial8250-tty-ttyS9.device                                         loaded active plugged /sys/devices/platform/serial8250/tty/ttyS9
  sys-devices-pnp0-00:05-tty-ttyS0.device                                                  loaded active plugged /sys/devices/pnp0/00:05/tty/ttyS0
  sys-devices-pnp0-00:06-tty-ttyS1.device                                                  loaded active plugged /sys/devices/pnp0/00:06/tty/ttyS1
  sys-devices-pnp0-00:07-tty-ttyS2.device                                                  loaded active plugged /sys/devices/pnp0/00:07/tty/ttyS2
  sys-devices-pnp0-00:08-tty-ttyS3.device                                                  loaded active plugged /sys/devices/pnp0/00:08/tty/ttyS3
  sys-devices-virtual-misc-rfkill.device                                                   loaded active plugged /sys/devices/virtual/misc/rfkill
  sys-devices-virtual-net-terminals.device                                                 loaded active plugged /sys/devices/virtual/net/terminals
  sys-module-configfs.device                                                               loaded active plugged /sys/module/configfs
  sys-module-fuse.device                                                                   loaded active plugged /sys/module/fuse
  sys-subsystem-net-devices-enp3s0.device                                                  loaded active plugged RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (RTL8111/8168 PCI Express Gigabit Ethernet controller)
  sys-subsystem-net-devices-enp4s0.device                                                  loaded active plugged RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (RTL8111/8168 PCI Express Gigabit Ethernet controller)
  sys-subsystem-net-devices-terminals.device                                               loaded active plugged /sys/subsystem/net/devices/terminals

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.
46 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
$ ls -la /dev/input/by-id/usb-Silicon_Works_Multi-touch_Device-event-if00
lrwxrwxrwx 1 root root 9 26. Okt 14:18 /dev/input/by-id/usb-Silicon_Works_Multi-touch_Device-event-if00 -> ../event5

Update:
I was stupid. The udev rule works and I forgot to put the escaped systemd unit name into quotation marks:

0 ✓ 1545 ~ $ systemctl status dev-input-by\x2did-usb\x2dSilicon_Works_Multi\x2dtouch_Device\x2devent\x2dif00.device
○ dev-input-byx2did-usbx2dSilicon_Works_Multix2dtouch_Devicex2deventx2dif00.device - /dev/input/byx2did/usbx2dSilicon_Works_Multix2dtouch_Devicex2deventx2dif00
     Loaded: loaded
     Active: inactive (dead)
3 ✗ 1545 ~ $ systemctl status "dev-input-by\x2did-usb\x2dSilicon_Works_Multi\x2dtouch_Device\x2devent\x2dif00.device"
● dev-input-by\x2did-usb\x2dSilicon_Works_Multi\x2dtouch_Device\x2devent\x2dif00.device - Multi-touch_Device
    Follows: unit currently follows state of sys-devices-pci0000:00-0000:00:14.0-usb1-1\x2d3-1\x2d3.1-1\x2d3.1:1.0-0003:29BD:4101.0001-input-input10-event5.device
     Loaded: loaded
     Active: active (plugged) since Fri 2022-10-28 13:18:07 CEST; 2min 24s ago
      Until: Fri 2022-10-28 13:18:07 CEST; 2min 24s ago
     Device: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3.1/1-3.1:1.0/0003:29BD:4101.0001/input/input10/event5

But still the unit fails:

0 ✓ 1545 ~ $ cat /usr/lib/systemd/system/touchscreen-log.service
[Unit]
Description=Log touch screen events
Requires=dev-input-by\x2did-usb\x2dSilicon_Works_Multi\x2dtouch_Device\x2devent\x2dif00.device
After=dev-input-by\x2did-usb\x2dSilicon_Works_Multi\x2dtouch_Device\x2devent\x2dif00.device

[Service]
ExecStart=/usr/bin/evtest /dev/input/by-id/usb-Silicon_Works_Multi-touch_Device-event-if00

[Install]
WantedBy=multi-user.target
0 ✓ 1545 ~ $ systemctl status touchscreen-log.service 
× touchscreen-log.service - Log touch screen events
     Loaded: loaded (/usr/lib/systemd/system/touchscreen-log.service; enabled; preset: disabled)
     Active: failed (Result: exit-code) since Fri 2022-10-28 13:18:06 CEST; 2min 50s ago
   Duration: 35ms
    Process: 314 ExecStart=/usr/bin/evtest /dev/input/by-id/usb-Silicon_Works_Multi-touch_Device-event-if00 (code=exited, status=1/FAILURE)
   Main PID: 314 (code=exited, status=1/FAILURE)
        CPU: 3ms

Okt 28 13:18:06 1545 systemd[1]: Started Log touch screen events.
Okt 28 13:18:06 1545 evtest[314]: evtest: No such file or directory
Okt 28 13:18:06 1545 systemd[1]: touchscreen-log.service: Main process exited, code=exited, status=1/FAILURE
Okt 28 13:18:06 1545 systemd[1]: touchscreen-log.service: Failed with result 'exit-code'.

Last edited by schard (2022-10-28 11:21:12)

Offline

#6 2022-10-28 15:07:18

seth
Member
Registered: 2012-09-03
Posts: 49,999

Re: systemd unit - wait for touch screen available

ExecStartPre=/usr/bin/sleep 0.5

?

Online

#7 2022-10-28 15:57:58

schard
Member
From: Hannover
Registered: 2016-05-06
Posts: 1,933
Website

Re: systemd unit - wait for touch screen available

That worked (now). But the question is whether it is stable, i.e. if the device will always be ready within half a second.

Offline

#8 2022-10-28 16:26:20

seth
Member
Registered: 2012-09-03
Posts: 49,999

Re: systemd unit - wait for touch screen available

That's the stupid thing about race conditions.

You could alternatively

while ! /usr/bin/evtest /dev/input/by-id/usb-Silicon_Works_Multi-touch_Device-event-if00; do sleep 0.1; done

or something stupid like that hmm

Online

Board footer

Powered by FluxBB