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

StackOverflow https://stackoverflow.com/questions/10517333

  •  06-06-2021
  •  | 
  •  

문제

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

도움이 되었습니까?

해결책 2

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top