vnc port selection
Quoted 22 lines · Anthony Liguori
Quoted 9 lines · Gerd Hoffmann
Hi folks,
Xen's qemu-dm version has a '-vncunused' command line switch which asks the internal vnc server to pick any unused tcp port to listen on. The actual port is communicated to the outside world via xenstore.
I'm looking for a reasonable way to implement that functionality in upstream qemu. First, I think it shouldn't be a separate command line switch but an option for the existion -vnc switch.
Maybe something like a to=N option. So you would have:
-vnc localhost:0,to=10
That would try from displays 0 to 10 and select the first one it could attach to.
Quoted 4 lines
Second, we need a
way to communicate the port picked which isn't xen-specific. Obvious choice is a monitor info subcommand.
Quoted 16 lines
There's already an info vnc. It can be added to that.
Regards,
Anthony Liguori
Quoted 6 lines
Comments? Other suggestions?
cheers,
Gerd
Hello Gerd,
Even though currently it is a bash+awk solution the algorithm could be of interest for you.
It works on Linux+OpenBSD+Solaris and accepts MIN and MAX value for the port. An aditional seed-value is added for slowly-released ports for immediate access.
I use different ranges particularly in order to distinguish displayforwarding and "clientforwarding".
Thus one range for local vncviewer access by OpenSSH with "-X" option, another for forwarded remote vncviewer access by OpenSSH tunnels with port-forwarding.
The files are available at http:/sourceforge.net/projects/ctys with the directory path: ctys.01_07_001b04/plugins/VNC
Arno
Signature · 5 lines
----------------------------------------------------------------------------
Arno-Can Uestuensoez
www.i4p.de / www.i4p.com########################################################################
#
#PROJECT: Unified Sessions Manager #AUTHOR: Arno-Can Uestuensoez - [email protected] #MAINTAINER: Arno-Can Uestuensoez - [email protected] #SHORT: ctys
#CALLFULLNAME: Commutate To Your Session
#LICENCE: GPL3
#VERSION: 01_06_001a10
#
########################################################################
#
# Copyright (C) 2007 Arno-Can Uestuensoez (UnifiedSessionsManager.org) #
########################################################################
function ptrace(inp){
if(!d){
print line ":" inp | "cat 1>&2"
}
}BEGIN{
ptrace("awk:getFirstFreeVNCPort");
ptrace("min ="min);
ptrace("max ="max);
ptrace("seed="seed);
chk[0]="";
}{
gsub("^[0-9.]*:+","",$4);
}$4>min&&$4<max{
idx=$4-min;
chk[idx]=$4;
}END{
l=max-min;
for(i=0;i<l;i++){
if(chk[i]==""){
if(seed==0){break;}
seed--;
ptrace("skip("seed")="i);
}
}
if(i<max){
ptrace("result="i);
printf("%d",min+i);
}else{
ptrace("result exceeds maximum("max")="i);
}
}
########################################################################
#
#PROJECT: Unified Sessions Manager
#AUTHOR: Arno-Can Uestuensoez - [email protected]
#MAINTAINER: Arno-Can Uestuensoez - [email protected]
#SHORT: ctys#CALLFULLNAME: Commutate To Your Session
#LICENCE: GPL3
#VERSION: 01_06_001a10
#
########################################################################
#
# Copyright (C) 2007 Arno-Can Uestuensoez (UnifiedSessionsManager.org) #
########################################################################
function ptrace(inp){
if(!d){
print line ":" inp | "cat 1>&2"
}
}BEGIN{
ptrace("awk:getFirstFreeVNCPort");
ptrace("min ="min);
ptrace("max ="max);
ptrace("seed="seed);
chk[0]="";
}{
gsub("^[0-9.]*:+","",$4);
}$4>min&&$4<max{
idx=$4-min;
chk[idx]=$4;
}END{
l=max-min;
for(i=0;i<l;i++){
if(chk[i]==""){
if(seed==0){break;}
seed--;
ptrace("skip("seed")="i);
}
}
if(i<max){
ptrace("result="i);
printf("%d",min+i);
}else{
ptrace("result exceeds maximum("max")="i);
}
}
########################################################################
#
#PROJECT: Unified Sessions Manager
#AUTHOR: Arno-Can Uestuensoez - [email protected]
#MAINTAINER: Arno-Can Uestuensoez - [email protected]
#SHORT: ctys#CALLFULLNAME: Commutate To Your Session
#LICENCE: GPL3
#VERSION: 01_06_001a10
#
########################################################################
#
# Copyright (C) 2007 Arno-Can Uestuensoez (UnifiedSessionsManager.org) #
########################################################################
function ptrace(inp){
if(!d){
print line ":" inp | "cat 1>&2"
}
}BEGIN{
ptrace("awk:getFirstFreeVNCPort");
ptrace("min ="min);
ptrace("max ="max);
ptrace("seed="seed);
chk[0]="";
}{
gsub("^[0-9.]*:+","",$4);
}$4>min&&$4<max{
idx=$4-min;
chk[idx]=$4;
}END{
l=max-min;
for(i=0;i<l;i++){
if(chk[i]==""){
if(seed==0){break;}
seed--;
ptrace("skip("seed")="i);
}
}
if(i<max){
ptrace("result="i);
printf("%d",min+i);
}else{
ptrace("result exceeds maximum("max")="i);
}
}#!/bin/bash
########################################################################
#
#PROJECT: Unified Sessions Manager #AUTHOR: Arno-Can Uestuensoez - [email protected] #MAINTAINER: Arno-Can Uestuensoez - [email protected] #SHORT: ctys
#CALLFULLNAME: Commutate To Your Session
#LICENCE: GPL3
#VERSION: 01_03_001b01
#
########################################################################
#
# Copyright (C) 2007 Arno-Can Uestuensoez (UnifiedSessionsManager.org) #
########################################################################
VNC_MAGIC=VNC_GENERIC;
VNC_VERSTRING=;
VNC_STATE=DISABLED;
VNCSERVER_OPT=;
VNCVIEWER_OPT=;
VNC_PREREQ=;
export VNC_BASEPORT=${VNC_BASEPORT:-5900}
_myPKGNAME_VNC="${BASH_SOURCE}"
_myPKGVERS_VNC="01.02.001b01"
hookInfoAdd $_myPKGNAME_VNC $_myPKGVERS_VNC
_myPKGBASE_VNC="${_myPKGNAME_VNC%/hook}"
VNC_VERSTRING=${_myPKGVERS_VNC}; VNC_PREREQ="HOST-CAPABILITY:VNC-${VNC_VERSTRING}-${MYARCH}";
if [ -d "${HOME}/.ctys" -a -d "${HOME}/.ctys/vnc" ];then
if [ -f "${HOME}/.ctys/vnc/vnc.conf.${MYOS}" ];then
. "${HOME}/.ctys/vnc/vnc.conf.${MYOS}"
fifi
if [ -d "${MYCONFPATH}" -a -d "${MYCONFPATH}/vnc" ];then
if [ -f "${MYCONFPATH}/vnc/vnc.conf.${MYOS}" ];then
. "${MYCONFPATH}/vnc/vnc.conf.${MYOS}"
fifi
_waitcVNC=${VNC_INIT_WAITC:-2}
_waitsVNC=${VNC_INIT_WAITS:-2}
#FUNCBEG############################################################### #NAME:
# getFirstFreeVNCPort
#
#TYPE:
# bash-function
#
#DESCRIPTION:
# Gets the first free port above a given base, thus multiple regions # could be managed
#
#EXAMPLE:
#
#PARAMETERS:
# $1: <MIN>
# $2: [<MAX>]
#
#OUTPUT:
# RETURN:
# VALUES:
# <first-port>
# #FUNCEND###############################################################
function getFirstFreeVNCPort () {
printDBG $S_LIB ${D_BULK} $LINENO $BASH_SOURCE "$FUNCNAME:CALL=<${*}>"
local MIN=${1:-$VNC_BASEPORT};
local MAX=$2;
[ -z "$MAX" ]&&let MAX=MIN+1000;
local _seed=$((RANDOM%VNCPORTSEED));
doDebug $S_XEN ${D_MAINT} $LINENO $BASH_SOURCE
local D=$?
printDBG $S_LIB ${D_BULK} $LINENO $BASH_SOURCE "$FUNCNAME:MIN=${MIN} MAX=${MAX} seed=${_seed}"
case ${MYOS} in
Linux)
local localClientAccess=`${CTYS_NETSTAT} -n -l -t|awk -v d="${D}" -v min="${MIN}" -v max="${MAX}" -v seed="${_seed}" -f ${_myPKGBASE_VNC}/getFirstFreeVNCPort.${MYOS}.awk`
;;
OpenBSD)
local localClientAccess=`${CTYS_NETSTAT} -n -l -t|awk -v d="${D}" -v min="${MIN}" -v max="${MAX}" -v seed="${_seed}" -f ${_myPKGBASE_VNC}/getFirstFreeVNCPort.${MYOS}.awk`
;;
SunOS)
local localClientAccess=`${CTYS_NETSTAT} -n -l -t|awk -v d="${D}" -v min="${MIN}" -v max="${MAX}" -v seed="${_seed}" -f ${_myPKGBASE_VNC}/getFirstFreeVNCPort.${MYOS}.awk`
;;
esac
printDBG $S_LIB ${D_BULK} $LINENO $BASH_SOURCE "$FUNCNAME:localClientAccess=<${localClientAccess}>"
echo -n -e "${localClientAccess}";
}#FUNCBEG############################################################### #NAME:
# getFirstFreeVNCDisplay
#
#TYPE:
# bash-function
#
#DESCRIPTION:
# Gets the first free display above a given base, thus multiple regions # could be managed
#
#EXAMPLE:
#
#PARAMETERS:
# $1: <MIN>
# $2: [<MAX>]
#
#OUTPUT:
# RETURN:
# VALUES:
# <first-port>
# #FUNCEND###############################################################
function getFirstFreeVNCDisplay () {
printDBG $S_LIB ${D_BULK} $LINENO $BASH_SOURCE "$FUNCNAME:CALL=<${*}>"
local MIN=${1:-$VNC_BASEPORT};
local MAX=$2;
[ -z "$MAX" ]&&let MAX=VNC_PORT+1000;
printDBG $S_LIB ${D_BULK} $LINENO $BASH_SOURCE "$FUNCNAME:MIN=${MIN} MAX=${MAX}"
local _myPort=`getFirstFreeVNCPort ${@}`
local _myDisplay=$((_myPort-MIN));
printDBG $S_LIB ${D_BULK} $LINENO $BASH_SOURCE "$FUNCNAME:_myPort=<${_myPort}>"
printDBG $S_LIB ${D_BULK} $LINENO $BASH_SOURCE "$FUNCNAME:_myDisplay=<${_myDisplay}>"
echo -n -e "${_myDisplay}";
}#FUNCBEG############################################################### #NAME:
# serverRequireVNC
#
#TYPE:
# bash-function
#
#DESCRIPTION:
# Reports whether a server component has to be called for the current # action.
#
#EXAMPLE:
#
#PARAMETERS:
# $*: ${EXECCALL}|<options-list>
# Generally a string containing an <options-list>, where the # first match is choosen. So only one type option is allowed to # be contained.
#
#OUTPUT:
# RETURN:
# INPUT, where required changes for destination are set.
# VALUES:
# 0: true, required - output is valid.
# 1: false, not required - output is not valid.
# #FUNCEND###############################################################
function serverRequireVNC () {
printDBG $S_VNC ${D_BULK} $LINENO $BASH_SOURCE "$FUNCNAME \$@=$@"
local _ret=1;
local _res=;
local _S=`getSessionType ${*}`;_S=${_S:-$C_SESSIONTYPE};
local _A=`getActionResulting ${*}`;
case $_A in
GETCLIENTPORT)
printDBG $S_VNC ${D_MAINT} $LINENO $BASH_SOURCE "$FUNCNAME:_res=\"${*}\""
printDBG $S_VNC ${D_MAINT} $LINENO $BASH_SOURCE "$FUNCNAME:_ret=\"0\""
echo -n "${*}";
return 0
;;
esac
local _CS_SPLIT=${*};
_CS_SPLIT=${_CS_SPLIT//CONNECTIONFORWARDING/SERVERONLY}
_CS_SPLIT=${_CS_SPLIT//*LOCALONLY*/}
_CS_SPLIT=${_CS_SPLIT//*CLIENTONLY*/}
if [ -n "${_CS_SPLIT}" ];then
_res="${_CS_SPLIT}";_ret=0;
fi
printDBG $S_VNC ${D_MAINT} $LINENO $BASH_SOURCE "_CS_SPLIT=\"${_CS_SPLIT}\""
printDBG $S_VNC ${D_MAINT} $LINENO $BASH_SOURCE "_S=\"${_S}\""
printDBG $S_VNC ${D_MAINT} $LINENO $BASH_SOURCE "_A=\"${_A}\""
printDBG $S_VNC ${D_MAINT} $LINENO $BASH_SOURCE "$FUNCNAME:_res=\"${_res}\""
printDBG $S_VNC ${D_MAINT} $LINENO $BASH_SOURCE "$FUNCNAME:_ret=\"${_ret}\""
echo -n "${_res}";
return ${_ret};
}#FUNCBEG############################################################### #NAME:
# clientRequireVNC
#
#TYPE:
# bash-function
#
#DESCRIPTION:
# Reports whether a client component has to be called for the current # action.
#
#EXAMPLE:
#
#PARAMETERS:
# $*: ${EXECCALL}|<options-list>
# Generally a string containing an <options-list>, where the # first match is choosen. So only one type option is allowed to # be contained.
#
#OUTPUT:
# RETURN:
# INPUT, where required changes for destination are set.
# VALUES:
# 0: true, required - output is valid.
# 1: false, not required - output is not valid.
# #FUNCEND###############################################################
function clientRequireVNC () {
printDBG $S_VNC ${D_BULK} $LINENO $BASH_SOURCE "$FUNCNAME \$@=$@"
local _ret=1;
local _res=;
local _A=`getActionResulting ${*}`;
local _S=`getSessionType ${*}`;_S=${_S:-$C_SESSIONTYPE};
local _CS_SPLIT=${*};
_CS_SPLIT=${_CS_SPLIT//*DISPLAYFORWARDING*/}
_CS_SPLIT=${_CS_SPLIT//*SERVERONLY*/}
if [ "${_CS_SPLIT}" == "${*}" ];then
_res="${_CS_SPLIT}";_ret=0;
fi
printDBG $S_VNC ${D_MAINT} $LINENO $BASH_SOURCE "_CS_SPLIT=\"${_CS_SPLIT}\""
printDBG $S_VNC ${D_MAINT} $LINENO $BASH_SOURCE "_S=\"${_S}\""
printDBG $S_VNC ${D_MAINT} $LINENO $BASH_SOURCE "_A=\"${_A}\""
printDBG $S_VNC ${D_MAINT} $LINENO $BASH_SOURCE "$FUNCNAME:_res=\"${_res}\""
printDBG $S_VNC ${D_MAINT} $LINENO $BASH_SOURCE "$FUNCNAME:_ret=\"${_ret}\""
echo -n "${_res}";
return ${_ret};
}#FUNCBEG############################################################### #NAME:
# setVersionVNC
#
#TYPE:
# bash-function
#
#DESCRIPTION:
# Sets defaults and MAGIC-ID for local vmware version.
#
#EXAMPLE:
#
#PARAMETERS:
#
#
#OUTPUT:
# GLOBALS:
# VNC_MAGIC: {VNC_REAL412|VNC_TIGHT129|...}
# Value to be checked.
#
# VMW_DEFAULTOPTS
# Appropriate defaults.
#
# -RealVNC - 4.1.2
# -TightVNC - 1.2.9
#
# RETURN:
#
# VALUES:
# #FUNCEND###############################################################
function setVersionVNC () {
local _checkonly=;
local _ret=0;
if [ "$1" == "NOEXIT" ];then
local _checkonly=1;
fi
local _verstrg=;
if [ -z "${VNCSEXE}" ];then
ABORT=2;
printERR $LINENO $BASH_SOURCE ${ABORT} "Missing executable for VNCserver"
printERR $LINENO $BASH_SOURCE ${ABORT} "can not find:"
printERR $LINENO $BASH_SOURCE ${ABORT} " -> vncserv"
printERR $LINENO $BASH_SOURCE ${ABORT} ""
printERR $LINENO $BASH_SOURCE ${ABORT} "Check your PATH"
printERR $LINENO $BASH_SOURCE ${ABORT} " -> PATH=${PATH}"
printERR $LINENO $BASH_SOURCE ${ABORT} ""
if [ "${C_SESSIONTYPE}" == "VNC" -a -z "${_checkonly}" ];then
gotoHell ${ABORT}
else
return ${ABORT}
fi
_ret=${ABORT};
else
local _vsexe=`${VNCSEXE} --help 2>&1|egrep '(Usage:|usage:)'`
ABORT=2;
if [ -n "$_vsexe" ];then
printDBG $S_LIB ${D_SYS} $LINENO "$BASH_SOURCE" "$FUNCNAME:`setSeverityColor TRY \"call(${VNCSEXE} --help)\"` => [ `setSeverityColor INF OK` ]"
_ret=0;
else
printDBG $S_LIB ${D_SYS} $LINENO "$BASH_SOURCE" "$FUNCNAME:`setSeverityColor TRY \"call(${VNCSEXE} --help)\"` => [ `setSeverityColor ERR NOK` ]"
_ret=${ABORT};
fi
fi
if [ -z "${VNCVEXE}" ];then
ABORT=2
printERR $LINENO $BASH_SOURCE ${ABORT} "Missing executable for VNCviewer"
printERR $LINENO $BASH_SOURCE ${ABORT} "can not find:"
printERR $LINENO $BASH_SOURCE ${ABORT} " -> vncviewer"
printERR $LINENO $BASH_SOURCE ${ABORT} ""
printERR $LINENO $BASH_SOURCE ${ABORT} "Check your PATH"
printERR $LINENO $BASH_SOURCE ${ABORT} " -> PATH=${PATH}"
printERR $LINENO $BASH_SOURCE ${ABORT} ""
if [ "${C_SESSIONTYPE}" == "VNC" -a -z "${_checkonly}" ];then
gotoHell ${ABORT}
else
return ${ABORT}
fi
_ret=${ABORT};
fi
if [ -n "`${VNCVEXE} --help 2>&1|egrep '(RealVNC)'`" ];then
# _verstrg=`${VNCVEXE} --help 2>&1|awk '/VNC [Vv]iewer/{printf("%s\n",$5);}'`
_verstrg=`${VNCVEXE} --help 2>&1|sed -n 's/VNC [Vv]iewer[^0-9]*\([0-9]*.[0-9]*.[0-9]*\).*/\1/p'`
ABORT=2;
if [ -n "$_verstrg" ];then
_verstrg="RealVNC-${_verstrg}"
printDBG $S_LIB ${D_SYS} $LINENO "$BASH_SOURCE" "$FUNCNAME:`setSeverityColor TRY \"call(${VNCVEXE} -version)\"` => [ `setSeverityColor INF OK` ]"
_ret=0;
else
printDBG $S_LIB ${D_SYS} $LINENO "$BASH_SOURCE" "$FUNCNAME:`setSeverityColor TRY \"call(${VNCVEXE} --version)\"` => [ `setSeverityColor ERR NOK` ]"
_ret=${ABORT};
fi
else
if [ -n "`${VNCVEXE} --help 2>&1|egrep '(TightVNC)'`" ];then
_verstrg=`${VNCVEXE} --help 2>&1|awk -v a=${_allign} '/[vV]iewer [vV]ersion/{printf("%s\n",$4);}'`
ABORT=2;
if [ -n "$_verstrg" ];then
_verstrg="TightVNC-${_verstrg}"
printDBG $S_LIB ${D_SYS} $LINENO "$BASH_SOURCE" "$FUNCNAME:`setSeverityColor TRY \"call(${VNCVEXE} -version)\"` => [ `setSeverityColor INF OK` ]"
_ret=0;
else
printDBG $S_LIB ${D_SYS} $LINENO "$BASH_SOURCE" "$FUNCNAME:`setSeverityColor TRY \"call(${VNCVEXE} --version)\"` => [ `setSeverityColor ERR NOK` ]"
_ret=${ABORT};
fi
else
if [ -n "`${VNCVEXE} --help 2>&1|egrep '(open display:)'`" ];then
printWNG 1 $LINENO $BASH_SOURCE 0 "DISPLAY is not available"
printWNG 1 $LINENO $BASH_SOURCE 0 " 1. One common cause is the call of \"ssh\" without the \"-X\""
printWNG 1 $LINENO $BASH_SOURCE 0 " option. Even for the utilized check by \"vncviewer --help\" "
printWNG 1 $LINENO $BASH_SOURCE 0 " option a display is required."
_verstrg=GENERIC
_ret=0;
else
printWNG 1 $LINENO $BASH_SOURCE 0 "Can not evaluate version for \"which-ed\" vncviewer."
printWNG 1 $LINENO $BASH_SOURCE 0 "."
printWNG 1 $LINENO $BASH_SOURCE 0 " 1. One common cause is the call of \"ssh\" without the \"-X\""
printWNG 1 $LINENO $BASH_SOURCE 0 " option. Even for the utilized check by \"vncviewer --help\" "
printWNG 1 $LINENO $BASH_SOURCE 0 " option a display is required."
printWNG 1 $LINENO $BASH_SOURCE 0 " 2. Another common cause for the initial usage is the missing "
printWNG 1 $LINENO $BASH_SOURCE 0 " permission \"X11Forwarding yes\" in \"/etc/ssh/sshd_conf\"."
_verstrg=GENERIC
_ret=0;
fi
fi
fi
printDBG $S_VNC ${D_BULK} $LINENO $BASH_SOURCE "VNC"
printDBG $S_VNC ${D_BULK} $LINENO $BASH_SOURCE " _verstrg=${_verstrg}"
#currently somewhat restrictive to specific versions.
case ${_verstrg} in
"TightVNC"*)
VNC_MAGIC=VNCT;
VNC_STATE=ENABLED;
VNC_PREREQ="${VNC_PREREQ}%${_verstrg}-${MYARCH} vncserver,vncviewer";
VNCSERVER_OPT="${VNCSERVER_OPT_TightVNC}";
VNCVIEWER_OPT="${VNCVIEWER_OPT_TightVNC}";
_ret=0;
;;
"RealVNC"*)
VNC_MAGIC=VNCR;
VNC_STATE=ENABLED;
VNC_PREREQ="${VNC_PREREQ}%${_verstrg}-${MYARCH} vncserver,vncviewer";
VNCSERVER_OPT="${VNCSERVER_OPT_RealVNC}";
VNCVIEWER_OPT="${VNCVIEWER_OPT_RealVNC}";
_ret=0;
;;
*)
VNC_MAGIC=VNCG;
VNCSERVER_OPT="${VNCSERVER_OPT_GENERIC}";
VNCVIEWER_OPT="${VNCVIEWER_OPT_GENERIC}";
VNC_PREREQ="${VNC_PREREQ}%${_verstrg}-${MYARCH}";
_ret=2;
;;
esac
printDBG $S_VNC ${D_BULK} $LINENO $BASH_SOURCE "VNC_MAGIC = ${VNC_MAGIC}"
printDBG $S_VNC ${D_BULK} $LINENO $BASH_SOURCE "VNC_VERSTRING = ${VNC_VERSTRING}"
printDBG $S_VNC ${D_BULK} $LINENO $BASH_SOURCE "VNC_STATE = ${VNC_STATE}"
printDBG $S_VNC ${D_BULK} $LINENO $BASH_SOURCE "VNC_PREREQ = ${VNC_PREREQ}"
printDBG $S_VNC ${D_BULK} $LINENO $BASH_SOURCE "VNCSERVER_OPT = ${VNCSERVER_OPT}"
printDBG $S_VNC ${D_BULK} $LINENO $BASH_SOURCE "VNCVIEWER_OPT = ${VNCVIEWER_OPT}"
return $_ret;
}#FUNCBEG############################################################### #NAME:
# noClientServerSplitSupportedMessageVNC
#
#TYPE:
# bash-function
#
#DESCRIPTION:
#
#EXAMPLE:
#
#PARAMETERS:
#
#OUTPUT:
# RETURN:
# VALUES:
# #FUNCEND###############################################################
function noClientServerSplitSupportedMessageVNC () {
ABORT=2
printERR $LINENO $BASH_SOURCE ${ABORT} "Unexpected ERROR!!!"
printERR $LINENO $BASH_SOURCE ${ABORT} "VNC perfectly supports ClientServerSplit!!!"
printERR $LINENO $BASH_SOURCE ${ABORT} "Check for process ownership, probably just missing permissions."
printERR $LINENO $BASH_SOURCE ${ABORT} "On grave slow machines just a timeout may have occured."
printERR $LINENO $BASH_SOURCE ${ABORT} "Try a following connect, if so adapt TIMEOUT value, but for this target only."
}#FUNCBEG############################################################### #NAME:
# clientServerSplitSupportedVNC
#
#TYPE:
# bash-function
#
#DESCRIPTION:
# Checks whether the split of client and server is supported. # This is just a hardcoded attribute.
#
#EXAMPLE:
#
#PARAMETERS:
#
#OUTPUT:
# RETURN:
# 0: If supported
# 1: else
#
# VALUES:
# #FUNCEND###############################################################
function clientServerSplitSupportedVNC () {
printDBG $S_VNC ${D_BULK} $LINENO $BASH_SOURCE "$FUNCNAME $1"
case $1 in
CREATE)return 0;;
CANCEL)return 0;;
esac
return 1;
}#FUNCBEG############################################################### #NAME:
# enumerateMySessionsVNC
#
#TYPE:
# bash-function
#
#DESCRIPTION:
# Not supported.
#
#EXAMPLE:
#
#PARAMETERS:
#
#OUTPUT:
# RETURN:
# VALUES:
# #FUNCEND###############################################################
function enumerateMySessionsVNC () {
printDBG $S_VNC ${D_BULK} $LINENO $BASH_SOURCE "$FUNCNAME:\$@=${@}"
}#
#Managed load of sub-packages gwhich are required in almost any case. #On-demand-loads will be performed within requesting action. #
hookPackage "${_myPKGBASE_VNC}/session"
hookPackage "${_myPKGBASE_VNC}/list"
hookPackage "${_myPKGBASE_VNC}/info"
if [ -d "${HOME}/.ctys" -a -d "${HOME}/.ctys/vnc" ];then
#Source pre-set environment from user
if [ -f "${HOME}/.ctys/vnc/vnc.conf" ];then
. "${HOME}/.ctys/vnc/vnc.conf"
fi
#Source pre-set environment from installation
if [ -f "${MYCONFPATH}/vnc/vnc/cli.conf" ];then
. "${MYCONFPATH}/conf/vnc/vnc.conf"
fifi
#FUNCBEG############################################################### #NAME:
# handleVNC
#
#TYPE:
# bash-function
#
#DESCRIPTION:
#
#EXAMPLE:
#
#PARAMETERS:
# $1: <OPMODE>
# $2: <ACTION>
#
#OUTPUT:
# RETURN:
#
# VALUES:
# #FUNCEND############################################################### function handleVNC () {
printDBG $S_VNC ${D_BULK} $LINENO $BASH_SOURCE "${FUNCNAME}:$*" local OPMODE=$1;shift
local ACTION=$1;shift
case ${ACTION} in CREATE)
case ${OPMODE} in
PROLOGUE)
;;
EPILOGUE)
;;
CHECKPARAM|ASSEMBLE|EXECUTE)
hookPackage "${_myPKGBASE_VNC}/create"
createConnectVNC ${OPMODE} ${ACTION}
;;
esac
;;
CANCEL)
case ${OPMODE} in
PROLOGUE)
;;
EPILOGUE)
;;
CHECKPARAM|ASSEMBLE|EXECUTE)
hookPackage "${_myPKGBASE_VNC}/cancel"
cutCancelSessionVNC ${OPMODE} ${ACTION}
;;
esac
;;
GETCLIENTPORT)
case ${OPMODE} in
PROLOGUE)
;;
EPILOGUE)
;;
CHECKPARAM)
if [ -n "$C_MODE_ARGS" ];then
printDBG $S_VNC ${D_BULK} $LINENO $BASH_SOURCE "C_MODE_ARGS=$C_MODE_ARGS"
_C_GETCLIENTPORT=$C_MODE_ARGS
else
ABORT=1
printERR $LINENO $BASH_SOURCE ${ABORT} "Missing <session-label>|<session-id>"
gotoHell ${ABORT}
fi
;;
EXECUTE)
printDBG $S_VNC ${D_BULK} $LINENO $BASH_SOURCE "Remote command:C_MODE_ARGS=${C_MODE_ARGS}"
printDBG $S_VNC ${D_BULK} $LINENO $BASH_SOURCE "CLIENTPORT(VNC,${MYHOST},${_C_GETCLIENTPORT})=`getClientTPVNC ${_C_GETCLIENTPORT}`"
echo "CLIENTPORT(VNC,${MYHOST},${_C_GETCLIENTPORT})=`getClientTPVNC ${_C_GETCLIENTPORT}`"
gotoHell 0
;;
ASSEMBLE)
;;
esac
;;
*)
#SUSPEND|RESUME|RESET
ABORT=1;
printERR $LINENO $BASH_SOURCE ${ABORT} "System Error, unsupported ACTION for VNC:ACTION=${ACTION} OPMODE=${OPMODE}"
;;esac
}
#FUNCBEG############################################################### #NAME:
# initVNC
#
#TYPE:
# bash-function
#
#DESCRIPTION:
#
#EXAMPLE:
#
#PARAMETERS:
#
#OUTPUT:
# RETURN:
#
# VALUES:
# #FUNCEND############################################################### function initVNC () {
local _curInit=$1;shift
local _initConsequences=$1
local ret=0;
local _raise=$((INITSTATE<_curInit));
printDBG $S_VNC ${D_MAINT} $LINENO $BASH_SOURCE "$FUNCNAME:${INITSTATE} -> ${_curInit} - ${_raise}"if [ "$_raise" == "1" ];then
#for raise of INITSTATE do not touch the OS's decisions, just expand.
case $_curInit in
0);;#NOP - Done by shell
1) #add own help to searchlist for options
MYOPTSFILES="${MYOPTSFILES} ${MYHELPPATH}/010_vnc"
setVersionVNC $_initConsequences
ret=$?
;;
2);;
3);;
4);;
5);;
6);;
esac else
case $_curInit in
*);;
esac
fi
return $ret
}
Hi folks,
Xen's qemu-dm version has a '-vncunused' command line switch which asks the internal vnc server to pick any unused tcp port to listen on. The actual port is communicated to the outside world via xenstore.
I'm looking for a reasonable way to implement that functionality in upstream qemu. First, I think it shouldn't be a separate command line switch but an option for the existion -vnc switch. Second, we need a way to communicate the port picked which isn't xen-specific. Obvious choice is a monitor info subcommand.
Comments? Other suggestions?
cheers,
Gerd
Signature · 1 line
http://kraxel.fedorapeople.org/xenner/
Quoted 9 lines · Gerd Hoffmann
Hi folks,
Xen's qemu-dm version has a '-vncunused' command line switch which asks the internal vnc server to pick any unused tcp port to listen on. The actual port is communicated to the outside world via xenstore.
I'm looking for a reasonable way to implement that functionality in upstream qemu. First, I think it shouldn't be a separate command line switch but an option for the existion -vnc switch.
Maybe something like a to=N option. So you would have:
-vnc localhost:0,to=10
That would try from displays 0 to 10 and select the first one it could attach to.
Quoted 4 lines
Second, we need a
way to communicate the port picked which isn't xen-specific. Obvious choice is a monitor info subcommand.
There's already an info vnc. It can be added to that.
Regards,
Anthony Liguori
Quoted 6 lines
Comments? Other suggestions?
cheers,
Gerd
Quoted 6 lines · Gerd Hoffmann
Hi folks,
Xen's qemu-dm version has a '-vncunused' command line switch which asks the internal vnc server to pick any unused tcp port to listen on. The actual port is communicated to the outside world via xenstore.
Quoted 9 lines
I'm looking for a reasonable way to implement that functionality in upstream qemu. First, I think it shouldn't be a separate command line switch but an option for the existion -vnc switch. Second, we need a way to communicate the port picked which isn't xen-specific. Obvious choice is a monitor info subcommand.
Comments? Other suggestions?
Presumably -vncunused is passed by the management application, which knows about all domains. Can't it figure out an unused port and pass it on?
Alternatively, have the management application pass an fd denoting the socket.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Quoted 13 lines · Avi Kivity
Quoted 12 lines · Gerd Hoffmann
Hi folks,
Xen's qemu-dm version has a '-vncunused' command line switch which asks the internal vnc server to pick any unused tcp port to listen on. The actual port is communicated to the outside world via xenstore.
I'm looking for a reasonable way to implement that functionality in upstream qemu. First, I think it shouldn't be a separate command line switch but an option for the existion -vnc switch. Second, we need a way to communicate the port picked which isn't xen-specific. Obvious choice is a monitor info subcommand.
Quoted 5 lines
Quoted 3 lines
Comments? Other suggestions?
Presumably -vncunused is passed by the management application, which knows about all domains. Can't it figure out an unused port and pass it on?
An argument for this sort of semantics is that if you just launch vncserver with no argument, it'll sit on the first unused port. So people are sort of used to this behavior.
Quoted 1 line
Alternatively, have the management application pass an fd denoting the socket.
If you are allocating the ports in the management tool, then just tell QEMU what port to open up. I don't think you gain anything passing an fd.
Regards,
Anthony Liguori
Quoted 13 lines · Avi Kivity
Quoted 12 lines · Gerd Hoffmann
Hi folks,
Xen's qemu-dm version has a '-vncunused' command line switch which asks the internal vnc server to pick any unused tcp port to listen on. The actual port is communicated to the outside world via xenstore.
I'm looking for a reasonable way to implement that functionality in upstream qemu. First, I think it shouldn't be a separate command line switch but an option for the existion -vnc switch. Second, we need a way to communicate the port picked which isn't xen-specific. Obvious choice is a monitor info subcommand.
Quoted 7 lines
Quoted 3 lines
Comments? Other suggestions?
Presumably -vncunused is passed by the management application, which knows about all domains. Can't it figure out an unused port and pass it on?
Yes & no. Yes, we do this in libvirt, but it open a race condition unless you pass the actual file descriptor to QEMU. In addition when we add IPv6 support to QEMU, you will actally have multiple sockets you need to listen on. It will make it far easier if we just do the right thing in QEMU, based on a command line flag.
Daniel
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Quoted 26 lines · Anthony Liguori
Quoted 13 lines · Avi Kivity
Quoted 12 lines · Gerd Hoffmann
Hi folks,
Xen's qemu-dm version has a '-vncunused' command line switch which asks the internal vnc server to pick any unused tcp port to listen on. The actual port is communicated to the outside world via xenstore.
I'm looking for a reasonable way to implement that functionality in upstream qemu. First, I think it shouldn't be a separate command line switch but an option for the existion -vnc switch. Second, we need a way to communicate the port picked which isn't xen-specific. Obvious choice is a monitor info subcommand.
Quoted 7 lines
Quoted 3 lines
Comments? Other suggestions?
Presumably -vncunused is passed by the management application, which knows about all domains. Can't it figure out an unused port and pass it on?
An argument for this sort of semantics is that if you just launch vncserver with no argument, it'll sit on the first unused port. So people are sort of used to this behavior.
Quoted 5 lines
Quoted 2 lines
Alternatively, have the management application pass an fd denoting the socket.
If you are allocating the ports in the management tool, then just tell QEMU what port to open up. I don't think you gain anything passing an fd.
And it as I mentioned it'll make adding IPv6 support harder.
Daniel
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Quoted 5 lines · Anthony Liguori
Quoted 2 lines
Alternatively, have the management application pass an fd denoting the socket.
If you are allocating the ports in the management tool, then just tell QEMU what port to open up. I don't think you gain anything passing an fd.
It prevents races, allows listening on non-traditional sockets (vnc over unix-domain), and allows privilege separation.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 5 lines · Avi Kivity
Quoted 4 lines · Anthony Liguori
Quoted 3 lines
Alternatively, have the management application pass an fd denoting the socket.
Quoted 7 lines
Quoted 4 lines
If you are allocating the ports in the management tool, then just tell QEMU what port to open up. I don't think you gain anything passing an fd.
It prevents races, allows listening on non-traditional sockets (vnc over unix-domain), and allows privilege separation.
Agreed: races are particularly irksome.
I have the same problem in another application, where one program allocates a fee port, but another (SSH tunnel) opens it. It's very annoying that the second program fails from time to time, due to the race.
-- Jamie
Anthony Liguori writes ("[Xen-devel] Re: [Qemu-devel] vnc port selection"):
Quoted 8 lines
Quoted 3 lines · Avi Kivity
Presumably -vncunused is passed by the management application, which knows about all domains. Can't it figure out an unused port and pass it on?
An argument for this sort of semantics is that if you just launch vncserver with no argument, it'll sit on the first unused port. So people are sort of used to this behavior.
Exactly. So that's why we need both the ability to do this, and the ability to find out what port was eventually used.
Quoted 5 lines
Quoted 2 lines
Alternatively, have the management application pass an fd denoting the socket.
If you are allocating the ports in the management tool, then just tell QEMU what port to open up. I don't think you gain anything passing an fd.
That has a race, because you commit to the port before having prevented another application from grabbing it. I think the `pick unused port' option is more sensible.
Ian.