On Thu, May 07, 2009 at 03:50:13PM +0200, Pritesh Kothari wrote:
Hi All,
I have added support for vrdp/sdl/gui modes for VirtualBox driver in libvirt.
Tha patch's are as below:
[PATCH 1/3]: contains support for vrdp/sdl/gui while defining a machine.
[PATCH 2/3]: contains support for vrdp/sdl/gui while dumping xml
[PATCH 3/3]: contains support for vrdp/sdl/gui while starting the machine
Regards,
Pritesh
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 223009a..97a686f 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -2322,20 +2322,12 @@ static int vboxDomainCreate(virDomainPtr dom) {
IProgress *progress = NULL;
PRUint32 machineCnt = 0;
PRUnichar *env = NULL;
- const char *display = getenv("DISPLAY");
PRUnichar *sessionType = NULL;
char displayutf8[32] = {0};
unsigned char iidl[VIR_UUID_BUFLEN] = {0};
int i, ret = -1;
- if (display) {
- sprintf(displayutf8, "DISPLAY=%s", display);
- data->pFuncs->pfnUtf8ToUtf16(displayutf8, &env);
- }
-
- data->pFuncs->pfnUtf8ToUtf16("gui", &sessionType);
-
if (!dom->name) {
vboxError(dom->conn, VIR_ERR_INTERNAL_ERROR,"%s",
"Error while reading the domain name");
@@ -2373,6 +2365,92 @@ static int vboxDomainCreate(virDomainPtr dom) {
if ( (state == MachineState_PoweredOff) ||
(state == MachineState_Saved) ||
(state == MachineState_Aborted) ) {
+ int vrdpPresent = 0;
+ int sdlPresent = 0;
+ int guiPresent = 0;
+ char *guiDisplay = NULL;
+ char *sdlDisplay = NULL;
+ PRUnichar *keyTypeUtf16 = NULL;
+ PRUnichar *valueTypeUtf16 = NULL;
+ char *valueTypeUtf8 = NULL;
+ PRUnichar *keyDislpayUtf16 = NULL;
+ PRUnichar *valueDisplayUtf16 = NULL;
+ char *valueDisplayUtf8 = NULL;
+ int valueDisplayFree = 1;
+
+ data->pFuncs->pfnUtf8ToUtf16("FRONTEND/Type",
&keyTypeUtf16);
+ machine->vtbl->GetExtraData(machine, keyTypeUtf16,
&valueTypeUtf16);
+ data->pFuncs->pfnUtf16Free(keyTypeUtf16);
+
+ if (valueTypeUtf16) {
+ data->pFuncs->pfnUtf16ToUtf8(valueTypeUtf16,
&valueTypeUtf8);
+ data->pFuncs->pfnUtf16Free(valueTypeUtf16);
+
+ if ( STREQ(valueTypeUtf8, "sdl") ||
STREQ(valueTypeUtf8, "gui") ) {
+
+
data->pFuncs->pfnUtf8ToUtf16("FRONTEND/Display", &keyDislpayUtf16);
+ machine->vtbl->GetExtraData(machine,
keyDislpayUtf16, &valueDisplayUtf16);
+ data->pFuncs->pfnUtf16Free(keyDislpayUtf16);
+
+ if (valueDisplayUtf16) {
+
data->pFuncs->pfnUtf16ToUtf8(valueDisplayUtf16, &valueDisplayUtf8);
+
data->pFuncs->pfnUtf16Free(valueDisplayUtf16);
+
+ if (strlen(valueDisplayUtf8) <= 0) {
+
data->pFuncs->pfnUtf8Free(valueDisplayUtf8);
+ valueDisplayUtf8 = getenv("DISPLAY");
+ valueDisplayFree = 0;
+ }
+ } else {
+ valueDisplayUtf8 = getenv("DISPLAY");
+ valueDisplayFree = 0;
+ }
+
+ if (STREQ(valueTypeUtf8, "sdl")) {
+ sdlPresent = 1;
+ sdlDisplay = strdup(valueDisplayUtf8);
+ }
+
+ if (STREQ(valueTypeUtf8, "gui")) {
+ guiPresent = 1;
+ guiDisplay = strdup(valueDisplayUtf8);
+ }
+ }
+
+ if (STREQ(valueTypeUtf8, "vrdp")) {
+ vrdpPresent = 1;
+ }
+
+ data->pFuncs->pfnUtf8Free(valueTypeUtf8);
+
+ } else {
+ guiPresent = 1;
+ guiDisplay = strdup(getenv("DISPLAY"));
+ }
+ if (valueDisplayFree)
+ data->pFuncs->pfnUtf8Free(valueDisplayUtf8);
+
+ if (guiPresent) {
+ sprintf(displayutf8, "DISPLAY=%.24s",
guiDisplay);
+ data->pFuncs->pfnUtf8ToUtf16(displayutf8, &env);
+
+ data->pFuncs->pfnUtf8ToUtf16("gui",
&sessionType);
+
+ VIR_FREE(guiDisplay);
+ }
+
+ if (sdlPresent) {
+ sprintf(displayutf8, "DISPLAY=%.24s",
sdlDisplay);
+ data->pFuncs->pfnUtf8ToUtf16(displayutf8, &env);
+
+ data->pFuncs->pfnUtf8ToUtf16("sdl",
&sessionType);
+
+ VIR_FREE(sdlDisplay);
+ }
+
+ if (vrdpPresent) {
+ data->pFuncs->pfnUtf8ToUtf16("vrdp",
&sessionType);
+ }
Same issue about use of 'getenv' & strdup OOM handling here.
Regards,
Daniel
--
|: 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 :|