UBUNTU: XOpenDisplay(NULL) fails when program run in boot sequence via rc.local

主宰稳场 提交于 2019-11-28 09:53:12

问题


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.

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?

David


回答1:


Solved thanks to tripleee.

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

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

where 'my-script' is:

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

everything works.




回答2:


Your program should only start once X11 is up and running. But a much better design is to make a service which runs with root privileges, but doesn't use X, and arrange for an X client to talk to it somehow. If you cannot exist without X, hook into the X11 startup sequence, rather than the system startup.



来源:https://stackoverflow.com/questions/10517333/ubuntu-xopendisplaynull-fails-when-program-run-in-boot-sequence-via-rc-local

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!