You are not logged in.

#1 2023-05-31 16:45:06

christian-oudard
Member
Registered: 2023-02-15
Posts: 3

acpid, XDG_RUNTIME_DIR for pactl in handler.sh

I've been struggling for a while with getting my acpi handler script working correctly with pulseaudio and pipewire.
Looking at journalctl, it reports the error as:

    Connection failure: Connection refused
    pa_context_connect() failed: Connection refused

I'll spare the gory details of my struggles, but I got it fixed.
Currently the page https://wiki.archlinux.org/title/Acpid only has a small comment about the XDG_RUNTIME_DIR variable:

Note: These commands may not work as expected with PulseAudio. [1] For full functionality, run commands as the current user while specifying the XDG_RUNTIME_DIR environment variable, for example with:
# sudo -u user XDG_RUNTIME_DIR=/run/user/user_id pactl

I have a more fleshed out implementation of this, which was a lot more work than expected.
https://gist.github.com/christian-oudar … d13563b594

TARGET_UID=1000
my_pactl() {
    setpriv --reuid $TARGET_UID sh -c "XDG_RUNTIME_DIR=/run/user/$TARGET_UID pactl $*"
}
...
    button/mute)
        my_pactl set-sink-mute @DEFAULT_SINK@ toggle
        logger 'Mute button pressed'
        ;;
    button/volumeup)
        my_pactl set-sink-mute @DEFAULT_SINK@ 0
        my_pactl set-sink-volume @DEFAULT_SINK@ +5%
        logger 'Volume up'
        ;;
    button/volumedown)
        my_pactl set-sink-volume @DEFAULT_SINK@ -5%
        logger 'Volume down'
        ;;

Maybe we could share this in the wiki? I haven't contributed to the wiki yet, so I don't know what the process and norms are.

Last edited by christian-oudard (2023-05-31 16:53:20)

Offline

#2 2023-05-31 17:37:27

Alad
Wiki Admin/IRC Op
From: Bagelstan
Registered: 2014-05-04
Posts: 2,413
Website

Re: acpid, XDG_RUNTIME_DIR for pactl in handler.sh

That snippet hardcodes a single user, so it won't work on multi-user systems. See https://wiki.archlinux.org/title/Acpid# … nt_display instead


Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby

Offline

#3 2023-05-31 18:05:51

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: acpid, XDG_RUNTIME_DIR for pactl in handler.sh

Or don't harcode anything and allow users to handle events however they like through acpi_listen in their own session where these env vars are already set as expected.

https://wiki.archlinux.org/title/Acpid# … pid_socket

Offline

Board footer

Powered by FluxBB