[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH 3/3] Support for vrdp/sdl/gui while starting the machine



>
> Same issue about use of 'getenv' & strdup OOM handling here.
>

Fixed these two and reposting the patch.

Regards,
Pritesh
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 85a336a..274afd8 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -2343,20 +2343,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");
@@ -2394,6 +2386,106 @@ 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;
+
+                        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 = NULL;
+                                    }
+                                }
+
+                                if (STREQ(valueTypeUtf8, "sdl")) {
+                                    sdlPresent = 1;
+                                    if (valueDisplayUtf8) {
+                                        sdlDisplay = strdup(valueDisplayUtf8);
+                                        if (sdlDisplay == NULL) {
+                                            vboxError(dom->conn, VIR_ERR_SYSTEM_ERROR, "%s", "strdup failed");
+                                            /* just don't go to cleanup yet as it is ok to have
+                                             * sdlDisplay as NULL and we check it below if it
+                                             * exist and then only use it there
+                                             */
+                                        }
+                                    }
+                                }
+
+                                if (STREQ(valueTypeUtf8, "gui")) {
+                                    guiPresent = 1;
+                                    if (valueDisplayUtf8) {
+                                        guiDisplay = strdup(valueDisplayUtf8);
+                                        if (guiDisplay == NULL) {
+                                            vboxError(dom->conn, VIR_ERR_SYSTEM_ERROR, "%s", "strdup failed");
+                                            /* just don't go to cleanup yet as it is ok to have
+                                             * guiDisplay as NULL and we check it below if it
+                                             * exist and then only use it there
+                                             */
+                                        }
+                                    }
+                                }
+                            }
+
+                            if (STREQ(valueTypeUtf8, "vrdp")) {
+                                vrdpPresent = 1;
+                            }
+
+                            data->pFuncs->pfnUtf8Free(valueTypeUtf8);
+
+                        } else {
+                            guiPresent = 1;
+                        }
+                        if (valueDisplayUtf8)
+                            data->pFuncs->pfnUtf8Free(valueDisplayUtf8);
+
+                        if (guiPresent) {
+                            if (guiDisplay) {
+                                sprintf(displayutf8, "DISPLAY=%.24s", guiDisplay);
+                                data->pFuncs->pfnUtf8ToUtf16(displayutf8, &env);
+                                VIR_FREE(guiDisplay);
+                            }
+
+                            data->pFuncs->pfnUtf8ToUtf16("gui", &sessionType);
+                        }
+
+                        if (sdlPresent) {
+                            if (sdlDisplay) {
+                                sprintf(displayutf8, "DISPLAY=%.24s", sdlDisplay);
+                                data->pFuncs->pfnUtf8ToUtf16(displayutf8, &env);
+                                VIR_FREE(sdlDisplay);
+                            }
+
+                            data->pFuncs->pfnUtf8ToUtf16("sdl", &sessionType);
+                        }
+
+                        if (vrdpPresent) {
+                            data->pFuncs->pfnUtf8ToUtf16("vrdp", &sessionType);
+                        }
 
                         data->vboxObj->vtbl->OpenRemoteSession(data->vboxObj,
                                                                data->vboxSession,

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]