[pulseaudio-discuss] Connect to non system-wide pulse server inside root privilege program (Asynchronous API)

Andrey ap.general at yandex.ru
Tue Nov 19 10:54:58 UTC 2019

12.11.2019 21:54, Andrey пишет:
> Hi all!
> Arun, thanks for the answer!
> 11.11.2019 04:40, Arun Raghavan пишет:
>> On Tue, 5 Nov 2019, at 3:50 PM, Andrey wrote:
>>> Hi all!
>>> Pf: Issue with pa_context_connect() call inside root privilege program.
>>> I have Xubuntu 19.10. On default pulseaudio server (ver 13.0) 
>>> started on
>>> user logon with "--demonize=no" parameter. I need reroute digital sound
>>> from /dev/dsp  to pulse. For this i install osspd  package (current ver
>>> 1.3.2-11). I have successfully used this package previously on Ubuntu
>>> 16.04/18.04-3 with no any tuning. Osspd daemon get source trough CUSE
>>> and required root privileges. I.e. osspd call pulse as root. I copy
>>> user's cookie file to /root/.config/pulse/cookie. But osspd can't
>>> connect to pulse server again. My distribution belongs to group 2 and i
>>> no put users to the "audio" group (but i test opposed: nothing 
>>> happens :) ).
>>> I debug osspd's slave processes (ossp-padsp) and detect what function
>>> pa_context_connect() return code 'connection refused'. I tried to run
>>> ossp-padsp as user - it connected to server successful. Then i call
>>> pa_context_connect() with name of server
>>> "unix:/run/user/1000/pulse/native" (instead NULL).... the connection is
>>> established! And as ordinary user and as root! It works for me now.
>>> BUT... I assume that somewhere something with settings of access rights
>>> to the pulse server I missed... What and where? How correctly should I
>>> connect to the non system-wide pulse server as root?
>>> Is this behavior of the connection process a normal(documented?) or 
>>> bug?
>>> Can i (is it right) use this feature to select the specific user's 
>>> pulse
>>> server to connect?
>> Not sure what the issue you have is, but there is one big hammer to 
>> sidestep this problem -- you can provide auth_anonymous=1 to 
>> module-native-protocol-unix in default.pa, and any local client can 
>> then connect.
>> -- Arun
> No... using this option does not work for me :(.
> I think that the problem is not the restriction of the rights to the 
> pulse server... I did not correctly formulate my original question. 
> It's just that the libpulse library doesn't know now what the default 
> server is. it requires an explicit server name in case the current 
> user's session does not have its own server running. That's the only 
> way I understand it.
> Now I tried to run the program as root, but previously set the 
> pulse_server environment variable (eval `pax11publish -i`).  It work 
> perfect!(i.e. with access rights all is ok)
> BUT!!!
> This program run on Ubuntu 16.04 with pulse 8.0 as root too.... 
> WITHOUT !!! PULSE_SERVER variable (it not set for root and ordinary 
> user). Where does the libpulse get the default server name???From root 
> X11 properties???
> How can I (is it possible to do this now?) configure 
> pulseaudio/libpulse 13.0 in Xubuntu 19.10 for the same 
> pa_context_connect() function behavior (in non system-wide mode)?
> Thanks :)
Well, for myself, I found as many as three solutions for the osspd 
package. They all work.

1. Using wrapper to execute "eval `pax11publish -i`" before running 
ossp-padsp (slave process of osspd) (!!! it denote that root X11 
properties contained pulse server name and root apply it!!!)

2. Adding the predefined unix socket to user's pulse server (i.e. 
"load-module module-native-protocol-unix auth-anonymous=1 
socket=/tmp/pulse-socket") and using "default-server = 
unix:/tmp/pulse-socket" in "/root/.config/pulse/client.conf".

3. Reworking source code of ossp-padsp.c to call function 
pa_context_connect() with server's name 
"unix:/run/user/<USERID>/pulse/native" (I can get USERID easily). Or 
using combination with predefined unix socket (as above) and  applying 
it as pulse server name in pa_context_connect().

Things are good...
BUT why did this function work before without these settings? Maybe 
something needs to be tweaked in the system? Where does the 
pa_context_connect() get the default server name???

And one more question. How to find out the server name after a 
successful connection (with NULL as calling name)? Function 
pa_context_get_server_info() does not contain such information... or I 
looked bad?

Thanks :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pulseaudio-discuss/attachments/20191119/db4a261b/attachment.html>

More information about the pulseaudio-discuss mailing list