VirtualBox

Changeset 18871 in vbox


Ignore:
Timestamp:
Apr 11, 2009 9:38:59 PM (16 years ago)
Author:
vboxsync
Message:

VBoxXPCOMCGlue.c: Use parameters for passing stuff down to the worker function, not globals, plz. (untested)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/cbinding/VBoxXPCOMCGlue.c

    r18853 r18871  
    6969/** Pointer to VBoxGetXPCOMCFunctions for the loaded VBoxXPCOMC so/dylib/dll. */
    7070PFNVBOXGETXPCOMCFUNCTIONS g_pfnGetFunctions = NULL;
    71 /** boolean for checking if the VBOX_APP_HOME is already set by the users */
    72 int g_bVAHSet = 0;
    7371
    7472
     
    7977 * @returns 0 on success, -1 on failure.
    8078 * @param   pszHome         The director where to try load VBoxXPCOMC from. Can be NULL.
    81  */
    82 static int tryLoadOne(const char *pszHome)
     79 * @param   fSetAppHome     Whether to set the VBOX_APP_HOME env.var. or not (boolean).
     80 */
     81static int tryLoadOne(const char *pszHome, int fSetAppHome)
    8382{
    8483    size_t      cchHome = pszHome ? strlen(pszHome) : 0;
    85     size_t      cbReq;
     84    size_t      cbBufNeeded;
    8685    char        szBuf[4096];
    8786    int         rc = -1;
     
    9089     * Construct the full name.
    9190     */
    92     cbReq = cchHome + sizeof("/" DYNLIB_NAME);
    93     if (cbReq > sizeof(szBuf))
    94     {
    95         sprintf(g_szVBoxErrMsg, "path buffer too small: %u bytes required", (unsigned)cbReq);
     91    cbBufNeeded = cchHome + sizeof("/" DYNLIB_NAME);
     92    if (cbBufNeeded > sizeof(szBuf))
     93    {
     94        sprintf(g_szVBoxErrMsg, "path buffer too small: %u bytes needed", (unsigned)cbBufNeeded);
    9695        return -1;
    9796    }
    98     memcpy(szBuf, pszHome, cchHome);
    99     szBuf[cchHome] = '/';
    100     cchHome++;
     97    if (cchHome)
     98    {
     99        memcpy(szBuf, pszHome, cchHome);
     100        szBuf[cchHome] = '/';
     101        cchHome++;
     102    }
    101103    memcpy(&szBuf[cchHome], DYNLIB_NAME, sizeof(DYNLIB_NAME));
    102104
     
    105107     * Then resolve and call the function table getter.
    106108     */
    107     if (!g_bVAHSet)
    108     {
    109         /* Override it as we know that user didn't set it
    110          * and that we only did it in previous iteration
    111          */
    112         setenv("VBOX_APP_HOME", pszHome, 1);
     109    if (fSetAppHome)
     110    {
     111        if (pszHome)
     112            setenv("VBOX_APP_HOME", pszHome, 1 /* always override */);
     113        else
     114            unsetenv("VBOX_APP_HOME");
    113115    }
    114116    g_hVBoxXPCOMC = dlopen(szBuf, RTLD_NOW | RTLD_LOCAL);
     
    163165    const char *pszHome = getenv("VBOX_APP_HOME");
    164166    if (pszHome)
    165     {
    166         g_bVAHSet = 1;
    167         return tryLoadOne(pszHome);
    168     }
     167        return tryLoadOne(pszHome, 0);
    169168
    170169    /*
     
    172171     */
    173172#if defined(__gnu__linux__) || defined(__linux__)
    174     if (tryLoadOne("/opt/VirtualBox") == 0)
    175         return 0;
    176     if (tryLoadOne("/usr/lib/virtualbox") == 0)
     173    if (tryLoadOne("/opt/VirtualBox", 1) == 0)
     174        return 0;
     175    if (tryLoadOne("/usr/lib/virtualbox", 1) == 0)
    177176        return 0;
    178177#elif defined(__sun__)
    179     if (tryLoadOne("/opt/VirtualBox/amd64") == 0)
    180         return 0;
    181     if (tryLoadOne("/opt/VirtualBox/i386") == 0)
     178    if (tryLoadOne("/opt/VirtualBox/amd64", 1) == 0)
     179        return 0;
     180    if (tryLoadOne("/opt/VirtualBox/i386", 1) == 0)
    182181        return 0;
    183182#elif defined(__APPLE__)
    184     if (tryLoadOne("/Application/VirtualBox.app/Contents/MacOS") == 0)
     183    if (tryLoadOne("/Application/VirtualBox.app/Contents/MacOS", 1) == 0)
    185184        return 0;
    186185#else
     
    191190     * Finally try the dynamic linker search path.
    192191     */
    193     if (tryLoadOne(NULL) == 0)
     192    if (tryLoadOne(NULL, 1) == 0)
    194193        return 0;
    195194
Note: See TracChangeset for help on using the changeset viewer.

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