add a small script in /etc/profile.d/dbus.sh to export DBUS_SESSION_BUS_ADDRESS
authorStephane Desneux <stephane.desneux@open.eurogiciel.org>
Thu, 23 Oct 2014 11:21:39 +0000 (13:21 +0200)
committerAdrian Szyndela <adrian.s@samsung.com>
Fri, 19 Feb 2016 10:09:56 +0000 (11:09 +0100)
If the dbus session address is not defined, this small script will try to
pick the address from the environment of the systemd --user process for the current
user.

Typically, this allows to log on a target through ssh, then run su - <user> and
have the same environment as the shells inside the user session.

Change-Id: Id6133077bf9943c4203f7d993b8942dc1455bef5
Signed-off-by: Stephane Desneux <stephane.desneux@open.eurogiciel.org>
packaging/dbus.sh [new file with mode: 0644]
packaging/dbus.spec

diff --git a/packaging/dbus.sh b/packaging/dbus.sh
new file mode 100644 (file)
index 0000000..7d600c1
--- /dev/null
@@ -0,0 +1,12 @@
+# if DBUS session address is not set, try to set it, by getting the DBUS_SESSIONS_BUS_ADDRESS variable
+# from the first systemd process running for the current user.
+# This typically allows a 'su - <user>' command to have the right DBUS address.
+
+if [[ -z "$DBUS_SESSION_BUS_ADDRESS" ]]; then
+   systemd_pid=$(pgrep -U $UID systemd | head -1)
+   if [[ -n "$systemd_pid" ]]; then
+      val=$(sed  '/\<DBUS_SESSION_BUS_ADDRESS=/!d ; s/.*\<DBUS_SESSION_BUS_ADDRESS=\([^[:cntrl:]]*\).*/\1/' /proc/${systemd_pid}/environ)
+      [[ -n "$val" ]] && export DBUS_SESSION_BUS_ADDRESS=$val
+   fi
+fi
+
index ac1edbb..38b0464 100644 (file)
@@ -28,6 +28,7 @@ Source3:        dbus_at_console.ck
 Source4:        baselibs.conf
 Source5:        dbus-user.service
 Source6:        dbus-user.socket
+Source7:        dbus.sh
 BuildRequires:  libcap-ng-devel
 BuildRequires:  pkgconfig(libsmack)
 # COMMON1-END
@@ -121,6 +122,9 @@ rm -rf %{buildroot}/%{_libdir}/pkgconfig/dbus-1.pc
 rm -rf %{buildroot}/%{_mandir}/man1/dbus-launch.1*
 rm -rf %{buildroot}/%{_bindir}/dbus-launch
 
+# install script for login shells (/etc/profile.d)
+install -d %{buildroot}%{_sysconfdir}/profile.d
+install -m0644 %{SOURCE7} %{buildroot}%{_sysconfdir}/profile.d/dbus.sh
 
 %pre
 # Add the "dbus" user and group
@@ -135,7 +139,7 @@ rm -rf %{buildroot}/%{_bindir}/dbus-launch
 %dir %{_localstatedir}/lib/dbus
 %dir /lib/dbus-1
 %dir /lib/dbus-1/system-services
-%license  COPYING 
+%license  COPYING
 %config(noreplace) %{_sysconfdir}/dbus-1/session.conf
 %config(noreplace) %{_sysconfdir}/dbus-1/system.conf
 %{_sysconfdir}/ConsoleKit
@@ -167,6 +171,7 @@ rm -rf %{buildroot}/%{_bindir}/dbus-launch
 %dir %{_datadir}/dbus-1/interfaces
 %dir %{_datadir}/dbus-1/services
 %dir %{_datadir}/dbus-1/system-services
+%{_sysconfdir}/profile.d/dbus.sh
 
 %files devel-doc
 %defattr(-,root,root)