|
2 | 2 | require 'singleton' |
3 | 3 | require 'timeout' |
4 | 4 |
|
| 5 | +DESIRED_DISPLAY = ":1.0".freeze |
| 6 | + |
5 | 7 | module ArduinoCI |
6 | 8 |
|
7 | 9 | # When arduino commands run, they need a graphical display. |
@@ -34,15 +36,20 @@ def alive?(pid) |
34 | 36 | end |
35 | 37 |
|
36 | 38 | # 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"]) |
39 | 41 | end |
40 | 42 |
|
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) |
42 | 49 | Timeout.timeout(timeout) do |
43 | 50 | loop do |
44 | 51 | return false unless alive? pid |
45 | | - return true if xserver_exist? |
| 52 | + return true if xserver_exist? display |
46 | 53 | end |
47 | 54 | end |
48 | 55 | rescue Timeout::Error |
@@ -71,7 +78,7 @@ def enable |
71 | 78 | puts "pipeline_start for Xvfb" |
72 | 79 | pipe = IO.popen(xvfb_cmd) |
73 | 80 | @pid = pipe.pid |
74 | | - @enabled = xvfb_launched?(@pid, 30) |
| 81 | + @enabled = xvfb_launched?(DESIRED_DISPLAY, @pid, 30) |
75 | 82 | end |
76 | 83 |
|
77 | 84 | # disable the virtual display |
@@ -130,7 +137,7 @@ def run_silent(env, *args) |
130 | 137 | def environment |
131 | 138 | return nil unless @existing || @enabled |
132 | 139 | return {} if @existing |
133 | | - { "DISPLAY" => ":1.0" } |
| 140 | + { "DISPLAY" => DESIRED_DISPLAY } |
134 | 141 | end |
135 | 142 |
|
136 | 143 | # On finalize, ensure child process is ended |
|
0 commit comments