bash XDG_SESSION_COOKIE 环境变量有什么用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/632515/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the XDG_SESSION_COOKIE environment variable for?
提问by Altreus
I've been fighting with crontab recently because in Intrepid the gconftool uses a dbus backend, and that means that when used from crontab it doesn't work.
我最近一直在与 crontab 作斗争,因为在 Intrepid 中,gconftool 使用 dbus 后端,这意味着从 crontab 使用时它不起作用。
To make it work I have had to export the relevant environment variables when I log in so that it finds the dbus session address when the cron comes to run.
为了使其工作,我必须在登录时导出相关的环境变量,以便在 cron 运行时找到 dbus 会话地址。
Out of curiosity I wondered what environment the cron couldsee and it turns out all I have is HOME, LOGNAME, PATH, SHELL, CWDand this new one on me, XDG_SESSION_COOKIE. This looks curious and several googlings have thrown up a number of bugs or other feature requests involving it but nothing that tells me what it does.
出于好奇,我想知道 cron可以看到什么环境,结果我所拥有的只是HOME, LOGNAME, PATH, SHELL,CWD和这个新的,XDG_SESSION_COOKIE. 这看起来很奇怪,一些谷歌搜索已经抛出了许多涉及它的错误或其他功能请求,但没有任何东西告诉我它的作用。
My instinct is that this variable can be used to find all the stuff that I've had to export to the file that I source before the cron job runs.
我的直觉是这个变量可用于查找在 cron 作业运行之前我必须导出到我源文件的所有内容。
My questions, therefore, are a) can I? b) if so, how? and c) what (else) does it do?
因此,我的问题是 a) 我可以吗?b) 如果是,如何?c) 它(其他)做什么?
Thanks all
谢谢大家
回答by Johannes Schaub - litb
This is very interesting. I found out it is the display manager setting a cookie. That one can be used to register processes to belong to a "session" which are managed by a daemon called ConsoleKit. That is to support fast user switching. My KDE4.2.1 system apparently supports it too.
这是非常有趣的。我发现这是显示管理器设置 cookie。该进程可用于注册属于“会话”的进程,这些进程由名为ConsoleKit. 即支持快速用户切换。我的 KDE4.2.1 系统显然也支持它。
Read thisfedora wiki entry.
阅读这个Fedora wiki 条目。
So this environment variable is like DBUS_SESSION_BUS_ADDRESSto give access to some entity (in the case of XDG_SESSION_COOKIEa login-session managed by ConsoleKit). For example having that environment variable in place, you can ask the manager for your current session:
所以这个环境变量就像DBUS_SESSION_BUS_ADDRESS是授予对某个实体的访问权限(在XDG_SESSION_COOKIE由 ConsoleKit 管理的登录会话的情况下)。例如,有了那个环境变量,您可以向经理询问您当前的会话:
$ dbus-send --print-reply --system --type=method_call \
--dest=org.freedesktop.ConsoleKit \
/org/freedesktop/ConsoleKit/Manager \
org.freedesktop.ConsoleKit.Manager.GetCurrentSession
method return sender=:1.1 -> dest=:1.34 reply_serial=2
object path "/org/freedesktop/ConsoleKit/Session1"
$
The Manager also supports querying for the session some process belongs to
Manager 还支持查询某个进程所属的会话
$ [...].Manager.GetSessionForUnixProcess uint32:4494
method return sender=:1.1 -> dest=:1.42 reply_serial=2
object path "/org/freedesktop/ConsoleKit/Session1"
However, it does not list or somehow contain variables that is related to some cronjob. However, documentation of dbus-launchsays that libdbuswill automatically find the right DBUS bus address. For example, files are stored in /home/js/.dbus/session-busthat contain the correct current dbus session addresses.
但是,它没有列出或以某种方式包含与某些cron工作相关的变量。但是,文档dbus-launch说这libdbus将自动找到正确的 DBUS 总线地址。例如,存储的文件/home/js/.dbus/session-bus包含正确的当前 dbus 会话地址。

