1 |
commit: e00275cad8aa0f5979c50d2fc9b317ebf754f9c2 |
2 |
Author: Justin Lecher <jlec <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Nov 26 10:17:13 2015 +0000 |
4 |
Commit: Justin Lecher <jlec <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Nov 26 10:26:01 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=e00275ca |
7 |
|
8 |
virtualx.eclass: Always start Xvfb session |
9 |
|
10 |
In order to have guarantee the same X env, we should always |
11 |
create a Xvfb session instead of attaching to a running X session. |
12 |
|
13 |
Gentoo-Bug: https://bugs.gentoo.org/show_bug.cgi?id=374141 |
14 |
|
15 |
Signed-off-by: Justin Lecher <jlec <AT> gentoo.org> |
16 |
|
17 |
eclass/virtualx.eclass | 112 ++++++++++++++++++++++--------------------------- |
18 |
1 file changed, 50 insertions(+), 62 deletions(-) |
19 |
|
20 |
diff --git a/eclass/virtualx.eclass b/eclass/virtualx.eclass |
21 |
index 69d9230..5d27ed9 100644 |
22 |
--- a/eclass/virtualx.eclass |
23 |
+++ b/eclass/virtualx.eclass |
24 |
@@ -71,7 +71,7 @@ esac |
25 |
|
26 |
# @FUNCTION: virtualmake |
27 |
# @DESCRIPTION: |
28 |
-# Function which attach to running X session or start new Xvfb session |
29 |
+# Function which start new Xvfb session |
30 |
# where the VIRTUALX_COMMAND variable content gets executed. |
31 |
virtualmake() { |
32 |
debug-print-function ${FUNCNAME} "$@" |
33 |
@@ -91,77 +91,65 @@ virtualmake() { |
34 |
VIRTUALX_COMMAND=${maketype} |
35 |
fi |
36 |
|
37 |
- # If $DISPLAY is not set, or xhost cannot connect to an X |
38 |
- # display, then do the Xvfb hack. |
39 |
- if [[ -n ${XVFB} && -n ${XHOST} ]] && \ |
40 |
- ( [[ -z ${DISPLAY} ]] || ! (${XHOST} &>/dev/null) ) ; then |
41 |
- debug-print "${FUNCNAME}: running Xvfb hack" |
42 |
- export XAUTHORITY= |
43 |
- # The following is derived from Mandrake's hack to allow |
44 |
- # compiling without the X display |
45 |
- |
46 |
- einfo "Scanning for an open DISPLAY to start Xvfb ..." |
47 |
- # If we are in a chrooted environment, and there is already a |
48 |
- # X server started outside of the chroot, Xvfb will fail to start |
49 |
- # on the same display (most cases this is :0 ), so make sure |
50 |
- # Xvfb is started, else bump the display number |
51 |
- # |
52 |
- # Azarah - 5 May 2002 |
53 |
- XDISPLAY=$(i=0; while [[ -f /tmp/.X${i}-lock ]] ; do ((i++));done; echo ${i}) |
54 |
- debug-print "${FUNCNAME}: XDISPLAY=${XDISPLAY}" |
55 |
- |
56 |
- # We really do not want SANDBOX enabled here |
57 |
- export SANDBOX_ON="0" |
58 |
- |
59 |
+ debug-print "${FUNCNAME}: running Xvfb hack" |
60 |
+ export XAUTHORITY= |
61 |
+ # The following is derived from Mandrake's hack to allow |
62 |
+ # compiling without the X display |
63 |
+ |
64 |
+ einfo "Scanning for an open DISPLAY to start Xvfb ..." |
65 |
+ # If we are in a chrooted environment, and there is already a |
66 |
+ # X server started outside of the chroot, Xvfb will fail to start |
67 |
+ # on the same display (most cases this is :0 ), so make sure |
68 |
+ # Xvfb is started, else bump the display number |
69 |
+ # |
70 |
+ # Azarah - 5 May 2002 |
71 |
+ XDISPLAY=$(i=0; while [[ -f /tmp/.X${i}-lock ]] ; do ((i++));done; echo ${i}) |
72 |
+ debug-print "${FUNCNAME}: XDISPLAY=${XDISPLAY}" |
73 |
+ |
74 |
+ # We really do not want SANDBOX enabled here |
75 |
+ export SANDBOX_ON="0" |
76 |
+ |
77 |
+ debug-print "${FUNCNAME}: ${XVFB} :${XDISPLAY} ${xvfbargs}" |
78 |
+ ${XVFB} :${XDISPLAY} ${xvfbargs} &>/dev/null & |
79 |
+ sleep 2 |
80 |
+ |
81 |
+ local start=${XDISPLAY} |
82 |
+ while [[ ! -f /tmp/.X${XDISPLAY}-lock ]]; do |
83 |
+ # Stop trying after 15 tries |
84 |
+ if ((XDISPLAY - start > 15)) ; then |
85 |
+ eerror "'${XVFB} :${XDISPLAY} ${xvfbargs}' returns:" |
86 |
+ echo |
87 |
+ ${XVFB} :${XDISPLAY} ${xvfbargs} |
88 |
+ echo |
89 |
+ eerror "If possible, correct the above error and try your emerge again." |
90 |
+ die "Unable to start Xvfb" |
91 |
+ fi |
92 |
+ ((XDISPLAY++)) |
93 |
debug-print "${FUNCNAME}: ${XVFB} :${XDISPLAY} ${xvfbargs}" |
94 |
${XVFB} :${XDISPLAY} ${xvfbargs} &>/dev/null & |
95 |
sleep 2 |
96 |
+ done |
97 |
|
98 |
- local start=${XDISPLAY} |
99 |
- while [[ ! -f /tmp/.X${XDISPLAY}-lock ]]; do |
100 |
- # Stop trying after 15 tries |
101 |
- if ((XDISPLAY - start > 15)) ; then |
102 |
- eerror "'${XVFB} :${XDISPLAY} ${xvfbargs}' returns:" |
103 |
- echo |
104 |
- ${XVFB} :${XDISPLAY} ${xvfbargs} |
105 |
- echo |
106 |
- eerror "If possible, correct the above error and try your emerge again." |
107 |
- die "Unable to start Xvfb" |
108 |
- fi |
109 |
+ # Now enable SANDBOX again if needed. |
110 |
+ export SANDBOX_ON="${OLD_SANDBOX_ON}" |
111 |
|
112 |
- ((XDISPLAY++)) |
113 |
- debug-print "${FUNCNAME}: ${XVFB} :${XDISPLAY} ${xvfbargs}" |
114 |
- ${XVFB} :${XDISPLAY} ${xvfbargs} &>/dev/null & |
115 |
- sleep 2 |
116 |
- done |
117 |
- |
118 |
- # Now enable SANDBOX again if needed. |
119 |
- export SANDBOX_ON="${OLD_SANDBOX_ON}" |
120 |
- |
121 |
- einfo "Starting Xvfb on \$DISPLAY=${XDISPLAY} ..." |
122 |
- |
123 |
- export DISPLAY=:${XDISPLAY} |
124 |
- # Do not break on error, but setup $retval, as we need |
125 |
- # to kill Xvfb |
126 |
- debug-print "${FUNCNAME}: ${VIRTUALX_COMMAND} \"$@\"" |
127 |
- if has "${EAPI}" 2 3; then |
128 |
- ${VIRTUALX_COMMAND} "$@" |
129 |
- retval=$? |
130 |
- else |
131 |
- nonfatal ${VIRTUALX_COMMAND} "$@" |
132 |
- retval=$? |
133 |
- fi |
134 |
+ einfo "Starting Xvfb on \$DISPLAY=${XDISPLAY} ..." |
135 |
|
136 |
- # Now kill Xvfb |
137 |
- kill $(cat /tmp/.X${XDISPLAY}-lock) |
138 |
- else |
139 |
- debug-print "${FUNCNAME}: attaching to running X display" |
140 |
- # Normal make if we can connect to an X display |
141 |
- debug-print "${FUNCNAME}: ${VIRTUALX_COMMAND} \"$@\"" |
142 |
+ export DISPLAY=:${XDISPLAY} |
143 |
+ # Do not break on error, but setup $retval, as we need |
144 |
+ # to kill Xvfb |
145 |
+ debug-print "${FUNCNAME}: ${VIRTUALX_COMMAND} \"$@\"" |
146 |
+ if has "${EAPI}" 2 3; then |
147 |
${VIRTUALX_COMMAND} "$@" |
148 |
retval=$? |
149 |
+ else |
150 |
+ nonfatal ${VIRTUALX_COMMAND} "$@" |
151 |
+ retval=$? |
152 |
fi |
153 |
|
154 |
+ # Now kill Xvfb |
155 |
+ kill $(cat /tmp/.X${XDISPLAY}-lock) |
156 |
+ |
157 |
# die if our command failed |
158 |
[[ ${retval} -ne 0 ]] && die "${FUNCNAME}: the ${VIRTUALX_COMMAND} failed." |