diff options
author | Stephane Desneux <stephane.desneux@open.eurogiciel.org> | 2014-10-23 13:21:39 +0200 |
---|---|---|
committer | Adrian Szyndela <adrian.s@samsung.com> | 2016-02-19 11:09:56 +0100 |
commit | 5b56e6d57d43bcb2eb762959203c292d5bb03414 (patch) | |
tree | 078b34d7d83689d6d67ab167efc4dce707dc46da /packaging | |
parent | e77f016eedb6ac43c60d1c1aa432695954197327 (diff) | |
download | dbus-5b56e6d57d43bcb2eb762959203c292d5bb03414.tar.gz dbus-5b56e6d57d43bcb2eb762959203c292d5bb03414.tar.bz2 dbus-5b56e6d57d43bcb2eb762959203c292d5bb03414.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>
Diffstat (limited to 'packaging')
-rw-r--r-- | packaging/dbus.sh | 12 | ||||
-rw-r--r-- | packaging/dbus.spec | 7 |
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) |