简体   繁体   English

来自 root 用户的 Wayland 检测

[英]Wayland detection from root user

I have a script that must be launched as root.我有一个必须以 root 身份启动的脚本。 I need to detect the graphics system and identify it (windows X system, Wayland).我需要检测图形系统并识别它(windows X 系统、Wayland)。

I tried using some environment vars like ${XDG_SESSION_TYPE} or ${WAYLAND_DISPLAY} which are revealing if you are using x11 or wayland, or if you are in a headless system... but, the problem is that the vars are not working from root user.我尝试使用一些环境变量,例如${XDG_SESSION_TYPE}${WAYLAND_DISPLAY} ,如果您使用的是 x11 或 wayland,或者如果您使用的是无头系统,这些变量会显示出来……但是,问题是这些变量无法正常工作根用户。 As you know, the graphics environment is usually launched by a normal user and as I said at the beginning of the question, for reasons that I'm not going to explain here, the script needs to be launched as root.如您所知,图形环境通常由普通用户启动,正如我在问题开头所说的那样,由于我不打算在这里解释的原因,脚本需要以 root 身份启动。

Next screenshot is showing only one common element between users, the XAUTHORITY var...下一张截图只显示了用户之间的一个共同元素,即XAUTHORITY ……

在此处输入图像描述

I could use that but I think that could be a very dirty way to do it.我可以使用它,但我认为这可能是一种非常肮脏的方式。 It must be a better way.这一定是更好的方法。 Any suggestion?有什么建议吗? Thanks.谢谢。

The only reliable method is for you to obtain the report, from the environment by a non-root user ID , of the XDG_SESSION_TYPE variable's value.唯一可靠的方法是通过非 root 用户 ID 从环境中获取XDG_SESSION_TYPE变量值的报告。

  • For X-Windows, XDG_SESSION_TYPE=x11对于 X-Windows,XDG_SESSION_TYPE=x11
  • For Wayland, XDG_SESSION_TYPE=wayland对于 Wayland,XDG_SESSION_TYPE=wayland

However, as datenwolf stated, since root is specifically hindered by hard-coded security precautions , even if you customized your root's.bashrc, you won't be able to get the GUI to respond reliably, if at all, depending on the tools and elements you use.然而,正如 datenwolf 所说,由于 root 受到硬编码安全预防措施的特别阻碍,即使您自定义了 root's.bashrc,您也无法让 GUI 可靠地响应,如果有的话,这取决于工具和你使用的元素。

If, on the other hand, you are attempting to build a tool for specific use by high-level security specialists, then you will likely require a customized build of the OS (removing those hard-coded security blocks) to complement those tools.另一方面,如果您正试图构建一个供高级安全专家特定使用的工具,那么您可能需要一个定制的操作系统构建(删除那些硬编码的安全块)来补充这些工具。 That... is a huge task, which only those with deep pockets and unlimited resources... can allow themselves to contemplate... unless the developers were smart enough to anticipate such a need and have all those code segments "drop-out" during compilation with the appropriate compile-time flag turned on/off .那……是一项艰巨的任务,只有那些财力雄厚、资源无限的人……才能允许自己思考……除非开发人员足够聪明,能够预见到这种需求,并让所有这些代码段“退出” “在编译期间打开/关闭适当的编译时标志 :-) :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM