summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephane Desneux <stephane.desneux@open.eurogiciel.org>2014-10-23 13:21:39 +0200
committerLukasz Skalski <l.skalski@samsung.com>2014-11-13 15:29:42 +0100
commit3fa68fa511bc2b68a5a9d266fdf29e51d340835a (patch)
tree07c108b533a268fbb3a9af963adc760e3da4d901
parent535b0b9844c9719ed03f08d7fd452661e3e6ef0b (diff)
downloaddbus-3fa68fa511bc2b68a5a9d266fdf29e51d340835a.tar.gz
dbus-3fa68fa511bc2b68a5a9d266fdf29e51d340835a.tar.bz2
dbus-3fa68fa511bc2b68a5a9d266fdf29e51d340835a.zip
add a small script in /etc/profile.d/dbus.sh to export DBUS_SESSION_BUS_ADDRESS
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>
-rw-r--r--packaging/dbus.sh12
-rw-r--r--packaging/dbus.spec7
2 files changed, 18 insertions, 1 deletions
diff --git a/packaging/dbus.sh b/packaging/dbus.sh
new file mode 100644
index 00000000..7d600c17
--- /dev/null
+++ b/packaging/dbus.sh
@@ -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
+
diff --git a/packaging/dbus.spec b/packaging/dbus.spec
index ac1edbb2..38b04643 100644
--- a/packaging/dbus.spec
+++ b/packaging/dbus.spec
@@ -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)