0

I'm using GDbus and make a dbus communication. It using sesstion bus.

Problem is dbus-launch.

I was running dbus in Yocto with c++11. And, I have to export $(dbus-launch).

But, I want to export $(dbus-launch) or same thing in booting time. Because dbus start by systemd.

Jaekwon Kim
  • 29
  • 2
  • 6

2 Answers2

1

One solution is to have a recipe that adds environment variable:

SRC_URI +=  "file://dbus-env.sh"

do_install_append() {
    install -d -m 0755 ${D}${sysconfdir}/profile.d
    install -m 0755 ${WORKDIR}/dbus-env.sh ${D}${sysconfdir}/profile.d/
}

FILES_${PN} += "${sysconfdir}/profile.d/dbus-env.sh"

With dbus-env.sh

#!/bin/sh

export $(dbus-launch)
Nayfe
  • 2,130
  • 13
  • 18
  • I was trying to install script in /etc/profile.d and reboot. But looks like export was not working. – Jaekwon Kim Dec 07 '17 at 13:00
  • is your script has execution rights ? `chmod ugo+x /etc/profile.d/yourscript.sh` Which other app needs the exported variables? – Nayfe Dec 07 '17 at 13:02
  • I missed checking mode. I'll try again. – Jaekwon Kim Dec 07 '17 at 13:05
  • This is can make environment. But profile.d is working after login. I need working before login. – Jaekwon Kim Dec 07 '17 at 17:14
  • 1
    if you use systemd as init, you can add `EnvironmentFile=/tmp/dbus-session` and `ExecStartPre=/usr/bin/dbus-session-env.sh` with `dbus-session-env.sh` doing `dbus-launch > /tmp/dbus-session` Then you can pass `DBUS_SESSION_BUS_ADDRESS` and `DBUS_SESSION_BUS_PID` in `ExecStart`. – Nayfe Dec 08 '17 at 08:37
0

Use this command in /etc/profile or $HOME/.profile or $HOME/.bashrc :

eval \`dbus-launch --auto-syntax`

this will export "DBUS_SESSION_BUS_ADDRESS" and "DBUS_SESSION_BUS_PID" with proper values

you can also use this script:

[[ -n $SSH_CLIENT ]] && export $(cat /proc/$(command pgrep -u "$USER"  -f -- "dbus-daemon --session" )/environ| tr '\0' '\n' | command grep "DBUS_SESSION_BUS_ADDRESS=")
wscourge
  • 10,657
  • 14
  • 59
  • 80