systemd alsa-restore doesn't work
Describe your issue
What's the expected behaviour?
# systemctl status alsa-restore
...
Mar 21 10:01:20 samsung-rossa systemd[1]: Starting Save/Restore Sound Card State...
Mar 21 10:01:20 samsung-rossa systemd[1]: Finished Save/Restore Sound Card State.
What's the current behaviour?
Mar 17 10:06:08 samsung-rossa systemd[1]: Starting Save/Restore Sound Card State...
Mar 17 10:06:08 samsung-rossa alsactl[1100]: /usr/sbin/alsactl: state_lock:168: file /var/lib/alsa/asound.state lock error: No such file or directory
Mar 17 10:06:08 samsung-rossa alsactl[1100]: /usr/sbin/alsactl: load_state:1715: Cannot open /var/lib/alsa/asound.state for reading: No such file or directory
Mar 17 10:06:08 samsung-rossa alsactl[1100]: /usr/sbin/alsactl: card_lock:197: card 0 lock error: No such file or directory
Mar 17 10:06:08 samsung-rossa systemd[1]: Finished Save/Restore Sound Card State.
How to reproduce your issue?
systemctl restart alsa-restore
What device are you using?
Samsung-rossa
On what postmarketOS version did you encounter the issue?
-
edge (
master
branch) -
v24.12
-
v24.06
(supported until 2025-01-23) -
I confirm that the issue still is present after running
sudo apk upgrade -a
On what environment did you encounter the issue?
Environments
- COSMIC
- GNOME Shell on Mobile
- Phosh
- Plasma Mobile
-
Sxmo (Wayland/Sway) Please post the output of
sxmo_version.sh
- Other: Please fill out
Which init system are you using?
- OpenRC
- systemd
How did you get postmarketOS image?
- from https://images.postmarketos.org
- I built it using pmbootstrap
- It was preinstalled on my device
Additional information
It's a locking problem (the directory where the lock file should be created doesn't exist). Check the source of alsactl.c:
#define SYS_LOCKPATH "/var/lock"
a default locking directory is used, unless a different one is chosen. /var/lock
doesn't exist in my phone.
The problem is trivial to fix, and there are at least three ways to fix it:
Option 1.- use the alsactl parameter --no-lock
Pro: easy
Con: the locking must be done for some reason
Option 2.- use the alsactl parameter --lock-dir
and state an existing directory
Pro: easy
Con: is that the only instance in which alsa needs locking? See later
Option 3.- Create the directory needed using a .conf file in /etc/tmpfiles.d/ (I use jr.conf to remind me that it's a local temporary solution)
# copied from Debian legacy.conf
d /run/lock 0755 root root -
L /var/lock - - - - ../run/lock
Pro: easy, two-line solution, and at least /run/lock
should always be present
Con: ??
After restart
$ ls -l /run/lock
total 8
-rw-r--r-- 1 root root 22 Mar 21 10:01 asound.state.lock
-rw-r--r-- 1 root root 22 Mar 21 10:01 card0.lock
$ ls -l /var/lib/alsa/
total 16
-rw-r--r-- 1 root root 13307 Mar 20 09:51 asound.state
Obviously I prefer option 3.