1

RPI 3b+, Debian Stretch

I want to start a Qt applicaton via systemd. The app uses X and needs to open a display.

It always fails due to an Invalid MIT_MAGIC-COOKIE. But then systemd restarts it (on-failure) and it runs fine. ("Start APES Display Application is my Qt app--my grep picked up that "Light Display Manager has the same issue--fails first time, but succeeds on restart)

pi@right-display:~ $ cat /var/log/syslog | grep Display

Nov 16 10:43:26 right-display systemd[1]: Stopping Light Display Manager...

Nov 16 10:43:40 right-display systemd[1]: Started Start APES Display Application.

Nov 16 10:43:40 right-display systemd[1]: Starting Light Display Manager...

Nov 16 10:43:41 right-display x11vnc[653]: 16/11/2023 10:43:41 *** XOpenDisplay failed. No -display or DISPLAY.

Nov 16 10:43:41 right-display systemd[1]: Started Light Display Manager.

Nov 16 10:43:42 right-display APES_Display[572]: QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-pi' Nov 16 10:43:44 right-display APES_Display[572]: Invalid MIT-MAGIC-COOKIE-1 keyqt.qpa.screen: QXcbConnection: Could not connect to display :0 Nov 16 10:43:44 right-display APES_Display[572]: Could not connect to any X display.

Nov 16 10:43:44 right-display systemd[1]: Display.service: Main process exited, code=exited, status=1/FAILURE

Nov 16 10:43:44 right-display systemd[1]: Display.service: Unit entered failed state.

Nov 16 10:43:44 right-display systemd[1]: Display.service: Failed with result 'exit-code'.

Nov 16 10:43:45 right-display x11vnc[653]: 16/11/2023 10:43:45 *** XOpenDisplay of ":0" successful.

Nov 16 10:44:02 right-display systemd[1]: Display.service: Service hold-off time over, scheduling restart.

Nov 16 10:44:02 right-display systemd[1]: Stopped Start APES Display Application.

Nov 16 10:44:02 right-display systemd[1]: Started Start APES Display Application.

Nov 16 10:44:02 right-display APES_Display[1307]: QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-pi'

So, there must be some service that must be running before my app can open a display? Or, do I need to create a "magic cookie" that seems to only be needed at boot time (starting the service manually always works)

How do I figure figure out what it is?

2

1 Answer 1

-1

Probably the best is to create a systemd timer which will wait several seconds so until the display is operational and to make your service dependent on this timer. OnBootSec= is the timer option that should be used. From what we can see, the first failure appears between Starting LDM & Started LDM.

1
  • 1
    I'm pretty sure I can make it work by adding a delay, but wouldn't it be better to add an After=unit so that there isn't a race condition? The whole reason I'm switching to use systemd instead of starting using LXDE autostart is to eliminate race conditions that seem to cause sporadic issues. Nov 16, 2023 at 16:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .