UBUNTU:当程序通过rc.local按启动顺序运行时,XOpenDisplay(NULL)失败 [英] UBUNTU: XOpenDisplay(NULL) fails when program run in boot sequence via rc.local

查看:537
本文介绍了UBUNTU:当程序通过rc.local按启动顺序运行时,XOpenDisplay(NULL)失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个程序,该程序在登录后在终端中具有ROOT权限运行,但是在重新启动后进行XOpenDisplay(NULL)调用时失败.该程序通过rc.local启动,但似乎看不到X11.

I have written a program that runs with ROOT permission in Terminal following login but fails when XOpenDisplay(NULL) call is made following reboot. The program is started up via rc.local but doesn't appear to be able to see X11.

我需要ROOT,因为我进行LibUSB调用,如果不是ROOT,这些操作将失败.我可以看到该程序正在以ROOT权限运行,但是检查环境变量显示未设置DISPLAY.我正在运行一个延迟循环,并且在用户登录后进行了检查,并且用户可以看到在环境变量中设置了DISPLAY,但程序无法执行.如果程序终止并在终端中运行,则它可以正常运行,因此问题在于,程序在启动时无法与X11进行交互,并且该状态持续存在.

I need ROOT because I make LibUSB calls and these fail if not ROOT. I can see the program is running with ROOT permission but inspection of environment variables shows DISPLAY not set. I have a delay loop running and checks are made after user login and user can see DISPLAY set in environment variables but program cannot. If program is terminated and run in Terminal it works perfectly so the problem is that the program cannot interact with X11 when it is started and this state persists.

我希望该程序可以在没有用户登录的情况下启动并运行.

I want the program to be up and running without user login.

有人可以让我知道我需要做什么吗?

Can anyone let me know what I need to do?

大卫

推荐答案

由于三元组而解决.

Ubuntu现在使用LightDM,因此将以下行添加到/etc/lightdm/lightdm.conf

Ubuntu now uses LightDM and so by adding the line below to /etc/lightdm/lightdm.conf

greeter-setup-script=usr/bin/'my-script'

其中我的脚本"是:

#!/bin/sh
/usr/bin/'my-prog' &

一切正常.

这篇关于UBUNTU:当程序通过rc.local按启动顺序运行时,XOpenDisplay(NULL)失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