OpenSecurity/bin/cygwin.py
changeset 165 a1b7a5a48a1e
parent 152 028c3055147f
child 167 1e1811fa44bc
     1.1 --- a/OpenSecurity/bin/cygwin.py	Thu May 15 09:19:09 2014 +0100
     1.2 +++ b/OpenSecurity/bin/cygwin.py	Tue May 20 15:26:03 2014 +0200
     1.3 @@ -37,7 +37,7 @@
     1.4  import subprocess
     1.5  import sys
     1.6  import _winreg
     1.7 -from subprocess import Popen, PIPE, call, STARTUPINFO, _subprocess
     1.8 +from subprocess import Popen, PIPE, STARTUPINFO, _subprocess
     1.9  import threading
    1.10  
    1.11  # local
    1.12 @@ -74,24 +74,6 @@
    1.13      theClass.user_home = os.environ['APPDATA']#os.path.expandvars("%APPDATA%")
    1.14      return theClass
    1.15  
    1.16 -class XRunner(threading.Thread): 
    1.17 -    #running = True
    1.18 -    def __init__(self): 
    1.19 -        threading.Thread.__init__(self)
    1.20 - 
    1.21 -    def stop(self):
    1.22 -        self.running = False
    1.23 -        
    1.24 -    def run(self):
    1.25 -        #while self.running:
    1.26 -        logger.info('X starting')
    1.27 -        if not Cygwin.is_X11_running():
    1.28 -            #os.system('"'+Cygwin.cygwin_x11+'" :0 -multiwindow -resize')
    1.29 -            sts = call('"'+Cygwin.cygwin_x11+'" :0 -multiwindow -resize', shell=True)
    1.30 -        else:
    1.31 -            logger.info('X already started')
    1.32 -                
    1.33 -            
    1.34              
    1.35  @once
    1.36  class Cygwin(object):
    1.37 @@ -231,27 +213,23 @@
    1.38      # executes command over ssh on guest vm with X forwarding
    1.39      @staticmethod
    1.40      def sshExecuteX11(command, address, user_name, certificate, wait_return=True):
    1.41 -        #return call('"'+ Cygwin.cygwin_bash +'" -l -c "' + 'DISPLAY=:0.0 ssh -Y -i \\\"' + certificate +'\\\" ' + user_name + '@' + address + ' ' + command + '"', shell=True)
    1.42          return Cygwin.bashExecute('DISPLAY=:0.0 ssh -Y -o StrictHostKeyChecking=no -i \\\"' + certificate +'\\\" ' + user_name + '@' + address + ' ' + command + '')
    1.43  
    1.44      @staticmethod
    1.45      def is_X11_running():
    1.46          """check if we can connect to a X11 running instance"""
    1.47 -        p = Cygwin.bashExecute('xset -display :0.0 q', wait_return = True, window = False) 
    1.48 +        p = Cygwin.bashExecute('xset -display :0 q', wait_return = True, window = False) 
    1.49          return p[0] == 0
    1.50          
    1.51      @staticmethod
    1.52      def start_X11():
    1.53 -        """start X11 in the background (if not already running) on DISPLAY=:0"""
    1.54 -        runner = XRunner()
    1.55 -        runner.start()
    1.56 +        """start X11 in the background (if not already running) on DISPLAY=:0
    1.57 +        
    1.58 +        If there is already a X11 running then exit silently, calling this
    1.59 +        method as often as needed.
    1.60 +        """
    1.61 +        Popen('"' + Cygwin.cygwin_x11 + '" :0 -multiwindow -resize -silent-dup-error')
    1.62          return (0, None, None)
    1.63 -
    1.64 -        # launch X11
    1.65 -        #return Cygwin.execute(Cygwin.cygwin_x11, ':0 -multiwindow', wait_return = True, window = False)
    1.66 -        #return Cygwin.bashExecute('XWin :0 -multiwindow', wait_return = True, window = False)
    1.67 -        #return Cygwin.bashExecute('DISPLAY=:0.0 xhost +', wait_return = True, window = False)
    1.68 -        #return os.system('"'+Cygwin.cygwin_x11+'" :0 -multiwindow -resize')
    1.69      
    1.70      @staticmethod    
    1.71      def cygPath(path):