Jetson Tx2 NX: display=:0 not ready at lightdm start

I use autologin of lightdm to skip login GUI and redirect desktop to my own session.
So after boot, it will directly go to my script set in my_session.desktop
script bellow:

#!/bin/bash -x

echo aaaa > /home/audfly/aaaa
echo ${DISPLAY} >> /home/audfly/aaaa
echo `whoami` >> /home/audfly/aaaa
while true
do
	xrandr >> /home/audfly/aaaa 2>&1
	sleep 1
done
echo aaaa >> /home/audfly/aaaa

Then I always get some error log like:

Invalid MIT-MAGIC-COOKIE-1 keyCan't open display :0
Invalid MIT-MAGIC-COOKIE-1 keyCan't open display :0
Invalid MIT-MAGIC-COOKIE-1 keyCan't open display :0

But if I restart lightdm, output of xrandr will be ok.

I think this is because some Nvidia driver’s not ready when lightdm start at boot. It sets DISPLAY=:0 anyway no mater whether it is ready or not indeed.

How can I solve this problem without restart lightdm? I can add some wait time before lightdm service but I don’t know how to check ready or pick which service as exec before?

Anything would be help!

Something I’ve done but not work:

  1. remove Option "AllowEmptyInitialConfiguration" "true" in /etc/X11/xorg.conf
  2. add [LightDM] logind-check-graphical=true in /etc/lightdm/lightdm.conf

There’s a way to make xrandr work:

#!/bin/bash -x

echo aaaa > /home/audfly/aaaa
echo ${DISPLAY} >> /home/audfly/aaaa
echo `whoami` >> /home/audfly/aaaa

xrandr >> /home/audfly/aaaa 2>&1
if [ $? != '0' ];then
        echo "${DISPLAY} not work!"
else
        echo "${DISPLAY} work!"
fi

startx &

sleep 2

DISPLAY=:1 xrandr >> /home/audfly/aaaa 2>&1
if [ $? != '0' ];then
        echo ":1 not work!"
else
        echo ":1 work!"
fi

echo aaaa >> /home/audfly/aaaa

log bellow:

aaaa
:0
audfly
Invalid MIT-MAGIC-COOKIE-1 keyCan't open display :0
Screen 0: minimum 8 x 8, current 1024 x 600, maximum 32767 x 32767
HDMI-0 connected primary 1024x600+0+0 (normal left inverted right x axis y axis) 470mm x 260mm
   1024x600      59.82*+
   1920x1080     60.00    59.95    50.00
   1280x1024     75.03
   1280x720      60.00    59.94    50.00
   1024x768      75.03    70.07    60.01
   832x624       75.05
   800x600       75.00    72.19    60.32    56.25
   720x576       50.00
   720x480       59.94
   720x400       70.04
   640x480       75.00    72.81    59.94
DP-0 disconnected (normal left inverted right x axis y axis)
aaaa

But why can’t I use display=:0 at boot while it can be used if restart lightdm?
The method is not elegant for me. Is there a better way?

Hi,
Please check Jetson Nano FAQ

Q: How to autorun an app or commands at startup?

Link 3 and 4 may be similar to you use-case. Please take a look.