10

Not that I need to aplay as root but it came across me and I wondered why it shouldn't work.

# aplay /home/bibek/apert.wav
XDG_RUNTIME_DIR (/run/user/1000) is not owned by us (uid 0), but by
uid 1000! (This could e g happen if you try to connect to a non-root
PulseAudio as a root user, over the native protocol. Don't do that.) 
ALSA lib pcm_dmix.c:1024:(snd_pcm_dmix_open) unable to open slave
aplay: main:722: audio open error: No such file or directory

I can see that it is giving me reasonable amount of details but I still don't understand.

3 Answers 3

6

Your root shell is coming from su right? The environment variable $XDG_RUNTIME_DIR is being inherited from your user shell. You can either run export XDG_RUNTIME_DIR="" before aplay to clear it, or you can use sudo -i instead of su to get a clean environment.

1
  • Actually, I also tried doing a fresh login as root from tty2 and run the comand only to get the same result. this time it gives me only the last two lines of error, however! Could it be possible that alsa is not properly configured for root or something. I feel like that No such file or directory shouldn't be there otherwise.
    – Bibek_G
    Commented Sep 25, 2015 at 6:13
3

As the error message shows, the connection is refused if it is not the original user that requests it. As root, you can use sudo to issue the command as that user, but the XDG_RUNTIME_DIR also needs to be the one of that user,

sudo -u '#1000' XDG_RUNTIME_DIR=/run/user/1000 aplay ...

Check the original user ID with id -u, it might not be 1000.

0

It is not that there is a technical impossibility, it is a built-in security measure available often available in applications that communicate with each other and should not be run as root.

Without such a measure you would have to make sure the protocol cannot be abused (or hijacked) to gain non-intended control over the "other side", due to some (as yet unfound) bug. As the effect of this could be extra severe if the program on the other side had root privileges, it is just easier to disallow that from the start.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .