Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2006-07-15 13:32:05 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2006-07-15 13:32:05 (GMT)
commitfaac100ba5cd7f344558904713c4f397a711396c (patch)
tree50a34519d6ddb4afc01cc22ba41373a6fe67b771 /shell
parent21b46a002256f7004c45c7ac379a93ce75d7834f (diff)
Automatically find a free display
Diffstat (limited to 'shell')
-rw-r--r--shell/Emulator.py36
1 files changed, 31 insertions, 5 deletions
diff --git a/shell/Emulator.py b/shell/Emulator.py
index 982fc21..373e3e2 100644
--- a/shell/Emulator.py
+++ b/shell/Emulator.py
@@ -1,20 +1,46 @@
+import logging
import os
+import socket
from Process import Process
class XephyrProcess(Process):
def __init__(self):
- # FIXME How to pick a free display number?
- self._display = 100
+ self._display = self.get_display_number()
cmd = 'Xephyr :%d -ac -screen 640x480' % (self._display)
Process.__init__(self, cmd)
-
+
+ def get_display_number(self):
+ """Find a free display number trying to connect to 6000+ sockets"""
+ retries = 20
+ display_number = 1
+ display_is_free = False
+
+ while not display_is_free and retries > 0:
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ try:
+ s.connect(('127.0.0.1', 6000 + display_number))
+ logging.info('Display %d is already in use. Trying next.' % (display_number))
+
+ display_number += 1
+ retries -= 1
+ except:
+ display_is_free = True
+
+ if display_is_free:
+ return display_number
+
+ return -1
+
def get_name(self):
return 'Xephyr'
def start(self):
- Process.start(self)
- os.environ['DISPLAY'] = ":%d" % (self._display)
+ if self._display < 0:
+ logging.error('Cannot find a free display.')
+ else:
+ Process.start(self)
+ os.environ['DISPLAY'] = ":%d" % (self._display)
class Emulator:
"""The OLPC emulator"""