Changeset 19028 in vbox for trunk/src/VBox/Main
- Timestamp:
- Apr 20, 2009 2:09:04 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 46138
- Location:
- trunk/src/VBox/Main/cbinding
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/cbinding/VBoxXPCOMCGlue.c
r18923 r19028 32 32 * Header Files * 33 33 *******************************************************************************/ 34 #ifdef LIBVIRT_VERSION35 # include <config.h>36 #endif /* LIBVIRT_VERSION */37 38 34 #include <stdio.h> 39 35 #include <string.h> 40 36 #include <stdlib.h> 37 #include <stdarg.h> 41 38 #include <dlfcn.h> 42 39 … … 64 61 void *g_hVBoxXPCOMC = NULL; 65 62 /** The last load error. */ 63 char g_szVBoxErrMsg[256]; 64 /** Pointer to the VBoxXPCOMC function table. */ 66 65 PCVBOXXPCOM g_pVBoxFuncs = NULL; 67 66 /** Pointer to VBoxGetXPCOMCFunctions for the loaded VBoxXPCOMC so/dylib/dll. */ … … 70 69 71 70 /** 71 * Wrapper for setting g_szVBoxErrMsg. Can be an empty stub. 72 * 73 * @param pszFormat The format string. 74 * @param ... The arguments. 75 */ 76 static 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 /** 72 86 * Try load VBoxXPCOMC.so/dylib/dll from the specified location and resolve all 73 87 * the symbols we need. 74 88 * 75 89 * @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). 78 94 */ 79 95 static int tryLoadOne(const char *pszHome, int fSetAppHome) … … 81 97 size_t cchHome = pszHome ? strlen(pszHome) : 0; 82 98 size_t cbBufNeeded; 83 char sz Buf[4096];99 char szName[4096]; 84 100 int rc = -1; 85 101 … … 88 104 */ 89 105 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); 92 110 return -1; 93 111 } 94 112 if (cchHome) 95 113 { 96 memcpy(sz Buf, pszHome, cchHome);97 sz Buf[cchHome] = '/';114 memcpy(szName, pszHome, cchHome); 115 szName[cchHome] = '/'; 98 116 cchHome++; 99 117 } 100 memcpy(&sz Buf[cchHome], DYNLIB_NAME, sizeof(DYNLIB_NAME));118 memcpy(&szName[cchHome], DYNLIB_NAME, sizeof(DYNLIB_NAME)); 101 119 102 120 /* … … 111 129 unsetenv("VBOX_APP_HOME"); 112 130 } 113 g_hVBoxXPCOMC = dlopen(sz Buf, RTLD_NOW | RTLD_LOCAL);131 g_hVBoxXPCOMC = dlopen(szName, RTLD_NOW | RTLD_LOCAL); 114 132 if (g_hVBoxXPCOMC) 115 133 { … … 123 141 { 124 142 g_pfnGetFunctions = pfnGetFunctions; 125 r c =0;143 return 0; 126 144 } 145 146 /* bail out */ 147 setErrMsg("%.80s: pfnGetFunctions(%#x) failed", 148 szName, VBOX_XPCOMC_VERSION); 127 149 } 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()); 134 158 return rc; 135 159 } … … 204 228 g_pVBoxFuncs = NULL; 205 229 g_pfnGetFunctions = NULL; 206 } 207 230 memset(g_szVBoxErrMsg, 0, sizeof(g_szVBoxErrMsg)); 231 } 232 -
trunk/src/VBox/Main/cbinding/VBoxXPCOMCGlue.h
r18895 r19028 41 41 extern void *g_hVBoxXPCOMC; 42 42 /** The last load error. */ 43 extern char g_szVBoxErrMsg[256]; 44 /** Pointer to the VBoxXPCOMC function table. */ 43 45 extern PCVBOXXPCOM g_pVBoxFuncs; 44 46 /** Pointer to VBoxGetXPCOMCFunctions for the loaded VBoxXPCOMC so/dylib/dll. */ -
trunk/src/VBox/Main/cbinding/tstXPCOMCCall.c
r18998 r19028 600 600 if (VBoxCGlueInit() != 0) 601 601 { 602 fprintf(stderr, "%s: FATAL: VBoxCGlueInit failed.\n", argv[0]); 602 fprintf(stderr, "%s: FATAL: VBoxCGlueInit failed: %s\n", 603 argv[0], g_szVBoxErrMsg); 603 604 return EXIT_FAILURE; 604 605 } -
trunk/src/VBox/Main/cbinding/tstXPCOMCGlue.c
r18891 r19028 321 321 if (VBoxCGlueInit() != 0) 322 322 { 323 fprintf(stderr, "%s: FATAL: VBoxCGlueInit failed.\n", argv[0]); 323 fprintf(stderr, "%s: FATAL: VBoxCGlueInit failed: %s\n", 324 argv[0], g_szVBoxErrMsg); 324 325 return EXIT_FAILURE; 325 326 }
Note:
See TracChangeset
for help on using the changeset viewer.