zone-vnc-console revision 4046
4c221b0da1816acf2ca302b10092df059484468dvboxsync# Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
4c221b0da1816acf2ca302b10092df059484468dvboxsync# Licensed under the Apache License, Version 2.0 (the "License"); you may
4c221b0da1816acf2ca302b10092df059484468dvboxsync# not use this file except in compliance with the License. You may obtain
4c221b0da1816acf2ca302b10092df059484468dvboxsync# a copy of the License at
4c221b0da1816acf2ca302b10092df059484468dvboxsync# Unless required by applicable law or agreed to in writing, software
4c221b0da1816acf2ca302b10092df059484468dvboxsync# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
4c221b0da1816acf2ca302b10092df059484468dvboxsync# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
4c221b0da1816acf2ca302b10092df059484468dvboxsync# License for the specific language governing permissions and limitations
4c221b0da1816acf2ca302b10092df059484468dvboxsync# under the License.
4c221b0da1816acf2ca302b10092df059484468dvboxsyncfrom subprocess import CalledProcessError, check_call, Popen
4c221b0da1816acf2ca302b10092df059484468dvboxsyncXSTARTUPHDR = "# WARNING: THIS FILE GENERATED BY SMF.\n" + \
4c221b0da1816acf2ca302b10092df059484468dvboxsync "# DO NOT EDIT THIS FILE. EDITS WILL BE LOST.\n"
4c221b0da1816acf2ca302b10092df059484468dvboxsyncXRESOURCES = "[[ -f ~/.Xresources ]] && /usr/bin/xrdb -merge ~/.Xresources\n"
4c221b0da1816acf2ca302b10092df059484468dvboxsync# Borderless, Monospsce font, point size 14, white foreground on black
4c221b0da1816acf2ca302b10092df059484468dvboxsync# background are reasonable defaults.
4c221b0da1816acf2ca302b10092df059484468dvboxsyncXTERMOPTS = ' -b 0 -fa Monospace -fs 14 -fg white -bg black -title ' + \
4c221b0da1816acf2ca302b10092df059484468dvboxsync '"Zone Console: $ZONENAME"'
4c221b0da1816acf2ca302b10092df059484468dvboxsync# Enclose command in comments to prevent xterm consuming zlogin opts
4c221b0da1816acf2ca302b10092df059484468dvboxsyncZLOGINOPTS = ' -e "/usr/bin/pfexec /usr/sbin/zlogin -C -E $ZONENAME"\n'
4c221b0da1816acf2ca302b10092df059484468dvboxsyncXSTARTUP = XSTARTUPHDR + XRESOURCES + XTERM + XTERMOPTS + ZLOGINOPTS
4c221b0da1816acf2ca302b10092df059484468dvboxsync # NOTE: 'geometry' below is that which matches the size of standard
4c221b0da1816acf2ca302b10092df059484468dvboxsync # 80 character undecorated xterm window using font style specified in
4c221b0da1816acf2ca302b10092df059484468dvboxsync # XTERMOPTS. The geometry doesn't matter too much because the display
4c221b0da1816acf2ca302b10092df059484468dvboxsync # will be resized using xrandr once the xterm geometry is established.
4c221b0da1816acf2ca302b10092df059484468dvboxsync cmd = [VNCSERVER, "-name", desktop_name, "-SecurityTypes=None",
4c221b0da1816acf2ca302b10092df059484468dvboxsync vnc = Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
4c221b0da1816acf2ca302b10092df059484468dvboxsync if line.startswith("New '%s' desktop is" % desktop_name):
4c221b0da1816acf2ca302b10092df059484468dvboxsync # set host prop
4c221b0da1816acf2ca302b10092df059484468dvboxsync # set port num prop
4c221b0da1816acf2ca302b10092df059484468dvboxsync cmd = [SVCCFG, '-s', fmri, 'setprop', 'vnc/port', '=', 'integer:',
4c221b0da1816acf2ca302b10092df059484468dvboxsync svccfg = subprocess.Popen(cmd, stdout=subprocess.PIPE,
4c221b0da1816acf2ca302b10092df059484468dvboxsync # first kill the SMF contract
4c221b0da1816acf2ca302b10092df059484468dvboxsync # 1 is returncode if no SMF contract processes were matched,
4c221b0da1816acf2ca302b10092df059484468dvboxsync # meaning they have already terminated.
4c221b0da1816acf2ca302b10092df059484468dvboxsync # reset port num prop to initial zero value
4c221b0da1816acf2ca302b10092df059484468dvboxsync cmd = [SVCCFG, '-s', fmri, 'setprop', 'vnc/port', '=', 'integer:',
4c221b0da1816acf2ca302b10092df059484468dvboxsync svccfg = subprocess.Popen(cmd, stdout=subprocess.PIPE,
4c221b0da1816acf2ca302b10092df059484468dvboxsync print "Error resetting 'vnc/port' property: " + err
% VNCSERVER)
% XTERM)
try:
try:
% sleep
% sleep