VirtualBox

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


Ignore:
Timestamp:
Apr 20, 2009 2:09:04 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
46138
Message:

Main/cbindins,libvirt/*glue: Bought back g_szVBoxErrMsg and change the code to use vsnprintf as well as fixing a couple of the string length constraints. When compiling with libvirt, we won't set g_szVBoxErrMsg. Renamed szBuf to szName to make it easier to read.

Location:
trunk/src/VBox/Main/cbinding
Files:
4 edited

Legend:

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

    r18923 r19028  
    3232*   Header Files                                                               *
    3333*******************************************************************************/
    34 #ifdef LIBVIRT_VERSION
    35 # include <config.h>
    36 #endif /* LIBVIRT_VERSION */
    37 
    3834#include <stdio.h>
    3935#include <string.h>
    4036#include <stdlib.h>
     37#include <stdarg.h>
    4138#include <dlfcn.h>
    4239
     
    6461void *g_hVBoxXPCOMC = NULL;
    6562/** The last load error. */
     63char g_szVBoxErrMsg[256];
     64/** Pointer to the VBoxXPCOMC function table. */
    6665PCVBOXXPCOM g_pVBoxFuncs = NULL;
    6766/** Pointer to VBoxGetXPCOMCFunctions for the loaded VBoxXPCOMC so/dylib/dll. */
     
    7069
    7170/**
     71 * Wrapper for setting g_szVBoxErrMsg. Can be an empty stub.
     72 *
     73 * @param   pszFormat       The format string.
     74 * @param   ...             The arguments.
     75 */
     76static void setErrMsg(const char *pszFormat, ...)
     77{
     78    va_list va;
     79    va_start(va, pszFormat);
     80    vsnprintf(g_szVBoxErrMsg, sizeof(g_szVBoxErrMsg), pszFormat, va);
     81    va_end(va);
     82}
     83
     84
     85/**
    7286 * Try load VBoxXPCOMC.so/dylib/dll from the specified location and resolve all
    7387 * the symbols we need.
    7488 *
    7589 * @returns 0 on success, -1 on failure.
    76  * @param   pszHome         The director where to try load VBoxXPCOMC from. Can be NULL.
    77  * @param   fSetAppHome     Whether to set the VBOX_APP_HOME env.var. or not (boolean).
     90 * @param   pszHome         The director where to try load VBoxXPCOMC from. Can
     91 *                          be NULL.
     92 * @param   fSetAppHome     Whether to set the VBOX_APP_HOME env.var. or not
     93 *                          (boolean).
    7894 */
    7995static int tryLoadOne(const char *pszHome, int fSetAppHome)
     
    8197    size_t      cchHome = pszHome ? strlen(pszHome) : 0;
    8298    size_t      cbBufNeeded;
    83     char        szBuf[4096];
     99    char        szName[4096];
    84100    int         rc = -1;
    85101
     
    88104     */
    89105    cbBufNeeded = cchHome + sizeof("/" DYNLIB_NAME);
    90     if (cbBufNeeded > sizeof(szBuf))
    91     {
     106    if (cbBufNeeded > sizeof(szName))
     107    {
     108        setErrMsg("path buffer too small: %u bytes needed",
     109                  (unsigned)cbBufNeeded);
    92110        return -1;
    93111    }
    94112    if (cchHome)
    95113    {
    96         memcpy(szBuf, pszHome, cchHome);
    97         szBuf[cchHome] = '/';
     114        memcpy(szName, pszHome, cchHome);
     115        szName[cchHome] = '/';
    98116        cchHome++;
    99117    }
    100     memcpy(&szBuf[cchHome], DYNLIB_NAME, sizeof(DYNLIB_NAME));
     118    memcpy(&szName[cchHome], DYNLIB_NAME, sizeof(DYNLIB_NAME));
    101119
    102120    /*
     
    111129            unsetenv("VBOX_APP_HOME");
    112130    }
    113     g_hVBoxXPCOMC = dlopen(szBuf, RTLD_NOW | RTLD_LOCAL);
     131    g_hVBoxXPCOMC = dlopen(szName, RTLD_NOW | RTLD_LOCAL);
    114132    if (g_hVBoxXPCOMC)
    115133    {
     
    123141            {
    124142                g_pfnGetFunctions = pfnGetFunctions;
    125                 rc = 0;
     143                return 0;
    126144            }
     145
     146            /* bail out */
     147            setErrMsg("%.80s: pfnGetFunctions(%#x) failed",
     148                      szName, VBOX_XPCOMC_VERSION);
    127149        }
    128         if (rc != 0)
    129         {
    130             dlclose(g_hVBoxXPCOMC);
    131             g_hVBoxXPCOMC = NULL;
    132         }
    133     }
     150        else
     151            setErrMsg("dlsym(%.80s/%.32s): %.128s",
     152                      szName, VBOX_GET_XPCOMC_FUNCTIONS_SYMBOL_NAME, dlerror());
     153        dlclose(g_hVBoxXPCOMC);
     154        g_hVBoxXPCOMC = NULL;
     155    }
     156    else
     157        setErrMsg("dlopen(%.80s): %.160s", szName, dlerror());
    134158    return rc;
    135159}
     
    204228    g_pVBoxFuncs = NULL;
    205229    g_pfnGetFunctions = NULL;
    206 }
    207 
     230    memset(g_szVBoxErrMsg, 0, sizeof(g_szVBoxErrMsg));
     231}
     232
  • trunk/src/VBox/Main/cbinding/VBoxXPCOMCGlue.h

    r18895 r19028  
    4141extern void *g_hVBoxXPCOMC;
    4242/** The last load error. */
     43extern char g_szVBoxErrMsg[256];
     44/** Pointer to the VBoxXPCOMC function table. */
    4345extern PCVBOXXPCOM g_pVBoxFuncs;
    4446/** Pointer to VBoxGetXPCOMCFunctions for the loaded VBoxXPCOMC so/dylib/dll. */
  • trunk/src/VBox/Main/cbinding/tstXPCOMCCall.c

    r18998 r19028  
    600600    if (VBoxCGlueInit() != 0)
    601601    {
    602         fprintf(stderr, "%s: FATAL: VBoxCGlueInit failed.\n", argv[0]);
     602        fprintf(stderr, "%s: FATAL: VBoxCGlueInit failed: %s\n",
     603                argv[0], g_szVBoxErrMsg);
    603604        return EXIT_FAILURE;
    604605    }
  • trunk/src/VBox/Main/cbinding/tstXPCOMCGlue.c

    r18891 r19028  
    321321    if (VBoxCGlueInit() != 0)
    322322    {
    323         fprintf(stderr, "%s: FATAL: VBoxCGlueInit failed.\n", argv[0]);
     323        fprintf(stderr, "%s: FATAL: VBoxCGlueInit failed: %s\n",
     324                argv[0], g_szVBoxErrMsg);
    324325        return EXIT_FAILURE;
    325326    }
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