Skip to content

Commit

Permalink
Make display detection more robust. (#916)
Browse files Browse the repository at this point in the history
* Refactor X11 display detection.
  * Add a short wait to allow lightdm to start X11 after being restarted.
  * Use systemctl directly instead of relying on wrapper.
  • Loading branch information
nuclearsandwich committed Jul 27, 2023
1 parent be6a8d1 commit 1fa30be
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions jenkins-scripts/lib/check_graphic_card.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ GRAPHIC_CARD_PKG=""

export_display_variable()
{
# Hack to found the current display (if available) two steps:
# Check for /tmp/.X11-unix/ socket and check if the process is running
for i in $(ls /tmp/.X11-unix/ | sed -e 's@^X@:@')
# Check for an active X11 display socket.
for i in $(find /tmp/.X11-unix -type s)
do
# grep can fail so let's disable the fail or error during its call
set +e
ps aux | grep bin/X.*$i | grep -v grep
set -e
if [ $? -eq 0 ] ; then
export DISPLAY=$i
# If a process is running with the open socket then
# lsof will exit successfully.
if lsof -Fp $i ; then
# Strip the path and leading X from the X11 socket
# but check that the resulting string is numeric and
# non-empty before exporting.
DISPLAY=:$(basename $i | sed -n -E 's/^X([0-9]+)/:\1/p')
if [ -n "$DISPLAY" ]; then
export DISPLAY
fi
fi
done
}
Expand Down Expand Up @@ -79,7 +82,9 @@ if $GPU_SUPPORT_NEEDED; then
if [[ ${DISPLAY} == "" ]]; then
echo "GPU support needed by the script but DISPLAY var is empty"
# Try to restart lightdm. It should stop the script in the case of failure
sudo service lightdm restart
sudo systemctl restart lightdm
# Wait for lightdm service to restart X11.
sleep 5
# Second try to get display variable
export_display_variable
if [[ ${DISPLAY} == "" ]]; then
Expand Down

0 comments on commit 1fa30be

Please sign in to comment.