[Linux] No sound under sudo
Problem Description
No sound can be played when AIR application run under sudo with Linux.
Sometimes multimedia applications should be run with root privileges (for example when autostart enabled). That's why it crucial.
Seems there is multiple similar issues with Video with audio playback too, with NetStream::appendBytes(), with M4A audio playback via NetStream and Sound SampleDataEvent.SAMPLE_DATA.
Tested with multiple AIR versions, even with latest AIR 51.1.1.3 with multiple different Linux x86_64 devices (VM and real), different OS versions and different applications. Same issue almost in all cases using Ubuntu 22/24. There is no such issue without sudo. There is almost no such issues using ffplay. There is no such issue with other platforms.
Related issues: https://github.com/airsdk/Adobe-Runtime-Support/issues/1984 https://github.com/airsdk/Adobe-Runtime-Support/discussions/1041#discussioncomment-1156059 https://github.com/airsdk/Adobe-Runtime-Support/issues/365 https://github.com/airsdk/Adobe-Runtime-Support/issues/224 https://github.com/airsdk/Adobe-Runtime-Support/issues/15
Steps to Reproduce
Launch application with code below with any Linux under sudo:
sudo ./linux_sound_root_bug
It should play audio via Sound.
Application example with sources and audio sample attached. linux_sound_root_bug.zip
package {
import flash.display.Sprite;
import flash.media.Sound;
import flash.net.URLRequest;
public class LinuxSoundRootBug extends Sprite {
public function LinuxSoundRootBug() {
var sound:Sound = new Sound(new URLRequest('audio.mp3'));
sound.play();
}
}
}
Actual Result: No audio played. No exceptions or errors in Scout. In terminal you will see:
Gtk-Message: 16:39:25.252: Failed to load module "canberra-gtk-module"
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
MESA: error: ZINK: failed to choose pdev
glx: failed to create drisw screen
Expected Result: Audio will be played.
Known Workarounds
- Launch application with
sudo -E:sudo -E ./linux_sound_root_bug - Launch application with
XDG_RUNTIME_DIRenvironmental variable:sudo XDG_RUNTIME_DIR=/run/user/1000 ./linux_sound_root_bug - Write native extension to set up
XDG_RUNTIME_DIRenvironmental variable just after AIR application start under sudo. For simple cases you can use:
if (!getuid()){//If run under root (sudo)
const char* sudoUID = std::getenv("SUDO_UID");
//Set up XDG_RUNTIME_DIR value
std::string xdgRuntimeDirValue = "/run/user/" + std::string(sudoUID);
setenv("XDG_RUNTIME_DIR", xdgRuntimeDirValue.c_str(), 1)
}
But for proper solution (if your application launches via systemd for example) you should properly get UID via loginctl or by another methods.