You are not logged in.

#1 2017-06-27 22:41:00

gnox
Member
Registered: 2013-05-18
Posts: 91

sudo and audio problem

Hi, while I was configuring a network namespace for a vpn when I try to execute a program that needs audio for example qutebrowser/firefox with youtube, I get no audio at all. I have pulseaudio installed.

If I run

$sudo ip exec netns exec vpnns firefox

Firefox runs as root no audio .

If I run

$sudo ip exec netns exec vpnns sudo -u $USER firefox

firefox runs as $USER but also without audio .

So trying only :

$sudo -u $USER firefox

I get the same problem and this discards anything that netns could affect.

I started "pulseaudio -D --system" as root, and the same problem. When I run qutebrowser I see this in the program outut :

ALCplaybackAlsa_open: Could not open playback device 'default': No such file or directory

I can see in pstree that pulseaudio pid of root have the same subprocesses? as pulseaudio of $USER

├─pulseaudio─┬─{alsa-sink-ALC89}
              ├─{alsa-sink-HDMI }
              └─{alsa-source-ALC}

Any ideas how can I get audio working using sudo?

Last edited by gnox (2017-06-27 22:42:19)

Offline

#2 2017-06-28 09:39:44

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,435

Re: sudo and audio problem

Why do you want to do this? You try to do many highly discouraged things by even attempting to run a browser as root, let alone letting a root owned process connect to the pulseaudio of your user (or even then trying to fumble your way around it by using the discouraged system mode pulseaudio)

For why sudo doesn't work is pretty easily explained, using sudo discards many of the "non-essential" environment variables by default. So both your dbus and the pulseaudio runtime paths which would usually be used to discover a pulse session are not present anymore.

Offline

#3 2017-06-28 18:56:52

gnox
Member
Registered: 2013-05-18
Posts: 91

Re: sudo and audio problem

V1del wrote:

Why do you want to do this? You try to do many highly discouraged things by even attempting to run a browser as root, let alone letting a root owned process connect to the pulseaudio of your user (or even then trying to fumble your way around it by using the discouraged system mode pulseaudio)

For why sudo doesn't work is pretty easily explained, using sudo discards many of the "non-essential" environment variables by default. So both your dbus and the pulseaudio runtime paths which would usually be used to discover a pulse session are not present anymore.

Well I need to have a vpn connection isolated for diferent processes and instead of using a container or vm I tried  learning network namespace,  the original command was only :

sudo ip exec netns exec vpnns sudo -u $user firefox

All the rest was me trying to figure out why the audio didnt work with pulseaudio.  I will try now using only alsa.

Thx

Offline

#4 2017-06-29 01:00:48

HiImTye
Member
From: Halifax, NS, Canada
Registered: 2012-05-09
Posts: 1,072

Re: sudo and audio problem

you should never run userspace programs as root. if you're running it as root to fix some unknown problem that you haven't explained, you should address that problem directly.
that said, if you really want to run firefox as root, ignoring all of the warnings of common sense, use gksudo/gksu instead.

Offline

#5 2017-06-29 02:26:15

tom.ty89
Member
Registered: 2012-11-15
Posts: 897

Re: sudo and audio problem

What you need is the PULSE_SERVER and PULSE_COOKIE env var. (That said, it works, but it doesn't necessarily mean that it's appropriate.) sudo is fine (as in, v.s. gksudo/gksu):

[tom@localhost ~]$ sudo PULSE_SERVER=/run/user/1000/pulse/native PULSE_COOKIE=/home/tom/.config/pulse/cookie pactl info
Server String: /run/user/1000/pulse/native
Library Protocol Version: 32
Server Protocol Version: 32
Is Local: yes
Client Index: 6
Tile Size: 65472
User Name: tom
Host Name: localhost
Server Name: pulseaudio
Server Version: 10.0
Default Sample Specification: s16le 2ch 44100Hz
Default Channel Map: front-left,front-right
Default Sink: jack_out
Default Source: jack_out.monitor
Cookie: 56bd:5d4a

Note that the pulse server is started as a user instance by the user tom(1000).

ip-netns(8) wrote:

       ip [-all] netns exec [ NAME ] cmd ... - Run cmd in the named network namespace

              This command allows applications that are network namespace unaware to be run in something other than the default network namespace...

There might be better ways to make use of netns instead of using its exec with sudo. Running anything that doesn't need to be run as root as root just because you want it to be using another network namespace doesn't sounds right anyway, no matter if it is a GUI program. But I don't know how new this netns thing is so perhaps for most programs exec is the only option.

Last edited by tom.ty89 (2017-06-29 04:37:33)

Offline

Board footer

Powered by FluxBB