Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Linux] No sound under sudo #3450

Open
itlancer opened this issue Sep 6, 2024 · 0 comments
Open

[Linux] No sound under sudo #3450

itlancer opened this issue Sep 6, 2024 · 0 comments
Labels

Comments

@itlancer
Copy link

itlancer commented Sep 6, 2024

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:
#1984
#1041 (comment)
#365
#224
#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

  1. Launch application with sudo -E:
    sudo -E ./linux_sound_root_bug
  2. Launch application with XDG_RUNTIME_DIR environmental variable:
    sudo XDG_RUNTIME_DIR=/run/user/1000 ./linux_sound_root_bug
  3. Write native extension to set up XDG_RUNTIME_DIR environmental 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant