XOpenDisplay 由于 udev 事件而失败

发布于 2024-10-06 21:59:07 字数 223 浏览 4 评论 0原文

我试图像这样打开 X 显示:

disp = XOpenDisplay(NULL);

当我从用户 shell 运行它时,它工作正常,但如果它从 udev 事件(Ubuntu 10.10)运行,函数调用将返回 NULL。我想知道这是否与不同的环境有关,因此也尝试了 XOpenDisplay(":0.0") 但无济于事。

有谁知道为什么会发生这种情况?

I am trying to open the X display like so:

disp = XOpenDisplay(NULL);

When I run this from my users shell it works fine but if it is run from a udev event (Ubuntu 10.10) the function call returns NULL. I wondered if this has something to do with the differing environment so have tried XOpenDisplay(":0.0") also but no avail.

Does anyone know why this happens?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

給妳壹絲溫柔 2024-10-13 21:59:07

XOpenDisplay(NULL) 将检查 DISPLAY 环境变量,该变量通常不在 udev 上下文中设置。为了能够使用 XOpenDisplay(something)(包括 something=NULL),您需要 X 服务器实例的访问密钥。

如果您想使用 XOpenDisplay 或任何使用它的图形程序,则需要将 XAUTHORITY 环境变量设置为密钥文件的位置。如果此环境变量为空,则使用 ~/.Xauthority 作为后备。

尝试从 udev 启动一些图形程序是一个坏主意(请阅读:您的方法和设计有问题):您不知道 X 显示编号。您也无法猜测,因为很可能有不止一台 X 服务器处于活动状态。然后您需要拥有其密钥文件,而该文件并不总是能够确定或获取。 udev 可以以 root 身份运行,但也有一些东西,比如使用 root_squash 挂载 NFS,以及人们可以用来重新定位密钥文件的 XAUTHORITY 变量。

如今图形问题的工作方式是用户或他/她正在使用的桌面环境必须启动专门侦听某些事件的后台程序。这样你就不能简单地侵入人们的屏幕,而必须遵守他们的事件通知系统。

XOpenDisplay(NULL) would inspect the DISPLAY environment variable, which usually is not set in udev context. To be able to use XOpenDisplay(something) (including something=NULL), you need the access key to the X server instance.

The XAUTHORITY environment variable is to be set to the location of the key file if you want to use XOpenDisplay or any graphical program that makes use of it. If this env var is empty, ~/.Xauthority is used as a fallback.

Trying to start some graphical program from udev is a bad idea (read: something is wrong in your approach and design): You don't know the X display number. You cannot guess it either, because there may be very well more than one X server active. And then you need to have its key file, which is not always possible to determine or obtain either. udev may run as root, but there are things like NFS mounts with root_squash, and the XAUTHORITY variable with which people can relocate their key file.

The way graphical problems work these days is that the user, or the desktop environment s/he is using, has to start a background program specifically listening for certain events. Just so that you cannot simply intrude on people's screens, but have to abide by their event notification system.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文