Skip to content

Commit 8fd9055

Browse files
committed
Set $DISPLAY before threads are started.
$DISPLAY is effectively a constant, so set it early, before the network thread is started, using a value in pyanaconda.constants.
1 parent e05a0e4 commit 8fd9055

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

anaconda

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,10 @@ def startX11():
120120

121121
# Start Xorg and wait for it become ready
122122
iutil.startX(["Xorg", "-br", "-logfile", "/tmp/X.log",
123-
":1", "vt6", "-s", "1440", "-ac",
123+
":%s" % constants.X_DISPLAY_NUMBER, "vt6", "-s", "1440", "-ac",
124124
"-nolisten", "tcp", "-dpi", "96",
125125
"-noreset"], output_redirect=xfd)
126126

127-
# Now that X is started, make $DISPLAY available
128-
os.environ["DISPLAY"] = ":1"
129-
130127
# function to handle X startup special issues for anaconda
131128
def doStartupX11Actions():
132129
"""Start window manager"""
@@ -410,6 +407,12 @@ def setupEnvironment():
410407
if "LD_PRELOAD" in os.environ:
411408
del os.environ["LD_PRELOAD"]
412409

410+
# Go ahead and set $DISPLAY whether we're going to use X or not
411+
if 'DISPLAY' in os.environ:
412+
flags.preexisting_x11 = True
413+
else:
414+
os.environ["DISPLAY"] = ":%s" % constants.X_DISPLAY_NUMBER
415+
413416
def setupLoggingFromOpts(options):
414417
if (options.debug or options.updateSrc) and not options.loglevel:
415418
# debugging means debug logging if an explicit level hasn't been st
@@ -618,9 +621,6 @@ def setupDisplay(anaconda, options, addons=None):
618621
stdoutLog.warning("Not asking for VNC because we don't have Xvnc")
619622
flags.vncquestion = False
620623

621-
if 'DISPLAY' in os.environ:
622-
flags.preexisting_x11 = True
623-
624624
# Should we try to start Xorg?
625625
want_x = anaconda.displayMode == 'g' and \
626626
not (flags.preexisting_x11 or flags.usevnc)
@@ -966,10 +966,10 @@ if __name__ == "__main__":
966966

967967
log.error("%s already exists, exiting", pidfile_path)
968968

969-
# If we have a $DISPLAY and zenity is available, we may be running in
970-
# a live environment and we can display an error dialog. Otherwise
971-
# just print an error.
972-
if "DISPLAY" in os.environ and os.access("/usr/bin/zenity", os.X_OK):
969+
# If we had a $DISPLAY at start and zenity is available, we may be
970+
# running in a live environment and we can display an error dialog.
971+
# Otherwise just print an error.
972+
if flags.preexisting_x11 and os.access("/usr/bin/zenity", os.X_OK):
973973
# The module-level _() calls are ok here because the language may
974974
# be set from the live environment in this case, and anaconda's
975975
# language setup hasn't happened yet.

pyanaconda/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,6 @@
174174
# for how long (in seconds) we try to wait for enough entropy for LUKS
175175
# keep this a multiple of 60 (minutes)
176176
MAX_ENTROPY_WAIT = 10 * 60
177+
178+
# X display number to use
179+
X_DISPLAY_NUMBER = 1

pyanaconda/vnc.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ def shutdownServer():
5555

5656
class VncServer:
5757

58-
def __init__(self, display="1", root="/", ip=None, name=None,
58+
def __init__(self, root="/", ip=None, name=None,
5959
password="", vncconnecthost="",
6060
vncconnectport="", log_file="/tmp/vncserver.log",
6161
pw_file="/tmp/vncpassword"):
62-
self.display = display
6362
self.root = root
6463
self.ip = ip
6564
self.name = name
@@ -123,9 +122,11 @@ def initialize(self):
123122
name_ips = [i[4][0] for i in socket.getaddrinfo(self.name, 0)]
124123
if self.name is not None and not self.name.startswith('localhost') \
125124
and ipstr is not None and self.ip in name_ips:
126-
self.connxinfo = "%s:%s (%s:%s)" % (socket.getfqdn(name=self.name), self.display, ipstr, self.display)
125+
self.connxinfo = "%s:%s (%s:%s)" % \
126+
(socket.getfqdn(name=self.name), constants.X_DISPLAY_NUMBER,
127+
ipstr, constants.X_DISPLAY_NUMBER)
127128
elif ipstr is not None:
128-
self.connxinfo = "%s:%s" % (ipstr, self.display,)
129+
self.connxinfo = "%s:%s" % (ipstr, constants.X_DISPLAY_NUMBER)
129130
else:
130131
self.connxinfo = None
131132

@@ -157,7 +158,7 @@ def connectToView(self):
157158
else:
158159
hostarg = self.vncconnecthost
159160

160-
vncconfigcommand = [self.root+"/usr/bin/vncconfig", "-display", ":%s"%self.display, "-connect", hostarg]
161+
vncconfigcommand = [self.root+"/usr/bin/vncconfig", "-display", ":%s" % constants.X_DISPLAY_NUMBER, "-connect", hostarg]
161162

162163
for _i in range(maxTries):
163164
vncconfp = iutil.startProgram(vncconfigcommand, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # vncconfig process
@@ -184,7 +185,7 @@ def startVncConfig(self):
184185

185186
self.log.info(_("Attempting to start vncconfig"))
186187

187-
vncconfigcommand = [self.root+"/usr/bin/vncconfig", "-nowin", "-display", ":%s" % self.display]
188+
vncconfigcommand = [self.root+"/usr/bin/vncconfig", "-nowin", "-display", ":%s" % constants.X_DISPLAY_NUMBER]
188189

189190
# Use startProgram to run vncconfig in the background
190191
iutil.startProgram(vncconfigcommand, stdout=self.openlogfile(), stderr=subprocess.STDOUT)
@@ -199,7 +200,7 @@ def VNCListen(self):
199200
else:
200201
self.log.info(_("Please manually connect your vnc client to <IP ADDRESS>:%s "
201202
"to begin the install. Switch to the shell (Ctrl-B 2) and "
202-
"run 'ip addr' to find the <IP ADDRESS>."), self.display)
203+
"run 'ip addr' to find the <IP ADDRESS>."), constants.X_DISPLAY_NUMBER)
203204

204205
def startServer(self):
205206
self.log.info(_("Starting VNC..."))
@@ -226,7 +227,7 @@ def startServer(self):
226227
self.setVNCPassword()
227228

228229
# Lets start the xvnc.
229-
xvnccommand = [ XVNC_BINARY_NAME, ":%s" % self.display,
230+
xvnccommand = [ XVNC_BINARY_NAME, ":%s" % constants.X_DISPLAY_NUMBER,
230231
"-depth", "16", "-br",
231232
"IdleTimeout=0", "-auth", "/dev/null", "-once",
232233
"DisconnectClients=false", "desktop=%s" % (self.desktop,),
@@ -266,8 +267,6 @@ def startServer(self):
266267
else:
267268
self.VNCListen()
268269

269-
os.environ["DISPLAY"]=":%s" % self.display
270-
271270
# Start vncconfig for copy/paste
272271
self.startVncConfig()
273272

0 commit comments

Comments
 (0)