Coder Social home page Coder Social logo

Comments (6)

masmu avatar masmu commented on July 19, 2024

Currently i am doing something quite similar.

There are more environment variables than DBUS_SESSION_BUS_ADDRESS which are necessary for what you are doing.
But i am not sure which of them are necessary. I am using the complete environment of the process to steal the DBUS_SESSION_BUS_ADDRESS from.

DBUS_SESSION_BUS_REGEX = (
    r'dbus-daemon.*address=(unix:abstract=/tmp/dbus-[A-Za-z0-9]{10})')

def find_session_bus_env(pid):
    for proc in psutil.process_iter():
        if proc.uids[0] == pid and proc.name == 'dbus-daemon':
            match = re.findall(DBUS_SESSION_BUS_REGEX, str(proc.cmdline))
            if match:
                return _get_proc_env(proc.pid)
    return None


def _get_proc_env(pid):
    env = {}
    location = '/proc/{pid}/environ'.format(pid=pid)
    with open(location) as f:
        content = f.read()
    for line in content.split('\0'):
        try:
            key, value = line.split('=', 1)
            env[key] = value
        except ValueError:
            pass
    return env

env = find_session_bus_env(1000)
process = UserMultiProcess(target=test, uid=1000, gid=1000, env=env)

If you find out which variables are needed exactly, let me know! 👍

from pulseaudio-dlna.

Lahorde avatar Lahorde commented on July 19, 2024

I got it working adding XDG_RUNTIME_DIR !

function find_dlna_devices()
{
    # DBUS_SESSION_BUS_ADDRESS XDG_RUNTIME_DIR must be set in order to be able to connect user to dbus from root
    # needed by pulseaudio_dlna
    while ! pid=$(pidof pulseaudio) ; do
        sleep 2
    done
    #pulseaudio starts several times, take first daemon
    pid=$(awk -F " " '{print $1}' <<< $pid)
    user=`ps -p $pid -o user=`
    export `strings /proc/$pid/environ | grep DBUS_SESSION_BUS_ADDRESS`
    export `strings /proc/$pid/environ | grep XDG_RUNTIME_DIR`

    if [ -n "$1" ] ; then
        renderer_arg="--renderer-urls=$1"
    fi
    stdbuf -i0 -o0 -e0 su $user -c "pulseaudio-dlna $renderer_arg"
    echo  "pulseaudio dlna stopped with code $?"
}

from pulseaudio-dlna.

masmu avatar masmu commented on July 19, 2024

Thanks for your feedback!

Yesterday it worked without XDG_RUNTIME_DIR. Today it stopped working (and i did not change the code) and after adding it, it was working again.

I also had to add DISPLAY. Could you check if there are more than one pulseaudio instances running?
I had this odd situation where the starting of pulseaudio-dlna made the system start a second pulseaudio instance.

from pulseaudio-dlna.

Lahorde avatar Lahorde commented on July 19, 2024

After pulseaudio-dlna I have a single pulseaudio process :

ps -ax |grep pulseaudio
 4173 ?        S<l    0:17 /usr/bin/pulseaudio --start --log-target=syslog
 4264 ?        S      0:00 su remi -c pulseaudio-dlna 
 4265 ?        Ss     0:00 pulseaudio-dlna

But during startup, before pulseaudio-dlna is launched,

pidof pulseaudio

can return several pid, that's why I've added

#pulseaudio starts several times, take first daemon
pid=$(awk -F " " '{print $1}' <<< $pid)

from pulseaudio-dlna.

masmu avatar masmu commented on July 19, 2024

I just release 0.4.0 and since that version it is possible to run the application as root. No additional hacks necessary. Btw: I ended up in using:

  • DISPLAY
  • DBUS_SESSION_BUS_ADDRESS
  • XDG_RUNTIME_DIR

Tests and bugs welcome! 👍

from pulseaudio-dlna.

Lahorde avatar Lahorde commented on July 19, 2024

I got some new errors when starting pulseaudio-dlna from NetworkManager dispatcher :

