dbus-launch
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被认为是一个大的会话的一部分,而不是一个在自己权限中的会话.