Dynamically Changing DBUS_SESSION_BUS_ADDRESS Without Re-login

251 Views Asked by At

I need to dynamically change DBUS_SESSION_BUS_ADDRESS in a project running on a Linux system. However, this change must occur when I login to the system or open a new session. This should be possible without causing issues with GDM (Gnome Display Manager). The methods I've tried so far have failed and caused problems with GDM and many other systems to. Below are the steps I tried and the results I got.

My main goal is using Dbus system via tcp for provide synchronized properties. For example, controlling the video that plays in VLC media player in both devices and I want to control both of them bidirectional.

First I added a command to change the DBUS_SESSION_BUS_ADDRESS to the .bashrc file. However, this only caused problems with GDM and I cannot login successfully.

export DBUS_SESSION_BUS_ADDRESS="tcp:host=10.0.5.165,bind=*,port=2334,family=ipv4"

Then I wrote a .sh script for exporting Dbus address after I login and adding the scrip path to .bashrc. I successfully login but Dbus address did not change. Right after this point, I learned that the dbus address is only read once when relogin is made for security reasons and cannot be changed environmentally.

Also I try creating a dbus-tcp.service

[Unit]
Description=Dbus TCP Service

After=network-online.target


[Service]
ExecStart=dbus-daemon --config-file /usr/share/dbus-1/dbus-tcp.conf
ExecStop=/opt/yaltes/redis/libexec/redis-shutdown
Type=simple

RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target

With this cutom dbus-tcp.conf file in /usr/share/dbus-1


<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
  <!-- Our well-known bus type, don't change this -->
  <type>session</type>

  <keep_umask/>

  <listen>tcp:host=localhost,bind=*,port=2334,family=ipv4</listen>

<listen>unix:tmpdir=/tmp</listen>

<auth>ANONYMOUS</auth>

<allow_anonymous/>

<apparmor mode="disabled"/>

  
  

  <standard_session_servicedirs />

  <policy context="default">
   ...
    <allow own="*"/>
  </policy>

    #<include ignore_missing="yes">/etc/dbus-1/session.conf</include>

  <includedir>session.d</includedir>

  <includedir>/etc/dbus-1/session.d</includedir>

  <!-- This is included last so local configuration can override what's 
       in this standard file -->
  <include ignore_missing="yes">/etc/dbus-1/session-local.conf</include>

  <include if_selinux_enabled="yes" selinux_root_relative="yes">contexts/dbus_contexts</include>


  <!-- the memory limits are 1G instead of say 4G because they can't exceed 32-bit signed int max -->
  ...

</busconfig>

When I save it and reboot, the login screen didn't even open.

Lastly I wrote export DBUS_SESSION_BUS_ADDRESS="tcp:host=10.0.5.165,bind=*,port=2334,family=ipv4" in to /etc/environment then reboot. After that i successfully change DBUS_SESSION_BUS_ADDRESS but only for root. So when i was root and typed

     echo $DBUS_SESSION_BUS_ADDRESS

it gave me the correct address.

0

There are 0 best solutions below