VirtualBox

Changeset 25942 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Jan 20, 2010 5:26:22 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
56784
Message:

*: RTEnv usage cleanup - avoid RTEnvGet() as it doesn't necessarily return UTF-8 encoded strings.

Location:
trunk/src/VBox/Main
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/HostImpl.cpp

    r25860 r25942  
    430430        // So use a fallback approach similar to Linux.
    431431        {
    432             if (RTEnvGet("VBOX_CDROM"))
     432            if (RTEnvExistEx(RTENV_DEFAULT, "VBOX_CDROM"))
    433433            {
    434                 char *cdromEnv = strdup(RTEnvGet("VBOX_CDROM"));
     434                char *cdromEnv = RTEnvDupEx(RTENV_DEFAULT, "VBOX_CDROM");
    435435                char *saveStr = NULL;
    436436                char *cdromDrive = NULL;
     
    448448                    cdromDrive = strtok_r(NULL, ":", &saveStr);
    449449                }
    450                 free(cdromEnv);
     450                RTStrFree(cdromEnv);
    451451            }
    452452            else
  • trunk/src/VBox/Main/freebsd/HostHardwareFreeBSD.cpp

    r25728 r25942  
    341341    int rc = VINF_SUCCESS;
    342342    bool success = false;
     343    char *pszFreeMe = RTEnvDupEx(RTENV_DEFAULT, pcszVar);
    343344
    344345    try
    345346    {
    346         const char *pcszCurrent = RTEnvGet (pcszVar);
     347        const char *pcszCurrent = pszFreeMe;
    347348        while (pcszCurrent && *pcszCurrent != '\0')
    348349        {
     
    357358            if (RT_SUCCESS(RTPathReal(szPath, szReal, sizeof(szReal))))
    358359            {
     360                szUdi[0] = '\0'; /** @todo r=bird: missing a call to devValidateDevice() here and szUdi wasn't
     361                                  *        initialized because of that.  Need proper fixing. */
    359362                pList->push_back(DriveInfo(szReal, szUdi, szDesc));
    360363                success = true;
     
    369372        rc = VERR_NO_MEMORY;
    370373    }
    371     LogFlowFunc (("rc=%Rrc, success=%d\n", rc, success));
     374    RTStrFree(pszFreeMe);
     375    LogFlowFunc(("rc=%Rrc, success=%d\n", rc, success));
    372376    return rc;
    373377}
  • trunk/src/VBox/Main/glue/com.cpp

    r22708 r25942  
    138138}
    139139
    140 int GetVBoxUserHomeDirectory (char *aDir, size_t aDirLen)
     140int GetVBoxUserHomeDirectory(char *aDir, size_t aDirLen)
    141141{
    142142    AssertReturn(aDir, VERR_INVALID_POINTER);
     
    146146    *aDir = 0;
    147147
    148     const char *VBoxUserHome = RTEnvGet ("VBOX_USER_HOME");
     148    const char *VBoxUserHome = RTEnvGet("VBOX_USER_HOME");
    149149
    150150    char path [RTPATH_MAX];
     
    155155        /* get the full path name */
    156156        char *VBoxUserHomeUtf8 = NULL;
    157         vrc = RTStrCurrentCPToUtf8 (&VBoxUserHomeUtf8, VBoxUserHome);
     157        vrc = RTStrCurrentCPToUtf8(&VBoxUserHomeUtf8, VBoxUserHome);
    158158        if (RT_SUCCESS(vrc))
    159159        {
    160             vrc = RTPathAbs (VBoxUserHomeUtf8, path, sizeof (path));
     160            vrc = RTPathAbs(VBoxUserHomeUtf8, path, sizeof (path));
    161161            if (RT_SUCCESS(vrc))
    162162            {
    163                 if (aDirLen < strlen (path) + 1)
     163                if (aDirLen < strlen(path) + 1)
    164164                    vrc = VERR_BUFFER_OVERFLOW;
    165165                else
    166                     strcpy (aDir, path);
     166                    strcpy(aDir, path);
    167167            }
    168             RTStrFree (VBoxUserHomeUtf8);
     168            RTStrFree(VBoxUserHomeUtf8);
    169169        }
    170170    }
     
    172172    {
    173173        /* compose the config directory (full path) */
    174         vrc = RTPathUserHome (path, sizeof (path));
     174        vrc = RTPathUserHome(path, sizeof(path));
    175175        if (RT_SUCCESS(vrc))
    176176        {
    177             size_t len =
    178                 RTStrPrintf (aDir, aDirLen, "%s%c%s",
    179                              path, RTPATH_DELIMITER, VBOX_USER_HOME_SUFFIX);
    180             if (len != strlen (path) + 1 + strlen (VBOX_USER_HOME_SUFFIX))
     177            size_t len = RTStrPrintf(aDir, aDirLen, "%s%c%s",
     178                                     path, RTPATH_DELIMITER, VBOX_USER_HOME_SUFFIX);
     179            if (len != strlen(path) + 1 + strlen (VBOX_USER_HOME_SUFFIX))
    181180                vrc = VERR_BUFFER_OVERFLOW;
    182181        }
     
    185184    /* ensure the home directory exists */
    186185    if (RT_SUCCESS(vrc))
    187         if (!RTDirExists (aDir))
    188             vrc = RTDirCreateFullPath (aDir, 0777);
     186        if (!RTDirExists(aDir))
     187            vrc = RTDirCreateFullPath(aDir, 0777);
    189188
    190189    return vrc;
  • trunk/src/VBox/Main/glue/initterm.cpp

    r25813 r25942  
    66
    77/*
    8  * Copyright (C) 2006-2007 Sun Microsystems, Inc.
     8 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121 */
    2222
    23 #if !defined (VBOX_WITH_XPCOM)
    24 
    25 #include <objbase.h>
     23#if !defined(VBOX_WITH_XPCOM)
     24
     25# include <objbase.h>
    2626
    2727#else /* !defined (VBOX_WITH_XPCOM) */
    2828
    29 #include <stdlib.h>
    30 
    31 /* XPCOM_GLUE is defined when the client uses the standalone glue
    32  * (i.e. dynamically picks up the existing XPCOM shared library installation).
    33  * This is not the case for VirtualBox XPCOM clients (they are always
    34  * distrubuted with the self-built XPCOM library, and therefore have a binary
    35  * dependency on it) but left here for clarity.
    36  */
    37 #if defined (XPCOM_GLUE)
    38 #include <nsXPCOMGlue.h>
    39 #endif
    40 
    41 #include <nsIComponentRegistrar.h>
    42 #include <nsIServiceManager.h>
    43 #include <nsCOMPtr.h>
    44 #include <nsEventQueueUtils.h>
    45 #include <nsEmbedString.h>
    46 
    47 #include <nsILocalFile.h>
    48 #include <nsIDirectoryService.h>
    49 #include <nsDirectoryServiceDefs.h>
    50 
    51 #endif /* !defined (VBOX_WITH_XPCOM) */
     29# include <stdlib.h>
     30
     31  /* XPCOM_GLUE is defined when the client uses the standalone glue
     32   * (i.e. dynamically picks up the existing XPCOM shared library installation).
     33   * This is not the case for VirtualBox XPCOM clients (they are always
     34   * distrubuted with the self-built XPCOM library, and therefore have a binary
     35   * dependency on it) but left here for clarity.
     36   */
     37# if defined(XPCOM_GLUE)
     38#  include <nsXPCOMGlue.h>
     39# endif
     40
     41# include <nsIComponentRegistrar.h>
     42# include <nsIServiceManager.h>
     43# include <nsCOMPtr.h>
     44# include <nsEventQueueUtils.h>
     45# include <nsEmbedString.h>
     46
     47# include <nsILocalFile.h>
     48# include <nsIDirectoryService.h>
     49# include <nsDirectoryServiceDefs.h>
     50
     51#endif /* !defined(VBOX_WITH_XPCOM) */
    5252
    5353#include "VBox/com/com.h"
     
    7070{
    7171
    72 #if defined (VBOX_WITH_XPCOM)
     72#if defined(VBOX_WITH_XPCOM)
    7373
    7474class DirectoryServiceProvider : public nsIDirectoryServiceProvider
     
    7979
    8080    DirectoryServiceProvider()
    81         : mCompRegLocation (NULL), mXPTIDatLocation (NULL)
    82         , mComponentDirLocation (NULL), mCurrProcDirLocation (NULL)
     81        : mCompRegLocation(NULL), mXPTIDatLocation(NULL)
     82        , mComponentDirLocation(NULL), mCurrProcDirLocation(NULL)
    8383        {}
    8484
    8585    virtual ~DirectoryServiceProvider();
    8686
    87     HRESULT init (const char *aCompRegLocation,
    88                   const char *aXPTIDatLocation,
    89                   const char *aComponentDirLocation,
    90                   const char *aCurrProcDirLocation);
     87    HRESULT init(const char *aCompRegLocation,
     88                 const char *aXPTIDatLocation,
     89                 const char *aComponentDirLocation,
     90                 const char *aCurrProcDirLocation);
    9191
    9292    NS_DECL_NSIDIRECTORYSERVICEPROVIDER
    9393
    9494private:
    95 
     95    /** @remarks This is not a UTF-8 string. */
    9696    char *mCompRegLocation;
     97    /** @remarks This is not a UTF-8 string. */
    9798    char *mXPTIDatLocation;
     99    /** @remarks This is not a UTF-8 string. */
    98100    char *mComponentDirLocation;
     101    /** @remarks This is not a UTF-8 string. */
    99102    char *mCurrProcDirLocation;
    100103};
    101104
    102 NS_IMPL_ISUPPORTS1 (DirectoryServiceProvider, nsIDirectoryServiceProvider)
     105NS_IMPL_ISUPPORTS1(DirectoryServiceProvider, nsIDirectoryServiceProvider)
    103106
    104107DirectoryServiceProvider::~DirectoryServiceProvider()
     
    106109    if (mCompRegLocation)
    107110    {
    108         RTStrFree (mCompRegLocation);
     111        RTStrFree(mCompRegLocation);
    109112        mCompRegLocation = NULL;
    110113    }
    111114    if (mXPTIDatLocation)
    112115    {
    113         RTStrFree (mXPTIDatLocation);
     116        RTStrFree(mXPTIDatLocation);
    114117        mXPTIDatLocation = NULL;
    115118    }
    116119    if (mComponentDirLocation)
    117120    {
    118         RTStrFree (mComponentDirLocation);
     121        RTStrFree(mComponentDirLocation);
    119122        mComponentDirLocation = NULL;
    120123    }
    121124    if (mCurrProcDirLocation)
    122125    {
    123         RTStrFree (mCurrProcDirLocation);
     126        RTStrFree(mCurrProcDirLocation);
    124127        mCurrProcDirLocation = NULL;
    125128    }
     
    131134 */
    132135HRESULT
    133 DirectoryServiceProvider::init (const char *aCompRegLocation,
    134                                 const char *aXPTIDatLocation,
    135                                 const char *aComponentDirLocation,
    136                                 const char *aCurrProcDirLocation)
     136DirectoryServiceProvider::init(const char *aCompRegLocation,
     137                               const char *aXPTIDatLocation,
     138                               const char *aComponentDirLocation,
     139                               const char *aCurrProcDirLocation)
    137140{
    138141    AssertReturn(aCompRegLocation, NS_ERROR_INVALID_ARG);
    139142    AssertReturn(aXPTIDatLocation, NS_ERROR_INVALID_ARG);
    140143
    141     int vrc = RTStrUtf8ToCurrentCP (&mCompRegLocation, aCompRegLocation);
     144/** @todo r=bird: Gotta check how this encoding stuff plays out on darwin!
     145 *  We get down to [VBoxNsxp]NS_NewNativeLocalFile and that file isn't
     146 *  nsLocalFileUnix.cpp on 32-bit darwin.  On 64-bit darwin it's a question
     147 *  of what we're doing in IPRT and such...  We should probably add a
     148 *  RTPathConvertToNative for use here. */
     149    int vrc = RTStrUtf8ToCurrentCP(&mCompRegLocation, aCompRegLocation);
    142150    if (RT_SUCCESS(vrc))
    143         vrc = RTStrUtf8ToCurrentCP (&mXPTIDatLocation, aXPTIDatLocation);
     151        vrc = RTStrUtf8ToCurrentCP(&mXPTIDatLocation, aXPTIDatLocation);
    144152    if (RT_SUCCESS(vrc) && aComponentDirLocation)
    145         vrc = RTStrUtf8ToCurrentCP (&mComponentDirLocation, aComponentDirLocation);
     153        vrc = RTStrUtf8ToCurrentCP(&mComponentDirLocation, aComponentDirLocation);
    146154    if (RT_SUCCESS(vrc) && aCurrProcDirLocation)
    147         vrc = RTStrUtf8ToCurrentCP (&mCurrProcDirLocation, aCurrProcDirLocation);
     155        vrc = RTStrUtf8ToCurrentCP(&mCurrProcDirLocation, aCurrProcDirLocation);
    148156
    149157    return RT_SUCCESS(vrc) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
     
    151159
    152160NS_IMETHODIMP
    153 DirectoryServiceProvider::GetFile (const char *aProp,
    154                                    PRBool *aPersistent,
    155                                    nsIFile **aRetval)
     161DirectoryServiceProvider::GetFile(const char *aProp,
     162                                  PRBool *aPersistent,
     163                                  nsIFile **aRetval)
    156164{
    157165    nsCOMPtr <nsILocalFile> localFile;
     
    163171    const char *fileLocation = NULL;
    164172
    165     if (strcmp (aProp, NS_XPCOM_COMPONENT_REGISTRY_FILE) == 0)
     173    if (strcmp(aProp, NS_XPCOM_COMPONENT_REGISTRY_FILE) == 0)
    166174        fileLocation = mCompRegLocation;
    167     else if (strcmp (aProp, NS_XPCOM_XPTI_REGISTRY_FILE) == 0)
     175    else if (strcmp(aProp, NS_XPCOM_XPTI_REGISTRY_FILE) == 0)
    168176        fileLocation = mXPTIDatLocation;
    169     else if (mComponentDirLocation && strcmp (aProp, NS_XPCOM_COMPONENT_DIR) == 0)
     177    else if (mComponentDirLocation && strcmp(aProp, NS_XPCOM_COMPONENT_DIR) == 0)
    170178        fileLocation = mComponentDirLocation;
    171     else if (mCurrProcDirLocation && strcmp (aProp, NS_XPCOM_CURRENT_PROCESS_DIR) == 0)
     179    else if (mCurrProcDirLocation && strcmp(aProp, NS_XPCOM_CURRENT_PROCESS_DIR) == 0)
    172180        fileLocation = mCurrProcDirLocation;
    173181    else
    174182        return NS_ERROR_FAILURE;
    175183
    176     rv = NS_NewNativeLocalFile (nsEmbedCString (fileLocation),
    177                                 PR_TRUE, getter_AddRefs (localFile));
     184    rv = NS_NewNativeLocalFile(nsEmbedCString(fileLocation),
     185                               PR_TRUE, getter_AddRefs(localFile));
    178186    if (NS_FAILED(rv))
    179187        return rv;
    180188
    181     return localFile->QueryInterface (NS_GET_IID (nsIFile),
    182                                       (void **) aRetval);
     189    return localFile->QueryInterface(NS_GET_IID (nsIFile), (void **)aRetval);
    183190}
    184191
     
    248255    HRESULT rc = E_FAIL;
    249256
    250 #if !defined (VBOX_WITH_XPCOM)
    251 
    252     DWORD flags = COINIT_MULTITHREADED |
    253                   COINIT_DISABLE_OLE1DDE |
    254                   COINIT_SPEED_OVER_MEMORY;
    255 
    256     rc = CoInitializeEx (NULL, flags);
     257#if !defined(VBOX_WITH_XPCOM)
     258
     259    DWORD flags = COINIT_MULTITHREADED
     260                | COINIT_DISABLE_OLE1DDE
     261                | COINIT_SPEED_OVER_MEMORY;
     262
     263    rc = CoInitializeEx(NULL, flags);
    257264
    258265    /// @todo the below rough method of changing the aparment type doesn't
     
    279286         * worry at all. */
    280287
    281         rc = CoInitializeEx (NULL, COINIT_APARTMENTTHREADED);
     288        rc = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
    282289        if (rc == RPC_E_CHANGED_MODE)
    283290        {
     
    285292            rc = S_OK;
    286293
    287             LogFlowFunc (("COM is already initialized in neutral threaded "
    288                           "apartment mode,\nwill accept it.\n"));
     294            LogFlowFunc(("COM is already initialized in neutral threaded "
     295                         "apartment mode,\nwill accept it.\n"));
    289296        }
    290297        else if (rc == S_FALSE)
     
    294301            rc = RPC_E_CHANGED_MODE;
    295302
    296             LogFlowFunc (("COM is already initialized in single threaded "
    297                           "apartment mode,\nwill reinitialize as "
    298                           "multi threaded.\n"));
     303            LogFlowFunc(("COM is already initialized in single threaded "
     304                         "apartment mode,\nwill reinitialize as "
     305                         "multi threaded.\n"));
    299306
    300307            enum { MaxTries = 10000 };
     
    303310            {
    304311                CoUninitialize();
    305                 rc = CoInitializeEx (NULL, flags);
     312                rc = CoInitializeEx(NULL, flags);
    306313                if (rc == S_OK)
    307314                {
     
    309316                     * initialization reference counter */
    310317
    311                     LogFlowFunc (("Will call CoInitializeEx() %d times.\n",
    312                                   MaxTries - tries));
     318                    LogFlowFunc(("Will call CoInitializeEx() %d times.\n",
     319                                 MaxTries - tries));
    313320
    314321                    while (tries ++ < MaxTries)
    315322                    {
    316                         rc = CoInitializeEx (NULL, flags);
    317                         Assert (rc == S_FALSE);
     323                        rc = CoInitializeEx(NULL, flags);
     324                        Assert(rc == S_FALSE);
    318325                    }
    319326                }
     
    321328        }
    322329        else
    323             AssertMsgFailed (("rc=%08X\n", rc));
     330            AssertMsgFailed(("rc=%08X\n", rc));
    324331    }
    325332# endif
     
    327334    /* the overall result must be either S_OK or S_FALSE (S_FALSE means
    328335     * "already initialized using the same apartment model") */
    329     AssertMsg (rc == S_OK || rc == S_FALSE, ("rc=%08X\n", rc));
     336    AssertMsg(rc == S_OK || rc == S_FALSE, ("rc=%08X\n", rc));
    330337
    331338    /* To be flow compatible with the XPCOM case, we return here if this isn't
     
    334341     *       counting, so this exercise is entirely for the EventQueue init. */
    335342    bool fRc;
    336     RTTHREAD hSelf = RTThreadSelf ();
     343    RTTHREAD hSelf = RTThreadSelf();
    337344    if (hSelf != NIL_RTTHREAD)
    338         ASMAtomicCmpXchgHandle (&gCOMMainThread, hSelf, NIL_RTTHREAD, fRc);
     345        ASMAtomicCmpXchgHandle(&gCOMMainThread, hSelf, NIL_RTTHREAD, fRc);
    339346    else
    340347        fRc = false;
     
    342349    {
    343350        if (   gCOMMainThread == hSelf
    344             && SUCCEEDED (rc))
     351            && SUCCEEDED(rc))
    345352            gCOMMainInitCount++;
    346353
    347         AssertComRC (rc);
     354        AssertComRC(rc);
    348355        return rc;
    349356    }
    350     Assert (RTThreadIsMain (hSelf));
     357    Assert(RTThreadIsMain(hSelf));
    351358
    352359    /* this is the first main thread initialization */
    353     Assert (gCOMMainInitCount == 0);
    354     if (SUCCEEDED (rc))
     360    Assert(gCOMMainInitCount == 0);
     361    if (SUCCEEDED(rc))
    355362        gCOMMainInitCount = 1;
    356363
    357364#else /* !defined (VBOX_WITH_XPCOM) */
    358365
    359     if (ASMAtomicXchgBool (&gIsXPCOMInitialized, true) == true)
     366    if (ASMAtomicXchgBool(&gIsXPCOMInitialized, true) == true)
    360367    {
    361368        /* XPCOM is already initialized on the main thread, no special
     
    365372         * Win32). */
    366373
    367         nsCOMPtr <nsIEventQueue> eventQ;
    368         rc = NS_GetMainEventQ (getter_AddRefs (eventQ));
     374        nsCOMPtr<nsIEventQueue> eventQ;
     375        rc = NS_GetMainEventQ(getter_AddRefs(eventQ));
    369376
    370377        if (NS_SUCCEEDED(rc))
    371378        {
    372379            PRBool isOnMainThread = PR_FALSE;
    373             rc = eventQ->IsOnCurrentThread (&isOnMainThread);
     380            rc = eventQ->IsOnCurrentThread(&isOnMainThread);
    374381            if (NS_SUCCEEDED(rc) && isOnMainThread)
    375                 ++ gXPCOMInitCount;
    376         }
    377 
    378         AssertComRC (rc);
     382                ++gXPCOMInitCount;
     383        }
     384
     385        AssertComRC(rc);
    379386        return rc;
    380387    }
    381     Assert (RTThreadIsMain (RTThreadSelf()));
     388    Assert(RTThreadIsMain(RTThreadSelf()));
    382389
    383390    /* this is the first initialization */
     
    386393
    387394    /* prepare paths for registry files */
    388     char userHomeDir [RTPATH_MAX];
    389     int vrc = GetVBoxUserHomeDirectory (userHomeDir, sizeof (userHomeDir));
    390     AssertRCReturn (vrc, NS_ERROR_FAILURE);
    391 
    392     char compReg [RTPATH_MAX];
    393     char xptiDat [RTPATH_MAX];
    394 
    395     /** @todo use RTPathAppend */
    396     RTStrPrintf (compReg, sizeof (compReg), "%s%c%s",
    397                  userHomeDir, RTPATH_DELIMITER, "compreg.dat");
    398     RTStrPrintf (xptiDat, sizeof (xptiDat), "%s%c%s",
    399                  userHomeDir, RTPATH_DELIMITER, "xpti.dat");
    400 
    401     LogFlowFunc (("component registry  : \"%s\"\n", compReg));
    402     LogFlowFunc (("XPTI data file      : \"%s\"\n", xptiDat));
     395    char szCompReg[RTPATH_MAX];
     396    char szXptiDat[RTPATH_MAX];
     397
     398    int vrc = GetVBoxUserHomeDirectory(szCompReg, sizeof(szCompReg));
     399    AssertRCReturn(vrc, NS_ERROR_FAILURE);
     400    strcpy(szXptiDat, szCompReg);
     401
     402    vrc = RTPathAppend(szCompReg, sizeof(szCompReg), "compreg.dat");
     403    AssertRCReturn(vrc, NS_ERROR_FAILURE);
     404    vrc = RTPathAppend(szXptiDat, sizeof(szXptiDat), "xpti.dat");
     405    AssertRCReturn(vrc, NS_ERROR_FAILURE);
     406
     407    LogFlowFunc(("component registry  : \"%s\"\n", szCompReg));
     408    LogFlowFunc(("XPTI data file      : \"%s\"\n", szXptiDat));
    403409
    404410#if defined (XPCOM_GLUE)
    405     XPCOMGlueStartup (nsnull);
     411    XPCOMGlueStartup(nsnull);
    406412#endif
    407413
     
    422428
    423429    /* Find out the directory where VirtualBox binaries are located */
    424     for (size_t i = 0; i < RT_ELEMENTS (kAppPathsToProbe); ++ i)
    425     {
    426         char appHomeDir [RTPATH_MAX];
    427         appHomeDir [RTPATH_MAX - 1] = '\0';
     430    for (size_t i = 0; i < RT_ELEMENTS(kAppPathsToProbe); ++ i)
     431    {
     432        char szAppHomeDir[RTPATH_MAX];
    428433
    429434        if (i == 0)
    430435        {
    431436            /* Use VBOX_APP_HOME if present */
    432             if (!RTEnvExist ("VBOX_APP_HOME"))
     437            vrc = RTEnvGetEx(RTENV_DEFAULT, "VBOX_APP_HOME", szAppHomeDir, sizeof(szAppHomeDir), NULL);
     438            if (vrc == VERR_ENV_VAR_NOT_FOUND)
    433439                continue;
    434 
    435             strncpy (appHomeDir, RTEnvGet ("VBOX_APP_HOME"), RTPATH_MAX - 1); /** @todo r=bird: Use RTEnvGetEx. */
     440            AssertRC(vrc);
    436441        }
    437442        else if (i == 1)
    438443        {
    439444            /* Use RTPathAppPrivateArch() first */
    440             vrc = RTPathAppPrivateArch (appHomeDir, sizeof (appHomeDir));
     445            vrc = RTPathAppPrivateArch(szAppHomeDir, sizeof(szAppHomeDir));
    441446            AssertRC (vrc);
    442             if (RT_FAILURE(vrc))
    443             {
    444                 rc = NS_ERROR_FAILURE;
    445                 continue;
    446             }
    447447        }
    448448        else
    449449        {
    450450            /* Iterate over all other paths */
    451             strncpy (appHomeDir, kAppPathsToProbe [i], RTPATH_MAX - 1);
    452         }
    453 
    454         nsCOMPtr <DirectoryServiceProvider> dsProv;
    455 
    456         char compDir [RTPATH_MAX];
    457         RTStrPrintf (compDir, sizeof (compDir), "%s%c%s",
    458                      appHomeDir, RTPATH_DELIMITER, "components");
    459         LogFlowFunc (("component directory : \"%s\"\n", compDir));
    460 
     451            szAppHomeDir[RTPATH_MAX - 1] = '\0';
     452            strncpy(szAppHomeDir, kAppPathsToProbe [i], RTPATH_MAX - 1);
     453            vrc = VINF_SUCCESS;
     454        }
     455        if (RT_FAILURE(vrc))
     456        {
     457            rc = NS_ERROR_FAILURE;
     458            continue;
     459        }
     460
     461        char szCompDir[RTPATH_MAX];
     462        vrc = RTPathAppend(strcpy(szCompDir, szAppHomeDir), sizeof(szCompDir), "components");
     463        if (RT_FAILURE(vrc))
     464        {
     465            rc = NS_ERROR_FAILURE;
     466            continue;
     467        }
     468        LogFlowFunc(("component directory : \"%s\"\n", szCompDir));
     469
     470        nsCOMPtr<DirectoryServiceProvider> dsProv;
    461471        dsProv = new DirectoryServiceProvider();
    462472        if (dsProv)
    463             rc = dsProv->init (compReg, xptiDat, compDir, appHomeDir);
     473            rc = dsProv->init(szCompReg, szXptiDat, szCompDir, szAppHomeDir);
    464474        else
    465475            rc = NS_ERROR_OUT_OF_MEMORY;
    466         if (NS_FAILED (rc))
     476        if (NS_FAILED(rc))
    467477            break;
    468478
     
    475485        {
    476486            char *appDirCP = NULL;
    477             vrc = RTStrUtf8ToCurrentCP (&appDirCP, appHomeDir);
     487            vrc = RTStrUtf8ToCurrentCP(&appDirCP, szAppHomeDir);
    478488            if (RT_SUCCESS(vrc))
    479489            {
    480                 nsCOMPtr <nsILocalFile> file;
    481                 rc = NS_NewNativeLocalFile (nsEmbedCString (appDirCP),
    482                                             PR_FALSE, getter_AddRefs (file));
     490                nsCOMPtr<nsILocalFile> file;
     491                rc = NS_NewNativeLocalFile(nsEmbedCString(appDirCP),
     492                                           PR_FALSE, getter_AddRefs(file));
    483493                if (NS_SUCCEEDED(rc))
    484                     appDir = do_QueryInterface (file, &rc);
    485 
    486                 RTStrFree (appDirCP);
     494                    appDir = do_QueryInterface(file, &rc);
     495
     496                RTStrFree(appDirCP);
    487497            }
    488498            else
    489499                rc = NS_ERROR_FAILURE;
    490500        }
    491         if (NS_FAILED (rc))
     501        if (NS_FAILED(rc))
    492502            break;
    493503
    494504        /* Set VBOX_XPCOM_HOME to the same app path to make XPCOM sources that
    495505         * still use it instead of the directory service happy */
    496         {
    497             char *pathCP = NULL;
    498             vrc = RTStrUtf8ToCurrentCP (&pathCP, appHomeDir);
    499             if (RT_SUCCESS(vrc))
    500             {
    501                 vrc = RTEnvSet ("VBOX_XPCOM_HOME", pathCP);
    502                 RTStrFree (pathCP);
    503             }
    504             AssertRC (vrc);
    505         }
     506        vrc = RTEnvSetEx(RTENV_DEFAULT, "VBOX_XPCOM_HOME", szAppHomeDir);
     507        AssertRC(vrc);
    506508
    507509        /* Finally, initialize XPCOM */
    508510        {
    509             nsCOMPtr <nsIServiceManager> serviceManager;
    510             rc = NS_InitXPCOM2 (getter_AddRefs (serviceManager),
    511                                 appDir, dsProv);
    512 
     511            nsCOMPtr<nsIServiceManager> serviceManager;
     512            rc = NS_InitXPCOM2(getter_AddRefs(serviceManager), appDir, dsProv);
    513513            if (NS_SUCCEEDED(rc))
    514514            {
    515                 nsCOMPtr <nsIComponentRegistrar> registrar =
    516                     do_QueryInterface (serviceManager, &rc);
     515                nsCOMPtr<nsIComponentRegistrar> registrar =
     516                    do_QueryInterface(serviceManager, &rc);
    517517                if (NS_SUCCEEDED(rc))
    518518                {
    519                     rc = registrar->AutoRegister (nsnull);
     519                    rc = registrar->AutoRegister(nsnull);
    520520                    if (NS_SUCCEEDED(rc))
    521521                    {
    522522                        /* We succeeded, stop probing paths */
    523                         LogFlowFunc (("Succeeded.\n"));
     523                        LogFlowFunc(("Succeeded.\n"));
    524524                        break;
    525525                    }
     
    529529
    530530        /* clean up before the new try */
    531         rc = NS_ShutdownXPCOM (nsnull);
     531        rc = NS_ShutdownXPCOM(nsnull);
    532532
    533533        if (i == 0)
     
    545545    util::InitAutoLockSystem();
    546546
    547     AssertComRC (rc);
     547    AssertComRC(rc);
    548548
    549549    /*
    550550     * Init the main event queue (ASSUMES it cannot fail).
    551551     */
    552     if (SUCCEEDED (rc))
     552    if (SUCCEEDED(rc))
    553553        EventQueue::init();
    554554
     
    560560    HRESULT rc = S_OK;
    561561
    562 #if !defined (VBOX_WITH_XPCOM)
     562#if !defined(VBOX_WITH_XPCOM)
    563563
    564564    /* EventQueue::uninit reference counting fun. */
     
    570570        {
    571571            EventQueue::uninit();
    572             ASMAtomicWriteHandle (&gCOMMainThread, NIL_RTTHREAD);
     572            ASMAtomicWriteHandle(&gCOMMainThread, NIL_RTTHREAD);
    573573        }
    574574    }
     
    578578#else /* !defined (VBOX_WITH_XPCOM) */
    579579
    580     nsCOMPtr <nsIEventQueue> eventQ;
    581     rc = NS_GetMainEventQ (getter_AddRefs (eventQ));
     580    nsCOMPtr<nsIEventQueue> eventQ;
     581    rc = NS_GetMainEventQ(getter_AddRefs(eventQ));
    582582
    583583    if (NS_SUCCEEDED(rc) || rc == NS_ERROR_NOT_AVAILABLE)
     
    593593        if (NS_SUCCEEDED(rc))
    594594        {
    595             rc = eventQ->IsOnCurrentThread (&isOnMainThread);
     595            rc = eventQ->IsOnCurrentThread(&isOnMainThread);
    596596            eventQ = nsnull; /* early release before shutdown */
    597597        }
     
    606606            /* only the main thread needs to uninitialize XPCOM and only if
    607607             * init counter drops to zero */
    608             if (-- gXPCOMInitCount == 0)
     608            if (--gXPCOMInitCount == 0)
    609609            {
    610610                EventQueue::uninit();
    611                 rc = NS_ShutdownXPCOM (nsnull);
     611                rc = NS_ShutdownXPCOM(nsnull);
    612612
    613613                /* This is a thread initialized XPCOM and set gIsXPCOMInitialized to
    614614                 * true. Reset it back to false. */
    615                 bool wasInited = ASMAtomicXchgBool (&gIsXPCOMInitialized, false);
    616                 Assert (wasInited == true);
    617                 NOREF (wasInited);
    618 
    619 #if defined (XPCOM_GLUE)
     615                bool wasInited = ASMAtomicXchgBool(&gIsXPCOMInitialized, false);
     616                Assert(wasInited == true);
     617                NOREF(wasInited);
     618
     619# if defined (XPCOM_GLUE)
    620620                XPCOMGlueShutdown();
    621 #endif
     621# endif
    622622            }
    623623        }
    624624    }
    625625
    626 #endif /* !defined (VBOX_WITH_XPCOM) */
    627 
    628     AssertComRC (rc);
     626#endif /* !defined(VBOX_WITH_XPCOM) */
     627
     628    AssertComRC(rc);
    629629
    630630    return rc;
  • trunk/src/VBox/Main/linux/HostHardwareLinux.cpp

    r25728 r25942  
    581581    int rc = VINF_SUCCESS;
    582582    bool success = false;
     583    char *pszFreeMe = RTEnvDupEx(RTENV_DEFAULT, pcszVar);
    583584
    584585    try
    585586    {
    586         const char *pcszCurrent = RTEnvGet (pcszVar);
     587        const char *pcszCurrent = pszFreeMe;
    587588        while (pcszCurrent && *pcszCurrent != '\0')
    588589        {
     
    611612        rc = VERR_NO_MEMORY;
    612613    }
    613     LogFlowFunc (("rc=%Rrc, success=%d\n", rc, success));
     614    RTStrFree(pszFreeMe);
     615    LogFlowFunc(("rc=%Rrc, success=%d\n", rc, success));
    614616    return rc;
    615617}
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette