Skip to content

Commit ae04aa6

Browse files
committed
remove race condition in display var for environment
1 parent 68fc323 commit ae04aa6

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

lib/arduino_ci/display_manager.rb

+13-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
require 'singleton'
33
require 'timeout'
44

5+
DESIRED_DISPLAY = ":1.0".freeze
6+
57
module ArduinoCI
68

79
# When arduino commands run, they need a graphical display.
@@ -34,15 +36,20 @@ def alive?(pid)
3436
end
3537

3638
# check whether an X server is taking connections
37-
def xserver_exist?
38-
run_silent(nil, ["xdpyinfo"])
39+
def xserver_exist?(display)
40+
run_silent({ "DISPLAY" => display }, ["xdpyinfo"])
3941
end
4042

41-
def xvfb_launched?(pid, timeout)
43+
# wait for the xvfb command to launch
44+
# @param display [String] the value of the DISPLAY env var
45+
# @param pid [Int] the process of Xvfb
46+
# @param timeout [Int] the timeout in seconds
47+
# @return [Bool] whether we detected a launch
48+
def xvfb_launched?(display, pid, timeout)
4249
Timeout.timeout(timeout) do
4350
loop do
4451
return false unless alive? pid
45-
return true if xserver_exist?
52+
return true if xserver_exist? display
4653
end
4754
end
4855
rescue Timeout::Error
@@ -71,7 +78,7 @@ def enable
7178
puts "pipeline_start for Xvfb"
7279
pipe = IO.popen(xvfb_cmd)
7380
@pid = pipe.pid
74-
@enabled = xvfb_launched?(@pid, 30)
81+
@enabled = xvfb_launched?(DESIRED_DISPLAY, @pid, 30)
7582
end
7683

7784
# disable the virtual display
@@ -130,7 +137,7 @@ def run_silent(env, *args)
130137
def environment
131138
return nil unless @existing || @enabled
132139
return {} if @existing
133-
{ "DISPLAY" => ":1.0" }
140+
{ "DISPLAY" => DESIRED_DISPLAY }
134141
end
135142

136143
# On finalize, ensure child process is ended

0 commit comments

Comments
 (0)