You are not logged in.

#1 2021-07-29 19:54:55

ethoman
Member
Registered: 2021-07-29
Posts: 2

[SOLVED] systemd-udevd: 'Process [process] failed with code 1'

I've been trying to set up a udev rule, which would disable/enable the touchpad when a mouse is plugged in/out.

cat /etc/udev/rules.d/01-touchpad.rules

KERNEL=="mouse[0-9]*", SUBSYSTEM=="input", ACTION=="add", RUN+="/usr/local/sbin/touchpadctl.sh -e"
KERNEL=="mouse[0-9]*", SUBSYSTEM=="input", ACTION=="remove", RUN+="/usr/local/sbin/touchpadctl.sh -d"

cat /usr/local/sbin/touchpadctl.sh

#!/bin/bash

# Enables (-e)/Disables (-d) the touchpad.
# Original author: lahwaacz at https://github.com/lahwaacz/Scripts/blob/master/toggle-touchpad.sh

# make sure that (only) one argument was supplied
if [ "$#" -ne 1 ]; then
        echo "Usage: -e|-d"
        exit 1
fi

# retrieve first instance of touchpad device
device="$(xinput list | grep -P '(?<=)[\w\s:]*(?i)(touchpad|synaptics)(?-i).*?(?=\s*id)' -o | head -n1 | xargs)"

if [ $1 == "-e" ]; then
        xinput enable "$device"
elif [ $1 == "-d" ]; then
        xinput disable "$device"
else
        echo "Usage: -e|-d"
        exit 1
fi

This successfully detects mouse add/remove events and subsequently invokes /usr/local/sbin/touchpadctl.sh. Although, the script fails (journalctl -b -u systemd-udevd.service):

Jul 29 21:44:05 arch systemd[1]: Starting Rule-based Manager for Device Events and Files...
Jul 29 21:44:05 arch systemd[1]: Started Rule-based Manager for Device Events and Files.
Jul 29 21:47:03 arch systemd-udevd[2953]: mouse0: Process '/usr/local/sbin/touchpadctl.sh -d' failed with exit code 1.
Jul 29 21:47:09 arch systemd-udevd[2974]: mouse0: Process '/usr/local/sbin/touchpadctl.sh -e' failed with exit code 1.

The lines that fail are:

xinput enable "$device"
xinput disable "$device"

The issue (I believe) is that systemd-udevd is invoked as a user that doesn't have write permissions and/or is blocked from such operations in some other way. This can be further illustrated by rewriting udev rules to (cat /etc/udev/rules.d/01-touchpad.rules):

KERNEL=="mouse[0-9]*", SUBSYSTEM=="input", ACTION=="add", RUN+="echo 'test' > /tmp/test.txt"

Resulting in (journalctl -b -u systemd-udevd.service):

Jul 29 22:22:51 arch systemd[1]: Starting Rule-based Manager for Device Events and Files...
Jul 29 22:22:51 arch systemd[1]: Started Rule-based Manager for Device Events and Files.
Jul 29 22:23:10 arch systemd-udevd[3190]: mouse0: Process 'echo 'test' > /tmp/test.txt' failed with exit code 1.

I've tried modifying the [Service] options at /etc/systemd/system/systemd-udevd.service (specifically, I've disabled the directives MemoryDenyWriteExecute and RestrictRealtime (as per this thread)) (cat /etc/systemd/system/systemd-udevd.service):

[Unit]
Description=Rule-based Manager for Device Events and Files
Documentation=man:systemd-udevd.service(8) man:udev(7)
DefaultDependencies=no
After=systemd-sysusers.service systemd-hwdb-update.service
Before=sysinit.target
ConditionPathIsReadWrite=/sys

[Service]
DeviceAllow=block-* rwm
DeviceAllow=char-* rwm
Type=notify
# Note that udev will reset the value internally for its workers
OOMScoreAdjust=-1000
Sockets=systemd-udevd-control.socket systemd-udevd-kernel.socket
Restart=always
RestartSec=0
ExecStart=/usr/lib/systemd/systemd-udevd
ExecReload=udevadm control --reload --timeout 0
KillMode=mixed
TasksMax=infinity
PrivateMounts=yes
ProtectClock=yes
ProtectHostname=yes
#MemoryDenyWriteExecute=yes
RestrictAddressFamilies=AF_UNIX AF_NETLINK AF_INET AF_INET6
#RestrictRealtime=yes
RestrictSUIDSGID=yes
SystemCallFilter=@system-service @module @raw-io
SystemCallErrorNumber=EPERM
SystemCallArchitectures=native
LockPersonality=yes
IPAddressDeny=any
WatchdogSec=3min

Although, that did not help. What could be the issue?

Last edited by ethoman (2021-07-29 21:28:21)

Offline

#2 2021-07-29 20:40:18

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,310

Re: [SOLVED] systemd-udevd: 'Process [process] failed with code 1'

The main issue here is that an udev rule does not run in your environment  and you don't do anything that would tell these xinput commands which xorg server they should connect to. You need to export DISPLAY=:0 and XAUTHORITY=/home/$usernamehere/.Xauthority at the very least. You could hardcode them as a simple test at the start of the file, technically you could also look for a process you know will be available and copy it's environment but I'd have to dig up that snippet.

Also incidentally xinput's error code for not being able to connect to a xorg server is 1 as well, so you might think that you are running into your "else" case while you aren't, you might want to change that.

I suggest you revert your changes to the udev services, they are unlikely to be the reason for your issue.

Last edited by V1del (2021-07-29 20:45:02)

Offline

#3 2021-07-29 21:15:04

ethoman
Member
Registered: 2021-07-29
Posts: 2

Re: [SOLVED] systemd-udevd: 'Process [process] failed with code 1'

V1del wrote:

The main issue here is that an udev rule does not run in your environment  and you don't do anything that would tell these xinput commands which xorg server they should connect to. You need to export DISPLAY=:0 and XAUTHORITY=/home/$usernamehere/.Xauthority at the very least.

Makes sense. I rewrote the udev rule as:

KERNEL=="mouse[0-9]*", SUBSYSTEM=="input", ACTION=="add", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/$username/.Xauthority", RUN+="/usr/local/sbin/touchpadctl.sh -d"
KERNEL=="mouse[0-9]*", SUBSYSTEM=="input", ACTION=="remove", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/$username/.Xauthority", RUN+="/usr/local/sbin/touchpadctl.sh -e"

This works as expected. Thank you.

V1del wrote:

Also incidentally xinput's error code for not being able to connect to a xorg server is 1 as well, so you might think that you are running into your "else" case while you aren't, you might want to change that.

I suggest you revert your changes to the udev services, they are unlikely to be the reason for your issue.

I should've checked this beforehand. Either way, thanks for the suggestions.

Last edited by ethoman (2021-07-29 21:15:38)

Offline

Board footer

Powered by FluxBB