Skip to content

Commit a6c2c3f

Browse files
committed
query x server to wait for launch
1 parent 6c3fc10 commit a6c2c3f

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

lib/arduino_ci/display_manager.rb

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,31 @@ def existing_display?
2424
false
2525
end
2626

27+
# check whether a process is alive
28+
# https://stackoverflow.com/a/32513298/2063546
29+
def alive?(pid)
30+
Process.kill(0, pid)
31+
true
32+
rescue
33+
false
34+
end
35+
36+
# check whether an X server is taking connections
37+
def xserver_exist?
38+
run_silent(nil, ["xdpyinfo"])
39+
end
40+
41+
def xvfb_launched?(pid, timeout)
42+
Timeout.timeout(timeout) do
43+
loop do
44+
return false unless alive? pid
45+
return true if xserver_exist?
46+
end
47+
end
48+
rescue Timeout::Error
49+
false
50+
end
51+
2752
# enable a virtual display
2853
def enable
2954
if @existing
@@ -35,14 +60,18 @@ def enable
3560
return unless @pid.nil? # TODO: disable first?
3661

3762
# open Xvfb
38-
xvfb_cmd = ["Xvfb", ":1", "-ac", "-screen", "0", "1280x1024x16"]
63+
xvfb_cmd = [
64+
"Xvfb",
65+
"+extension", "RANDR",
66+
":1",
67+
"-ac",
68+
"-screen", "0",
69+
"1280x1024x16",
70+
]
3971
puts "pipeline_start for Xvfb"
4072
pipe = IO.popen(xvfb_cmd)
4173
@pid = pipe.pid
42-
sleep(3) # TODO: test a connection to the X server?
43-
@enabled = true
44-
puts "\n\nxdpyinfo:\n\n"
45-
system(environment, "xdpyinfo")
74+
@enabled = xvfb_launched?(@pid, 30)
4675
end
4776

4877
# disable the virtual display

0 commit comments

Comments
 (0)