Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
487 views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...