I'm on Ubuntu 16.04, and I've just developed this piece of software which automates PulseAudio hotplug events.
I'm currently using the following udev rule:
/etc/udev/rules.d/90-autopulse.rules:
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0d8c", ATTRS{idProduct}=="1066", ENV{SYSTEMD_WANTS}="[email protected]" I'm using this as my systemd unit:
/etc/systemd/system/[email protected]:
[Unit] Description=PulseAudio Hotplug Service [Service] Type=oneshot Environment=DISPLAY=:0 User=%i ExecStart=/usr/local/bin/autopulse switch StandardOutput=journal I unfortunately need to manually set DISPLAY=:0, though there's no guarantee that I'll be that given X session.
Is there a way to configure udev or systemd to pull the DISPLAY variable for a given user and use that in the environment? Or am I stuck hardcoding it?
I suppose I could do an ExecStartPre or something to discover it, or perhaps adjust my script. What are my options purely in udev and systemd?
SYSTEMD_USER_WANTS, but documentation is sorely lacking. Also, it should be possible within my program to use/usr/bin/wto find the X display for a given user, but it doesn't count as being part of systemd.:0as opposed to:1, etc. Most distros maintain different X sessions per logged in user.DISPLAY, start it when the X session is started (from the display manager,.xsession, or whatever), and not from systemd. Systemd (or at least the init system that it's supposed to replace) is for system-wide services.