Beispiel #1
0
def runVncViewer(domid, do_autopass, do_daemonize=False):
    xs = OurXenstoreConnection()
    d = '/local/domain/%d/' % domid
    vnc_port = xs.read_eventually(d + 'console/vnc-port')
    vfb_backend = xs.read_maybe(d + 'device/vfb/0/backend')
    vnc_listen = None
    vnc_password = None
    vnc_password_tmpfile = None
    cmdl = ['vncviewer']
    if vfb_backend is not None:
        vnc_listen = xs.read_maybe(vfb_backend + '/vnclisten')
        if do_autopass:
            vnc_password = xs.read_maybe(vfb_backend + '/vncpasswd')
            if vnc_password is not None:
                cmdl.append('-autopass')
                vnc_password_tmpfile = os.tmpfile()
                print >>vnc_password_tmpfile, vnc_password
                vnc_password_tmpfile.seek(0)
                vnc_password_tmpfile.flush()
    if vnc_listen is None:
        vnc_listen = 'localhost'
    cmdl.append('%s:%d' % (vnc_listen, int(vnc_port) - 5900))
    if do_daemonize:
        pid = utils.daemonize('vncviewer', cmdl, vnc_password_tmpfile)
        if pid == 0:
            puts >>sys.stderr, 'failed to invoke vncviewer'
            os._exit(-1)
    else:
        print 'invoking ', ' '.join(cmdl)
        if vnc_password_tmpfile is not None:
            os.dup2(vnc_password_tmpfile.fileno(), 0)
        os.execvp('vncviewer', cmdl)
Beispiel #2
0
def runVncViewer(domid, do_autopass, do_daemonize=False):
    xs = OurXenstoreConnection()
    d = '/local/domain/%d/' % domid
    vnc_port = xs.read_eventually(d + 'console/vnc-port')
    vfb_backend = xs.read_maybe(d + 'device/vfb/0/backend')
    vnc_listen = None
    vnc_password = None
    vnc_password_tmpfile = None
    cmdl = ['vncviewer']
    if vfb_backend is not None:
        vnc_listen = xs.read_maybe(vfb_backend + '/vnclisten')
        if do_autopass:
            vnc_password = xs.read_maybe(vfb_backend + '/vncpasswd')
            if vnc_password is not None:
                cmdl.append('-autopass')
                vnc_password_tmpfile = os.tmpfile()
                print >> vnc_password_tmpfile, vnc_password
                vnc_password_tmpfile.seek(0)
                vnc_password_tmpfile.flush()
    if vnc_listen is None:
        vnc_listen = 'localhost'
    cmdl.append('%s:%d' % (vnc_listen, int(vnc_port) - 5900))
    if do_daemonize:
        pid = utils.daemonize('vncviewer', cmdl, vnc_password_tmpfile)
        if pid == 0:
            puts >> sys.stderr, 'failed to invoke vncviewer'
            os._exit(-1)
    else:
        print 'invoking ', ' '.join(cmdl)
        if vnc_password_tmpfile is not None:
            os.dup2(vnc_password_tmpfile.fileno(), 0)
        os.execvp('vncviewer', cmdl)
Beispiel #3
0
def spawn_vnc(display):
    """Spawns a vncviewer that listens on the specified display.  On success,
    returns the port that the vncviewer is listening on and sets the global
    vncpid.  On failure, returns 0.  Note that vncviewer is daemonized.
    """
    vncargs = (["vncviewer", "-log", "*:stdout:0",
            "-listen", "%d" % (VNC_BASE_PORT + display) ])
    global vncpid
    vncpid = utils.daemonize("vncviewer", vncargs)
    if vncpid == 0:
        return 0

    return VNC_BASE_PORT + display