1DBUS-LAUNCH(1) User Commands DBUS-LAUNCH(1)
2
3
4
6 dbus-launch - Utility to start a message bus from a shell script
7
9 dbus-launch [--version] [--help] [--sh-syntax] [--csh-syntax]
10 [--auto-syntax] [--binary-syntax] [--close-stderr]
11 [--exit-with-session] [--exit-with-x11]
12 [--autolaunch=MACHINEID] [--config-file=FILENAME] [PROGRAM]
13 [ARGS...]
14
15
17 The dbus-launch command is used to start a session bus instance of
18 dbus-daemon from a shell script. It would normally be called from a
19 user's login scripts. Unlike the daemon itself, dbus-launch exits, so
20 backticks or the $() construct can be used to read information from
21 dbus-launch.
22
23 With no arguments, dbus-launch will launch a session bus instance and
24 print the address and PID of that instance to standard output.
25
26 You may specify a program to be run; in this case, dbus-launch will
27 launch a session bus instance, set the appropriate environment
28 variables so the specified program can find the bus, and then execute
29 the specified program, with the specified arguments. See below for
30 examples.
31
32 If you launch a program, dbus-launch will not print the information
33 about the new bus to standard output.
34
35 When dbus-launch prints bus information to standard output, by default
36 it is in a simple key-value pairs format. However, you may request
37 several alternate syntaxes using the --sh-syntax, --csh-syntax,
38 --binary-syntax, or --auto-syntax options. Several of these cause
39 dbus-launch to emit shell code to set up the environment.
40
41 With the --auto-syntax option, dbus-launch looks at the value of the
42 SHELL environment variable to determine which shell syntax should be
43 used. If SHELL ends in "csh", then csh-compatible code is emitted;
44 otherwise Bourne shell code is emitted. Instead of passing
45 --auto-syntax, you may explicitly specify a particular one by using
46 --sh-syntax for Bourne syntax, or --csh-syntax for csh syntax. In
47 scripts, it's more robust to avoid --auto-syntax and you hopefully know
48 which shell your script is written in.
49
50 See http://www.freedesktop.org/software/dbus/ for more information
51 about D-Bus. See also the man page for dbus-daemon.
52
54 Distributions running dbus-launch as part of a standard X session
55 should run dbus-launch --exit-with-session after the X server has
56 started and become available, as a wrapper around the "main" X client
57 (typically a session manager or window manager), as in these examples:
58
59 dbus-launch --exit-with-session gnome-session
60
61 dbus-launch --exit-with-session openbox
62
63 dbus-launch --exit-with-session ~/.xsession
64
65 If your distribution does not do this, you can achieve similar results
66 by running your session or window manager in the same way in a script
67 run by your X session, such as ~/.xsession, ~/.xinitrc or ~/.Xclients.
68
69 To start a D-Bus session within a text-mode session, do not use
70 dbus-launch. Instead, see dbus-run-session(1).
71
72 ## test for an existing bus daemon, just to be safe
73 if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
74 ## if not found, launch a new one
75 eval `dbus-launch --sh-syntax`
76 echo "D-Bus per-session daemon address is: $DBUS_SESSION_BUS_ADDRESS"
77 fi
78
79 Note that in this case, dbus-launch will exit, and dbus-daemon will not
80 be terminated automatically on logout.
81
83 If DBUS_SESSION_BUS_ADDRESS is not set for a process that tries to use
84 D-Bus, by default the process will attempt to invoke dbus-launch with
85 the --autolaunch option to start up a new session bus or find the
86 existing bus address on the X display or in a file in
87 ~/.dbus/session-bus/
88
89 Whenever an autolaunch occurs, the application that had to start a new
90 bus will be in its own little world; it can effectively end up starting
91 a whole new session if it tries to use a lot of bus services. This can
92 be suboptimal or even totally broken, depending on the app and what it
93 tries to do.
94
95 There are two common reasons for autolaunch. One is ssh to a remote
96 machine. The ideal fix for that would be forwarding of
97 DBUS_SESSION_BUS_ADDRESS in the same way that DISPLAY is forwarded. In
98 the meantime, you can edit the session.conf config file to have your
99 session bus listen on TCP, and manually set DBUS_SESSION_BUS_ADDRESS,
100 if you like.
101
102 The second common reason for autolaunch is an su to another user, and
103 display of X applications running as the second user on the display
104 belonging to the first user. Perhaps the ideal fix in this case would
105 be to allow the second user to connect to the session bus of the first
106 user, just as they can connect to the first user's display. However, a
107 mechanism for that has not been coded.
108
109 You can always avoid autolaunch by manually setting
110 DBUS_SESSION_BUS_ADDRESS. Autolaunch happens because the default
111 address if none is set is "autolaunch:", so if any other address is set
112 there will be no autolaunch. You can however include autolaunch in an
113 explicit session bus address as a fallback, for example
114 DBUS_SESSION_BUS_ADDRESS="something:,autolaunch:" - in that case if the
115 first address doesn't work, processes will autolaunch. (The bus address
116 variable contains a comma-separated list of addresses to try.)
117
118 The --autolaunch option is considered an internal implementation detail
119 of libdbus, and in fact there are plans to change it. There's no real
120 reason to use it outside of the libdbus implementation anyhow.
121
123 The following options are supported:
124
125 --auto-syntax
126 Choose --csh-syntax or --sh-syntax based on the SHELL environment
127 variable.
128
129 --binary-syntax
130 Write to stdout a nul-terminated bus address, then the bus PID as a
131 binary integer of size sizeof(pid_t), then the bus X window ID as a
132 binary integer of size sizeof(long). Integers are in the machine's
133 byte order, not network byte order or any other canonical byte
134 order.
135
136 --close-stderr
137 Close the standard error output stream before starting the D-Bus
138 daemon. This is useful if you want to capture dbus-launch error
139 messages but you don't want dbus-daemon to keep the stream open to
140 your application.
141
142 --config-file=FILENAME
143 Pass --config-file=FILENAME to the bus daemon, instead of passing
144 it the --session argument. See the man page for dbus-daemon
145
146 --csh-syntax
147 Emit csh compatible code to set up environment variables.
148
149 --exit-with-x11
150 If this option is provided, a persistent "babysitter" process will
151 be created, and will connect to the X server. If it cannot do so,
152 launching fails. If the "babysitter" process loses its X
153 connection, it kills the message bus daemon, disconnecting all of
154 its clients (which should exit in response). This avoids having
155 leftover daemon processes from a user X session, after the X
156 session has ended.
157
158 --exit-with-session
159 If this option is provided, a persistent "babysitter" process will
160 be created, as if for --exit-with-x11. If it cannot connect to the
161 X server, it will monitor the terminal from which dbus-launch was
162 started instead, and if it gets a HUP on stdin, the message bus
163 daemon will be killed. This option is not recommended, since it
164 will consume input from the terminal where it was started; it is
165 mainly provided for backwards compatibility.
166
167 --autolaunch=MACHINEID
168 This option implies that dbus-launch should scan for a
169 previously-started session and reuse the values found there. If no
170 session is found, it will start a new session. The
171 --exit-with-session option is implied if --autolaunch is given.
172 This option is for the exclusive use of libdbus, you do not want to
173 use it manually. It may change in the future.
174
175 --sh-syntax
176 Emit Bourne-shell compatible code to set up environment variables.
177
178 --version
179 Print the version of dbus-launch
180
181 --help
182 Print the help info of dbus-launch
183
185 If you run dbus-launch myapp (with any other options), dbus-daemon will
186 not exit when myapp terminates: this is because myapp is assumed to be
187 part of a larger session, rather than a session in its own right.
188
190 See http://www.freedesktop.org/software/dbus/doc/AUTHORS
191
193 Please send bug reports to the D-Bus mailing list or bug tracker, see
194 http://www.freedesktop.org/software/dbus/
195
196
197
198D-Bus 1.12.20 01/26/2021 DBUS-LAUNCH(1)