NAME
dbus-launch - Utility to start a message bus from a shell script
dbus-launch - 從shell腳本啟動一個消息總線的工具(實用程序)
URL
http://dbus.freedesktop.org/doc/dbus-launch.1.html
SYNOPSIS
dbus-launch [--version ] [--help ] [--sh-syntax ] [--csh-syntax ] [--auto-syntax ] [--binary-syntax ] [--close-stderr ] [--exit-with-session ] [--autolaunch=MACHINEID
] [--config-file=FILENAME
] [PROGRAM
] [ARGS
...]
DESCRIPTION
The dbus-launch command is used to start a session bus instance of dbus-daemon from a shell script.
dbus-launch 命令用於從shell腳本啟動一個 dbus-daemon 的會話總線實例.
It would normally be called from a user's login scripts.
dbus-launch 命令通常會在用戶的登錄腳本中調用.
Unlike the daemon itself, dbus-launch exits, so backticks or the $() construct can be used to read information from dbus-launch.
與守護進程不同, 如果 dbus-launch 退出, 那么可以使用反引號或者$()結構從dbus-launch中讀取信息.
With no arguments, dbus-launch will launch a session bus instance and print the address and pid of that instance to standard output.
如果沒有參數, dbus-launch 會加載一個會話總線實例,並且把地址和實例的pid打印到標准輸出.
You may specify a program to be run; in this case,
dbus-launch will launch a session bus instance,
你可以指定一個程序運行; 在這種情況下, dbus-launch 會加載一個會話實例,
set the appropriate environment variables so the specified program can find the bus,
and then execute the specified program, with the specified arguments. See below for examples.
並且設置恰當的環境變量使指定的程序能夠找到總線,並且之后使用指定的參數來執行指定的程序.
看下面的例子作為參考.
If you launch a program, dbus-launch will not print the information about the new bus to standard output.
如果你加載一個程序, dbus-launch 不會在標准輸出打印新總線的信息.
When dbus-launch prints bus information to standard output,
by default it is in a simple key-value pairs format.
當dbus-launch在標准輸出打印bus信息時, 默認情況下是簡單的key-value pairs格式.
However, you may request several alternate syntaxes using the --sh-syntax,
--csh-syntax, --binary-syntax, or --auto-syntax options.
當然, 你可以請求幾個可替換的語法 通過使用--sh-syntax, --csh-syntax, --binary-syntax, 或者 --auto-syntax 選項.
Several of these cause dbus-launch to emit shell code to set up the environment.
其中幾個會引起dbus-launch發送shell code來設置環境.
With the --auto-syntax option, dbus-launch looks at the value of the SHELL environment variable
to determine which shell syntax should be used.
使用--auto-syntax 選項, dbus-launch 會根據SHELL環境變量來決定使用哪一個shell語法.
If SHELL ends in "csh", then csh-compatible code is emitted; otherwise Bourne shell code is emitted.
如果SHELL 以"csh" 結尾, 那么會發送 csh-compatible code; 否則會發送Bourne shell code.
Instead of passing --auto-syntax, you may explicity specify a particular one
by using --sh-syntax for Bourne syntax, or --csh-syntax for csh syntax.
如果不使用 --auto-syntax選項, 你可以明確的指定一個,
--sh-syntax for Bourne syntax, or --csh-syntax for csh syntax.
In scripts, it's more robust to avoid --auto-syntax and you hopefully know which shell your script is written in.
在腳本中, 避免使用 --auto-syntax 會增加腳本的健壯性,並且你也希望知道你的腳本寫在什么shell中.
See http://www.freedesktop.org/software/dbus/ for more information about D-Bus.
See also the man page for dbus-daemon.
EXAMPLES
Here is an example of how to use dbus-launch with an sh-compatible shell to start the per-session bus daemon:
下面是一個如何使用dbus-launch的例子, 使用一個sh-compatible shell來啟動每會話總線守護進程:
## 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 --exit-with-session` echo "D-Bus per-session daemon address is: $DBUS_SESSION_BUS_ADDRESS" fi
You might run something like that in your login scripts.
你可以在你的登錄腳本中運行類似的命令.
Note that in this case, dbus-launch will exit, and dbus-daemon will not be terminated automatically on logout.
在這個例子中,需要注意的是dbus-launch會退出,但是dbus-daemon在登出會自動結束.
Another way to use dbus-launch is to run your main session program, like so:
另一種使用dbus-launch的方法是運行你的主會話程序, 像下面這樣:
Distributions running 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), as in these examples:
dbus-launch --exit-with-session gnome-session dbus-launch --exit-with-session openbox dbus-launch --exit-with-session ~/.xsession
The above would likely be appropriate for ~/.xsession or ~/.Xclients.
上面的用法應當在 ~/.xsession 和 ~/.Xclients 文件中使用.
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
.
AUTOMATIC LAUNCHING
If DBUS_SESSION_BUS_ADDRESS is not set for a process that tries to use D-Bus,
如果沒有為一個要使用D-Bus的進程設置 DBUS_SESSION_BUS_ADDRESS,
by default the process will attempt to invoke dbus-launch with the --autolaunch option to start up a new session bus
默認情況下,這個進程會試圖使用--autolaunch選項執行dbus-launch來啟動一個新的會話,
or find the existing bus address on the X display or in a file in ~/.dbus/session-bus/
或者尋找在X display上或目錄(~/.dbus/session-bus/)下文件中 存在的總線地址.
Whenever an autolaunch occurs, the application that had to start a new bus will be in its own little world;
每當一個autolaunch發生,需要啟動一個新總線的應用會在自己的小世界中;
it can effectively end up starting a whole new session if it tries to use a lot of bus services.
如果應用想要使用很多的總線服務,這種方式有效的啟動一個全新的會話.
This can be suboptimal or even totally broken, depending on the app and what it tries to do.
這種方式是次優甚至毀滅性的, 這取決於app和他想要做什么.
There are two common reasons for autolaunch.
使用autolaunch有2個通常的原因.
One is ssh to a remote machine.
一個是ssh來遠程計算機.
The ideal fix for that would be forwarding of DBUS_SESSION_BUS_ADDRESS in the same way that DISPLAY is forwarded.
In the meantime, you can edit the session.conf config file to have your session bus listen on TCP,
在此期間, 你可以編輯 session.conf 配置文件來使你的session bus 監聽TCP,
and manually set DBUS_SESSION_BUS_ADDRESS, if you like.
如果你願意,你可以手動設置 DBUS_SESSION_BUS_ADDRESS.
The second common reason for autolaunch is an su to another user,
第二個原因是超級用戶對於另一個用戶,
and display of X applications running as the second user on the display belonging to the first user.
並且X應用的顯示作為第二個用戶運行在屬於第一個用戶的的display上.
Perhaps the ideal fix in this case would be to allow the second user to connect to the session bus of the first user,
也可以這個case可能允許第二個用戶連接到第一個用的會話總線上,
just as they can connect to the first user's display. However, a mechanism for that has not been coded.
就像和他可以連接到第一個用戶的display上, 但是這種結構沒有實現.
You can always avoid autolaunch by manually setting DBUS_SESSION_BUS_ADDRESS.
你總是可以通過手動設置DBUS_SESSION_BUS_ADDRESS來避免autolaunch.
Autolaunch happens because the default address if none is set is "autolaunch:",
Autolaunch發生是因為默認的地址中
so if any other address is set there will be no autolaunch.
所以如果設置有任何其他地址,就不會發生autolaunch.
You can however include autolaunch in an explicit session bus address as a fallback,
然而你可以在總線地址中包含autolaunch作為備選方案,
for example DBUS_SESSION_BUS_ADDRESS="something:,autolaunch:"
in that case if the first address doesn't work, processes will autolaunch.
這種情況下,如果第一個地址不能正常工作,進程就會autolaunch.
(The bus address variable contains a comma-separated list of addresses to try.)
總線地址變量是一個使用逗號分隔的可以嘗試使用的地址列表.
The --autolaunch option is considered an internal implementation detail of libdbus, and in fact there are plans to change it.
--autolaunch選項被認為是libdbus一個內部實現詳細, 並且實際上計划要改變它.
There's no real reason to use it outside of the libdbus implementation anyhow.
總之沒有任何原因在libdbus實現外使用 --autolaunch選項.
OPTIONS
The following options are supported:
dbus-launch命令支持下面的選項:
--auto-syntax
Choose --csh-syntax or --sh-syntax based on the SHELL environment variable.
根據環境變量SHELL的值自動選擇使用--csh-syntax 或者 --sh-syntax.
--binary-syntax
Write to stdout a nul-terminated bus address,
--binary-syntax 向stdout寫一個null結尾的bus地址字符串,
then the bus PID as a binary integer of size sizeof(pid_t),
跟着是總線PID,大小是sizeof(pid_t)二進制整型.
then the bus X window ID as a binary integer of size sizeof(long).
再跟着是這個總線的 X window ID,大小是sizeof(long)二進制整型.
Integers are in the machine's byte order, not network byte order or any other canonical byte order.
整形是使用機器的字節序,不是網絡字節序或者其他標准的字節序.
--csh-syntax
Emit csh compatible code to set up environment variables.
發送csh兼容碼設置環境變量
--sh-syntax
Emit Bourne-shell compatible code to set up environment variables.
發送Bourne-shell兼容碼設置環境變量
--close-stderr
Close the standard error output stream before starting the D-Bus daemon.
啟動D-Bus 守護進程前關閉標准輸出流.
This is useful if you want to capture dbus-launch error messages
but you don't want dbus-daemon to keep the stream open to your application.
如果你想捕獲dbus-launch錯誤消息,但是不想dbus-daemon保持流對對應用的開放,這會使非常有用的.
--config-file=FILENAME
Pass --config-file=FILENAME to the bus daemon, instead of passing it the --session argument.
通過將配置文件FILENAME傳給 bus daemon 來代替 --session argument.
See the man page for dbus-daemon
--exit-with-session
If this option is provided, a persistent "babysitter" process will be created that watches
stdin for HUP and tries to connect to the X server.
如果提供了這個選項, 會創建一個持續的 "babysitter"進程用於監視stdin 中的 HUP信息, 並且試着連接到 X server.
If this process gets a HUP on stdin or loses its X connection, it kills the message bus daemon.
如果這個進程在stdin中獲得了HUP或者丟失了他的 X connection, 他會終止消息總線的守護進程.
--autolaunch=MACHINEID
This option implies that dbus-launch should scan for a previously-started session and reuse the values found there.
這個選項意味着dbus-launch應該掃描先前啟動的session並且復用在那發現的值.
If no session is found, it will start a new session.
如果沒有找到會話, 他會啟動一個新的會話.
The --exit-with-session option is implied if --autolaunch is given.
如果提供了--atuolaunch選項, --exit-with-session選項也默認開啟.
This option is for the exclusive use of libdbus, you do not want to use it manually. It may change in the future.
這個選項是為libdbus獨有的, 你不會想要手動使用這個選項.
--version
Print the version of dbus-launch
NOTES
If you run dbus-launch myapp (with any other options), dbus-daemon will not exit when myapp terminates:
this is because myapp is assumed to be part of a larger session, rather than a session in its own right.
如果你運行下面這樣的指令(和其他任何選項),
dbus-launch myapp
當myapp結束時,dbus-daemon也不會退出,這是因為myapp被認為是一個大的會話的一部分,而不是一個在自己權限中的會話.