I want to use a sleep hook of xsecurelock to auto-lock X before suspend or sleep.
But the unit file I used before does not work recently. The file is from ref1 and ref2, like this one.
My problem is similar to this issue https://github.com/google/xsecurelock/issues/117. It is caused by the incorrect environment variable XAUTHORITY=/home/%i/.Xauthority which is out-of-date, according to the man of sddm.conf.
xsecurelock[279181]: Invalid MIT-MAGIC-COOKIE-1 key
xsecurelock[279181]: xsecurelock: Could not connect to $DISPLAY.
# man sddm.conf
The UserAuthFile= option was removed, the file is always created as /tmp/xauth_XXXXX. This is necessary for to the use of FamilyWild entries.
The path of UserAuthFile is easier to get in user session than in systems system slice.
[$] echo $XAUTHORITY
/tmp/xauth_ZtesOe
[$] xauth -v list | head -n1 | cut -d' ' -f4
/tmp/xauth_ZtesOe
At first, I try to figure out how to get user's XAUTHORITY in system service /etc/systemd/system/xsecurelock@.service,
but enn... then I find that user service is already aware of XAUTHORITY, and we can call user service in a system sleep service. So a different way to deal with this problem by two unit file is tried, as shown below. A backup url.
Another tip: the Type in sleep@.service can be simple or exec, but oneshot and forking will interrupt the sleep process! See more
[$] cat /etc/systemd/system/sleep@.service
# path: /etc/systemd/system/sleep@.service
[Unit]
Description=Call user's sleep service before system suspend/sleep target
Before=sleep.target
[Service]
# oneshot,forking: user unit up, breaks sleep; simple,exec: ok
Type=simple
ExecStart=/usr/bin/systemctl --user --machine=%i@ start --wait xsecurelock.service
[Install]
WantedBy=sleep.target
Although the issue is solved, I still want to know if we can auto-set XAUTHORITY=/tmp/xauth_XXXXX in the system unit file /etc/systemd/system/xsecurelock@.service.
I want to use a sleep hook of xsecurelock to auto-lock X before suspend or sleep. But the unit file I used before does not work recently. The file is from ref1 and ref2, like this one. My problem is similar to this issue https://github.com/google/xsecurelock/issues/117. It is caused by the incorrect environment variable
XAUTHORITY=/home/%i/.Xauthority
which is out-of-date, according to the man ofsddm.conf
.The path of
UserAuthFile
is easier to get in user session than in systems system slice.At first, I try to figure out how to get user's XAUTHORITY in system service
/etc/systemd/system/xsecurelock@.service
, but enn... then I find that user service is already aware of XAUTHORITY, and we can call user service in a system sleep service. So a different way to deal with this problem by two unit file is tried, as shown below. A backup url. Another tip: theType
insleep@.service
can besimple
orexec
, butoneshot
andforking
will interrupt the sleep process! See moreAlthough the issue is solved, I still want to know if we can auto-set
XAUTHORITY=/tmp/xauth_XXXXX
in the system unit file/etc/systemd/system/xsecurelock@.service
.