To solve this problem, I need to set the environment variable DBUS_SESSION_BUS_ADDRESS
for all shells inside tmux
every time I restart gnome without restarting tmux (this is often). How can I best solve this?
- I cannot cleanly change another processes' environment.
- I cannot send a command to every pane
- I could set the environment variable in my
PROMPT_COMMAND
. It means I need to press Enter before I can run gnome applications. It's ugly and overkill. - I could set the environment variable by executing a command before every command, but that's a bit overkill.
Is there another way to fix this in a cleaner way?
Best Answer
In this specific case, instead of letting Gnome run
dbus-launch
to create a random D-Bus address, startdbus-daemon
explicitly early in your X session startup and give it a fixed address likeunix:path=~/.dbus-$HOSTNAME-$DISPLAY
.Given the information in the bug report, you may even be able to get away with
unset DBUS_SESSION_BUS_ADDRESS
and let applications find out the bus address from the root window properties.In the general case, your assessment is correct: all you have is unreliable methods such as
ptrace
(which may crash the program, or not work due to a security framework such as Apparmor or SELinux) or injecting a shell command (which only works in panes that are currently at a shell prompt). Running a command at each shell prompt (with zsh'spreexec
or bash'sPROMPT_COMMAND
) at least doesn't risk breaking stuff.Another solution would be an
LD_PRELOAD
library that interceptsgetenv
calls. This also feels like overkill.Your best bet is to let the application do the job by creating a level of indirection: arrange for the value of the environment variable to remain valid, and for the application to interpret it in a situation-aware manner. Letting the application look up the D-Bus bus address in the root window properties is an example of this approach.