12-13 22:29:48 pulseaudio_dlna.application                    INFO     Using version: 0.4.6
12-13 22:29:48 pulseaudio_dlna.application                    INFO     Using localhost: 192.168.1.90:8080
12-13 22:29:48 pulseaudio_dlna.application                    INFO     Encoder settings:
12-13 22:29:48 pulseaudio_dlna.application                    INFO       <AacEncoder available="True" bit-rate="192">
12-13 22:29:48 pulseaudio_dlna.application                    INFO       <FlacEncoder available="True">
12-13 22:29:48 pulseaudio_dlna.application                    INFO       <L16Encoder available="False" sample-rate="44100" channels="2">
12-13 22:29:48 pulseaudio_dlna.application                    INFO       <LameEncoder available="True" bit-rate="192">
12-13 22:29:48 pulseaudio_dlna.application                    INFO       <NullEncoder available="True">
12-13 22:29:48 pulseaudio_dlna.application                    INFO       <OggEncoder available="False" bit-rate="192">
12-13 22:29:48 pulseaudio_dlna.application                    INFO       <OpusEncoder available="False" bit-rate="192">
12-13 22:29:48 pulseaudio_dlna.application                    INFO       <WavEncoder available="False">
12-13 22:29:48 pulseaudio_dlna.application                    INFO     Codec settings:
12-13 22:29:48 pulseaudio_dlna.application                    INFO       <AacCodec enabled="True" priority="12" mime_type="audio/aac">
12-13 22:29:48 pulseaudio_dlna.application                    INFO       <L16Codec enabled="True" priority="0" mime_type="audio/L16">
12-13 22:29:48 pulseaudio_dlna.application                    INFO       <OpusCodec enabled="True" priority="3" mime_type="audio/opus">
12-13 22:29:48 pulseaudio_dlna.application                    INFO       <Mp3Codec enabled="True" priority="18" mime_type="audio/mp3">
12-13 22:29:48 pulseaudio_dlna.application                    INFO       <FlacCodec enabled="True" priority="9" mime_type="audio/flac">
12-13 22:29:48 pulseaudio_dlna.application                    INFO       <WavCodec enabled="True" priority="15" mime_type="audio/wav">
12-13 22:29:48 pulseaudio_dlna.application                    INFO       <OggCodec enabled="True" priority="6" mime_type="audio/ogg">
12-13 22:29:56 pulseaudio_dlna.listener                       INFO     Discovery complete.
12-13 22:29:56 pulseaudio_dlna.pulseaudio                     INFO     Could not get default sink. Perhaps there is no one set?
Process Process-3:
Traceback (most recent call last):
  File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python2.7/site-packages/pulseaudio_dlna/pulseaudio.py", line 433, in run
    self._connect(signals)
  File "/usr/lib/python2.7/site-packages/pulseaudio_dlna/pulseaudio.py", line 72, in _connect
    sink = PulseSinkFactory.new(self.bus, sink_path)
  File "/usr/lib/python2.7/site-packages/pulseaudio_dlna/pulseaudio.py", line 242, in new
    label = self._convert_bytes_to_unicode(description_bytes)
  File "/usr/lib/python2.7/site-packages/pulseaudio_dlna/pulseaudio.py", line 264, in _convert_bytes_to_unicode
    return name.decode(locale.getpreferredencoding())
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 16: ordinal not in range(128)

I solved it exporting LANG variable in bash function calling pulseaudio-dlna that is called by root user.

function find_dlna_devices()
{
    #some DBUS_SESSION_BUS_ADDRESS XDG_RUNTIME_DIR must be set in order to be able to connect user to dbus from root
    # needed by pulseaudio_dlna
    while ! pid=$(pidof pulseaudio) ; do
        sleep 2
    done
    #pulseaudio starts several times, take first daemon
    pid=$(awk -F " " '{print $1}' <<< $pid)
    user=`ps -p $pid -o user=`
    export `strings /proc/$pid/environ | grep DBUS_SESSION_BUS_ADDRESS`
    export `strings /proc/$pid/environ | grep XDG_RUNTIME_DIR`
    export `strings /proc/$pid/environ | grep LANG`

    if [ -n "$1" ] ; then
        renderer_arg="--renderer-urls=$1"
    fi
    stdbuf -i0 -o0 -e0 su $user -c "pulseaudio-dlna $renderer_arg"
    echo  "pulseaudio dlna stopped with code $?"
}

from pulseaudio-dlna.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.