DBUS-LAUNCH(1)
π DBUS-LAUNCH(1) π
okay bestie, gather round, because we're talking about dbus-launch β a lil utility from the User Commands corner of your manual pages, section 1, that starts a message bus from a shell script. she's giving little-helper-that-could energy and honestly? obsessed. π¦
β¨ NAME β¨
dbus-launch β utility to start a message bus from a shell script π
β¨ SYNOPSIS β¨
dbus-launch [--version] [--help] [--sh-syntax] [--csh-syntax]
[--auto-syntax] [--binary-syntax] [--close-stderr]
[--exit-with-session] [--exit-with-x11]
[--autolaunch=MACHINEID] [--config-file=FILENAME] [PROGRAM]
[ARGS...]
β¨ DESCRIPTION β¨
so the way that dbus-launch works is: it starts up a session bus instance of dbus-daemon from inside a shell script. she's normally called from a user's login scripts, like, that's her whole job. and here's the thing that makes her special β unlike the daemon itself, dbus-launch exits. so you can use backticks or the $() construct to read info back out of her. iconic behaviour, honestly. β¨
with no arguments at all? dbus-launch will launch a session bus instance and print the address and PID of that instance straight to standard output. slay.
you can also specify a program to be run, and in that case dbus-launch will launch a session bus instance, set the appropriate environment variables so your specified program can find the bus, and then execute that program with the arguments you gave it. examples are down below, don't worry π«Ά
heads up bestie: if you launch a program, dbus-launch will not print the info about the new bus to standard output. no bus gossip for you in that case.
when dbus-launch does print bus info to standard output, by default it comes out in a simple key-value pairs format. but you can request several alternate syntaxes with the --sh-syntax, --csh-syntax, --binary-syntax, or --auto-syntax options. several of these make dbus-launch emit shell code to set up the environment β she's literally writing code for you, main character energy.
with the --auto-syntax option, dbus-launch looks at the value of the SHELL environment variable to figure out which shell syntax to use. if SHELL ends in "csh", then csh-compatible code gets emitted; otherwise it's Bourne shell code. instead of passing --auto-syntax, you may explicitly specify a particular one by using --sh-syntax for Bourne syntax, or --csh-syntax for csh syntax. and fr fr, in scripts it's more robust to avoid --auto-syntax β you hopefully know which shell your script is written in π
more info about D-Bus lives at https://www.freedesktop.org/wiki/Software/dbus/ and you should also peep the man page for dbus-daemon. iykyk.
πΈ EXAMPLES πΈ
distributions that run dbus-launch as part of a standard X session should run dbus-launch --exit-with-session after the X server has started and become available, as a wrapper around the "main" X client (typically a session manager or window manager). like these:
dbus-launch --exit-with-session gnome-session
dbus-launch --exit-with-session openbox
dbus-launch --exit-with-session ~/.xsession
if your distribution does not do this, you can achieve similar results by running your session or window manager in the same way in a script run by your X session, such as ~/.xsession, ~/.xinitrc or ~/.Xclients. we love a DIY moment π
to start a D-Bus session within a text-mode session, do not use dbus-launch. instead, see dbus-run-session(1). periodt.
## test for an existing bus daemon, just to be safe
if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
## if not found, launch a new one
eval `dbus-launch --sh-syntax`
echo "D-Bus per-session daemon address is: $DBUS_SESSION_BUS_ADDRESS"
fi
note that in this case, dbus-launch will exit, and dbus-daemon will not be terminated automatically on logout. π that daemon is staying, she lives here now.
π AUTOMATIC LAUNCHING π
if DBUS_SESSION_BUS_ADDRESS is not set for a process that tries to use D-Bus, then by default that process will attempt to invoke dbus-launch with the --autolaunch option, to either start up a new session bus or find the existing bus address on the X display or in a file in ~/.dbus/session-bus/.
whenever an autolaunch happens, the application that had to start a new bus ends up in its own little world. like, she can effectively end up starting a whole new session if she tries to use a lot of bus services. this can be suboptimal or even totally broken, depending on the app and what it's trying to do. π
there are two common reasons for autolaunch:
- ssh to a remote machine. the ideal fix for that would be forwarding of
DBUS_SESSION_BUS_ADDRESSin the same way thatDISPLAYis forwarded. in the meantime, you can edit thesession.confconfig file to have your session bus listen on TCP, and manually setDBUS_SESSION_BUS_ADDRESS, if you like. - an
suto another user, and display of X applications running as the second user on the display belonging to the first user. perhaps the ideal fix in this case would be to allow the second user to connect to the session bus of the first user, just as they can connect to the first user's display. however, a mechanism for that has not been coded. π
you can always avoid autolaunch by manually setting DBUS_SESSION_BUS_ADDRESS. autolaunch happens because the default address if none is set is "autolaunch:" β so if any other address is set, there will be no autolaunch. you can however include autolaunch in an explicit session bus address as a fallback, for example DBUS_SESSION_BUS_ADDRESS="something:,autolaunch:" β in that case, if the first address doesn't work, processes will autolaunch. (the bus address variable contains a comma-separated list of addresses to try, bestie.)
the --autolaunch option is considered an internal implementation detail of libdbus, and in fact there are plans to change it. there's no real reason to use it outside of the libdbus implementation anyhow. so like, hands off unless you're libdbus. π₯
π OPTIONS π
the following options are supported:
--auto-syntaxβ choose--csh-syntaxor--sh-syntaxbased on theSHELLenvironment variable.--binary-syntaxβ write to stdout a nul-terminated bus address, then the bus PID as a binary integer of sizesizeof(pid_t), then the bus X window ID as a binary integer of sizesizeof(long). integers are in the machine's byte order, not network byte order or any other canonical byte order.--close-stderrβ close the standard error output stream before starting the D-Bus daemon. this is useful if you want to capturedbus-launcherror messages but you don't wantdbus-daemonto keep the stream open to your application.--config-file=FILENAMEβ pass--config-file=FILENAMEto the bus daemon, instead of passing it the--sessionargument. see the man page fordbus-daemon.--csh-syntaxβ emit csh compatible code to set up environment variables.--exit-with-x11β if this option is provided, a persistent "babysitter" process will be created, and will connect to the X server. if it cannot do so, launching fails. if the "babysitter" process loses its X connection, it kills the message bus daemon, disconnecting all of its clients (which should exit in response). this avoids having leftover daemon processes from a user X session, after the X session has ended. π§--exit-with-sessionβ if this option is provided, a persistent "babysitter" process will be created, as if for--exit-with-x11. if it cannot connect to the X server, it will monitor the terminal from whichdbus-launchwas started instead, and if it gets aHUPon stdin, the message bus daemon will be killed. this option is not recommended, since it will consume input from the terminal where it was started; it is mainly provided for backwards compatibility.--autolaunch=MACHINEIDβ this option implies thatdbus-launchshould scan for a previously-started session and reuse the values found there. if no session is found, it will start a new session. the--exit-with-sessionoption is implied if--autolaunchis given. this option is for the exclusive use of libdbus, you do not want to use it manually. it may change in the future.--sh-syntaxβ emit Bourne-shell compatible code to set up environment variables.--versionβ print the version ofdbus-launch.--helpβ print the help info ofdbus-launch.
β NOTES β
if you run dbus-launch myapp (with any other options), dbus-daemon will not exit when myapp terminates. the reason is that myapp is assumed to be part of a larger session, rather than a session in its own right. so she's a team player, not a solo act π
π AUTHOR π
see https://dbus.freedesktop.org/doc/AUTHORS
π¦ BUGS π¦
please send bug reports to the D-Bus mailing list or bug tracker, see https://www.freedesktop.org/wiki/Software/dbus/
and that's the whole page bestie π this was D-Bus 1.16.2, manual section DBUS-LAUNCH(1) β go forth, launch your bus, and stay hydrated β¨π
π¦ where this page comes from
- debian trixie: dbus-x11 1.16.2-2 Β· GPL-2.0-or-later OR AFL-2.1, AND MIT AND Tcl-BSDish
- ubuntu questing: dbus-x11 1.16.2-2ubuntu2
- ubuntu resolute: dbus-x11 1.16.2-2ubuntu4 Β· GPL-2.0-or-later OR AFL-2.1, AND MIT AND Tcl-BSDish
- ubuntu stonking: dbus-x11 1.16.2-5ubuntu2 Β· GPL-2.0-or-later OR AFL-2.1, AND MIT AND Tcl-BSDish
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms