Home / Alt manpages / dbus-update-activation-environment(1)

  • dbus-update-activation-environment(1)
  • User command
  • linux

Refresh D-Bus Activation Variables Without Restarting Your Session

You will update the environment inherited by newly activated D-Bus services, and optionally by services started through systemd --user. This is useful after a graphical session starts with a missing DISPLAY, XAUTHORITY or application setting. Allow about ten minutes. You need an active D-Bus session bus and the dbus-bin package. The installed command checked for this guide is D-Bus 1.14.10 from Ubuntu package version 1.14.10-4ubuntu4.1.

This command changes the activation environment held by the bus. It does not change the environment of programs that are already running, and it does not restart services. You normally do not need sudo; use the command as the desktop user whose session bus should be updated.

1. Confirm the command and the session bus

Check the binary and its installed package first. These are read-only checks:

$ command -v dbus-update-activation-environment
/usr/bin/dbus-update-activation-environment
$ dpkg-query -W -f='${Package} ${Version}\n' dbus-bin
dbus-bin 1.14.10-4ubuntu4.1
$ dbus-update-activation-environment --help
dbus-update-activation-environment: update environment variables that will be set for D-Bus
    session services

The command finds the session bus through DBUS_SESSION_BUS_ADDRESS, XDG_RUNTIME_DIR and/or DISPLAY. If none points to a reachable bus, the command cannot update anything.

Checkpoint

If the package check succeeds but later commands return an error about connecting to the session bus, fix the session context first. Do not run the command with sudo to work around that error: root would normally target a different user environment and bus.

2. Pass selected variables from the current shell

Give the command variable names without values when the desired values are already exported in the current environment. This is the safest default because it limits the update to variables you name:

$ dbus-update-activation-environment --verbose DISPLAY XAUTHORITY
dbus-update-activation-environment: setting DISPLAY=:0
dbus-update-activation-environment: setting XAUTHORITY=/run/user/1000/gdm/Xauthority
$ printf 'exit status: %s\n' "$?"
exit status: 0

The exact values and path will differ on your machine. With --verbose, status messages go to standard error. A named variable that is not present in the command's environment is silently ignored, so check it before relying on the result:

if [ -n "${DISPLAY-}" ]; then
    dbus-update-activation-environment --verbose DISPLAY
else
    printf '%s\n' 'DISPLAY is not set in this shell' >&2
fi

Remember that updating the bus does not export a variable into your current shell and does not rewrite another process's environment. It affects services activated after the update.

3. Set a value explicitly

Use VAR=VAL when the value should be supplied directly rather than copied from the shell. The value must be UTF-8:

$ dbus-update-activation-environment --verbose MY_APP_MODE=desktop
dbus-update-activation-environment: setting MY_APP_MODE=desktop
$ printf 'exit status: %s\n' "$?"
exit status: 0

Use a value that is appropriate for the service you are starting. Do not put secrets, access tokens or passwords into a shared activation environment unless you have checked which user services can read them. The setting persists in the bus activation state until the session bus goes away, and the D-Bus side has no command for unsetting a variable after it has been set.

Recovery

There is no D-Bus unset operation in this tool. If you set a harmless test variable, stop using it and start a new session bus, normally by logging out and in. For a sensitive value, rotate the credential as well as ending the affected session.

4. Update systemd user services as well

Add --systemd when the same variables must reach both traditional D-Bus activation and systemd --user activation:

$ dbus-update-activation-environment --systemd --verbose DISPLAY XAUTHORITY
dbus-update-activation-environment: setting DISPLAY=:0
dbus-update-activation-environment: setting XAUTHORITY=/run/user/1000/gdm/Xauthority
$ printf 'exit status: %s\n' "$?"
exit status: 0

If a user instance of systemd is available on D-Bus, it receives the update as well. Without --systemd, the command updates the D-Bus daemon activation environment only. That distinction is a common source of confusion: a D-Bus service may see the new value while a user service started by systemd still sees the old one.

DBUS_SESSION_BUS_ADDRESS is a special case. The manual says it is not useful to add it to the D-Bus daemon activation environment because the daemon overrides its value when starting a service, but it may still be useful for systemd. If you need it for user services, use the systemd form explicitly:

$ dbus-update-activation-environment --systemd DBUS_SESSION_BUS_ADDRESS DISPLAY XAUTHORITY

5. Use --all only after reviewing the boundary

--all copies every environment variable present in the command's environment. It is intended for session startup scripts and compatibility with older X11 setups, not as a casual replacement for naming the few variables a service needs.

If you need this compatibility behaviour, remove the session metadata that should not be propagated in a subshell, then run the update:

(
    unset XDG_SEAT
    unset XDG_SESSION_ID
    unset XDG_VTNR
    dbus-update-activation-environment --systemd --all --verbose
)

The parentheses keep the unset operations inside the child shell. Your login shell keeps its original variables. Review the environment before using this form, especially if the shell contains credentials or machine-specific paths. The command ignores non-UTF-8 names and values with a warning.

6. Diagnose failure without guessing

Capture the status immediately after the command:

dbus-update-activation-environment --verbose DISPLAY
status=$?
case "$status" in
    0)  printf '%s\n' 'activation environment updated' ;;
    64) printf '%s\n' 'invalid command-line option or argument' >&2 ;;
    69) printf '%s\n' 'the bus rejected the environment update' >&2 ;;
    71) printf '%s\n' 'could not connect to the session bus' >&2 ;;
    *)  printf 'unexpected exit status: %s\n' "$status" >&2 ;;
esac
exit "$status"

Status 64 is EX_USAGE, 71 is EX_OSERR, and 69 is EX_UNAVAILABLE in the installed manual. A successful update still does not restart an already running service. Stop and start the affected user service through its normal manager, or open a new session, only after checking that doing so is safe.

Done means

  • The command and package version were checked without elevated privileges.
  • The selected variables exist in the current shell, or explicit UTF-8 values were supplied.
  • --systemd was used when systemd user services also need the update.
  • --all was reserved for a reviewed session-startup environment.
  • The command returned status 0, and you understand that existing processes keep their old environment.
  • You did not put credentials into a shared activation environment without a clear cleanup plan.