diff options
author | Stephane Desneux <stephane.desneux@open.eurogiciel.org> | 2014-10-23 13:21:39 +0200 |
---|---|---|
committer | Lukasz Skalski <l.skalski@samsung.com> | 2014-11-13 12:02:54 +0100 |
commit | fd23238ddc102b24eb4d7bf13f1fc705370c7e0f (patch) | |
tree | d541e8e0c2606b48650a7a02301f587c13ce380b | |
parent | 766b68f6d994048be74c2430688fc55fca3df979 (diff) | |
download | dbus-fd23238ddc102b24eb4d7bf13f1fc705370c7e0f.tar.gz dbus-fd23238ddc102b24eb4d7bf13f1fc705370c7e0f.tar.bz2 dbus-fd23238ddc102b24eb4d7bf13f1fc705370c7e0f.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.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) |