Changeset 58029 in vbox
- Timestamp:
- Oct 5, 2015 8:50:18 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/VBoxGuestLib.h
r57006 r58029 586 586 uint32_t u32Root; 587 587 } VBGLR3SHAREDFOLDERMAPPING; 588 /** Pointer to a shared folder mapping information struct . */588 /** Pointer to a shared folder mapping information structure. */ 589 589 typedef VBGLR3SHAREDFOLDERMAPPING *PVBGLR3SHAREDFOLDERMAPPING; 590 /** Pointer to a const shared folder mapping information structure. */ 591 typedef VBGLR3SHAREDFOLDERMAPPING const *PCVBGLR3SHAREDFOLDERMAPPING; 590 592 591 593 VBGLR3DECL(int) VbglR3SharedFolderConnect(uint32_t *pu32ClientId); -
trunk/src/VBox/Additions/common/VBoxService/VBoxService-os2.def
r56294 r58029 1 ; $Id$ 1 2 ;; @file 2 3 ; VBoxService - OS/2 definition file. -
trunk/src/VBox/Additions/common/VBoxService/VBoxService-win.cpp
r57358 r58029 34 34 * Internal Functions * 35 35 *********************************************************************************************************************************/ 36 static void WINAPI v boxServiceWinMain(DWORD argc, LPTSTR *argv);36 static void WINAPI vgsvcWinMain(DWORD argc, LPTSTR *argv); 37 37 38 38 … … 47 47 static SERVICE_TABLE_ENTRY const g_aServiceTable[] = 48 48 { 49 { VBOXSERVICE_NAME, v boxServiceWinMain },49 { VBOXSERVICE_NAME, vgsvcWinMain }, 50 50 { NULL, NULL} 51 51 }; … … 57 57 * @todo Add event log capabilities / check return values. 58 58 */ 59 static DWORD v boxServiceWinAddAceToObjectsSecurityDescriptor(LPTSTR pszObjName,59 static DWORD vgsvcWinAddAceToObjectsSecurityDescriptor(LPTSTR pszObjName, 60 60 SE_OBJECT_TYPE ObjectType, 61 61 LPTSTR pszTrustee, … … 80 80 { 81 81 if (dwRes == ERROR_FILE_NOT_FOUND) 82 V BoxServiceError("AddAceToObjectsSecurityDescriptor: Object not found/installed: %s\n", pszObjName);82 VGSvcError("AddAceToObjectsSecurityDescriptor: Object not found/installed: %s\n", pszObjName); 83 83 else 84 V BoxServiceError("AddAceToObjectsSecurityDescriptor: GetNamedSecurityInfo: Error %u\n", dwRes);84 VGSvcError("AddAceToObjectsSecurityDescriptor: GetNamedSecurityInfo: Error %u\n", dwRes); 85 85 goto l_Cleanup; 86 86 } … … 98 98 if (ERROR_SUCCESS != dwRes) 99 99 { 100 V BoxServiceError("AddAceToObjectsSecurityDescriptor: SetEntriesInAcl: Error %u\n", dwRes);100 VGSvcError("AddAceToObjectsSecurityDescriptor: SetEntriesInAcl: Error %u\n", dwRes); 101 101 goto l_Cleanup; 102 102 } … … 108 108 if (ERROR_SUCCESS != dwRes) 109 109 { 110 V BoxServiceError("AddAceToObjectsSecurityDescriptor: SetNamedSecurityInfo: Error %u\n", dwRes);110 VGSvcError("AddAceToObjectsSecurityDescriptor: SetNamedSecurityInfo: Error %u\n", dwRes); 111 111 goto l_Cleanup; 112 112 } … … 125 125 126 126 /** Reports our current status to the SCM. */ 127 static BOOL v boxServiceWinSetStatus(DWORD dwStatus, DWORD dwCheckPoint)127 static BOOL vgsvcWinSetStatus(DWORD dwStatus, DWORD dwCheckPoint) 128 128 { 129 129 if (g_hWinServiceStatus == NULL) /* Program could be in testing mode, so no service environment available. */ 130 130 return FALSE; 131 131 132 V BoxServiceVerbose(2, "Setting service status to: %ld\n", dwStatus);132 VGSvcVerbose(2, "Setting service status to: %ld\n", dwStatus); 133 133 g_dwWinServiceLastStatus = dwStatus; 134 134 … … 154 154 } 155 155 else 156 V BoxServiceError("Error determining OS version, rc=%Rrc\n", rc);156 VGSvcError("Error determining OS version, rc=%Rrc\n", rc); 157 157 #endif 158 158 } … … 165 165 BOOL fStatusSet = SetServiceStatus(g_hWinServiceStatus, &ss); 166 166 if (!fStatusSet) 167 V BoxServiceError("Error reporting service status=%ld (controls=%x, checkpoint=%ld) to SCM: %ld\n",167 VGSvcError("Error reporting service status=%ld (controls=%x, checkpoint=%ld) to SCM: %ld\n", 168 168 dwStatus, ss.dwControlsAccepted, dwCheckPoint, GetLastError()); 169 169 return fStatusSet; … … 176 176 * @param uCheckPoint Some number. 177 177 */ 178 void V BoxServiceWinSetStopPendingStatus(uint32_t uCheckPoint)179 { 180 v boxServiceWinSetStatus(SERVICE_STOP_PENDING, uCheckPoint);181 } 182 183 184 static RTEXITCODE v boxServiceWinSetDesc(SC_HANDLE hService)178 void VGSvcWinSetStopPendingStatus(uint32_t uCheckPoint) 179 { 180 vgsvcWinSetStatus(SERVICE_STOP_PENDING, uCheckPoint); 181 } 182 183 184 static RTEXITCODE vgsvcWinSetDesc(SC_HANDLE hService) 185 185 { 186 186 #ifndef TARGET_NT4 … … 194 194 &desc)) 195 195 { 196 V BoxServiceError("Cannot set the service description! Error: %ld\n", GetLastError());196 VGSvcError("Cannot set the service description! Error: %ld\n", GetLastError()); 197 197 return RTEXITCODE_FAILURE; 198 198 } … … 205 205 * Installs the service. 206 206 */ 207 RTEXITCODE V BoxServiceWinInstall(void)208 { 209 V BoxServiceVerbose(1, "Installing service ...\n");207 RTEXITCODE VGSvcWinInstall(void) 208 { 209 VGSvcVerbose(1, "Installing service ...\n"); 210 210 211 211 TCHAR imagePath[MAX_PATH] = { 0 }; … … 215 215 if (hSCManager == NULL) 216 216 { 217 V BoxServiceError("Could not open SCM! Error: %ld\n", GetLastError());217 VGSvcError("Could not open SCM! Error: %ld\n", GetLastError()); 218 218 return RTEXITCODE_FAILURE; 219 219 } … … 227 227 imagePath, NULL, NULL, NULL, NULL, NULL); 228 228 if (hService != NULL) 229 V BoxServiceVerbose(0, "Service successfully installed!\n");229 VGSvcVerbose(0, "Service successfully installed!\n"); 230 230 else 231 231 { … … 234 234 { 235 235 case ERROR_SERVICE_EXISTS: 236 V BoxServiceVerbose(1, "Service already exists, just updating the service config.\n");236 VGSvcVerbose(1, "Service already exists, just updating the service config.\n"); 237 237 hService = OpenService(hSCManager, VBOXSERVICE_NAME, SERVICE_ALL_ACCESS); 238 238 if (hService) … … 249 249 NULL, 250 250 VBOXSERVICE_FRIENDLY_NAME)) 251 V BoxServiceVerbose(1, "The service config has been successfully updated.\n");251 VGSvcVerbose(1, "The service config has been successfully updated.\n"); 252 252 else 253 rc = V BoxServiceError("Could not change service config! Error: %ld\n", GetLastError());253 rc = VGSvcError("Could not change service config! Error: %ld\n", GetLastError()); 254 254 } 255 255 else 256 rc = V BoxServiceError("Could not open service! Error: %ld\n", GetLastError());256 rc = VGSvcError("Could not open service! Error: %ld\n", GetLastError()); 257 257 break; 258 258 259 259 default: 260 rc = V BoxServiceError("Could not create service! Error: %ld\n", dwErr);260 rc = VGSvcError("Could not create service! Error: %ld\n", dwErr); 261 261 break; 262 262 } … … 264 264 265 265 if (rc == RTEXITCODE_SUCCESS) 266 rc = v boxServiceWinSetDesc(hService);266 rc = vgsvcWinSetDesc(hService); 267 267 268 268 CloseServiceHandle(hService); … … 274 274 * Uninstalls the service. 275 275 */ 276 RTEXITCODE V BoxServiceWinUninstall(void)277 { 278 V BoxServiceVerbose(1, "Uninstalling service ...\n");276 RTEXITCODE VGSvcWinUninstall(void) 277 { 278 VGSvcVerbose(1, "Uninstalling service ...\n"); 279 279 280 280 SC_HANDLE hSCManager = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS); 281 281 if (hSCManager == NULL) 282 282 { 283 V BoxServiceError("Could not open SCM! Error: %d\n", GetLastError());283 VGSvcError("Could not open SCM! Error: %d\n", GetLastError()); 284 284 return RTEXITCODE_FAILURE; 285 285 } … … 306 306 } 307 307 308 V BoxServiceVerbose(0, "Service successfully uninstalled!\n");308 VGSvcVerbose(0, "Service successfully uninstalled!\n"); 309 309 rcExit = RTEXITCODE_SUCCESS; 310 310 } 311 311 else 312 rcExit = V BoxServiceError("Could not remove service! Error: %d\n", GetLastError());312 rcExit = VGSvcError("Could not remove service! Error: %d\n", GetLastError()); 313 313 CloseServiceHandle(hService); 314 314 } 315 315 else 316 rcExit = V BoxServiceError("Could not open service! Error: %d\n", GetLastError());316 rcExit = VGSvcError("Could not open service! Error: %d\n", GetLastError()); 317 317 CloseServiceHandle(hSCManager); 318 318 … … 321 321 322 322 323 static int v boxServiceWinStart(void)323 static int vgsvcWinStart(void) 324 324 { 325 325 int rc = VINF_SUCCESS; … … 339 339 else 340 340 { 341 DWORD dwRes = v boxServiceWinAddAceToObjectsSecurityDescriptor(TEXT("\\\\.\\VBoxMiniRdrDN"),341 DWORD dwRes = vgsvcWinAddAceToObjectsSecurityDescriptor(TEXT("\\\\.\\VBoxMiniRdrDN"), 342 342 SE_FILE_OBJECT, 343 343 (LPTSTR)pBuiltinUsersSID, … … 363 363 if (RT_SUCCESS(rc)) 364 364 { 365 v boxServiceWinSetStatus(SERVICE_START_PENDING, 0);366 367 rc = V BoxServiceStartServices();365 vgsvcWinSetStatus(SERVICE_START_PENDING, 0); 366 367 rc = VGSvcStartServices(); 368 368 if (RT_SUCCESS(rc)) 369 369 { 370 v boxServiceWinSetStatus(SERVICE_RUNNING, 0);371 V BoxServiceMainWait();370 vgsvcWinSetStatus(SERVICE_RUNNING, 0); 371 VGSvcMainWait(); 372 372 } 373 373 else 374 374 { 375 v boxServiceWinSetStatus(SERVICE_STOPPED, 0);375 vgsvcWinSetStatus(SERVICE_STOPPED, 0); 376 376 #if 0 /** @todo r=bird: Enable this if SERVICE_CONTROL_STOP isn't triggered automatically */ 377 V BoxServiceStopServices();377 VGSvcStopServices(); 378 378 #endif 379 379 } 380 380 } 381 381 else 382 v boxServiceWinSetStatus(SERVICE_STOPPED, 0);382 vgsvcWinSetStatus(SERVICE_STOPPED, 0); 383 383 384 384 if (RT_FAILURE(rc)) 385 V BoxServiceError("Service failed to start with rc=%Rrc!\n", rc);385 VGSvcError("Service failed to start with rc=%Rrc!\n", rc); 386 386 387 387 return rc; … … 398 398 * Something else on failure, error will have been reported. 399 399 */ 400 RTEXITCODE V BoxServiceWinEnterCtrlDispatcher(void)400 RTEXITCODE VGSvcWinEnterCtrlDispatcher(void) 401 401 { 402 402 if (!StartServiceCtrlDispatcher(&g_aServiceTable[0])) 403 return V BoxServiceError("StartServiceCtrlDispatcher: %u. Please start %s with option -f (foreground)!\n",403 return VGSvcError("StartServiceCtrlDispatcher: %u. Please start %s with option -f (foreground)!\n", 404 404 GetLastError(), g_pszProgName); 405 405 return RTEXITCODE_SUCCESS; … … 408 408 409 409 #ifndef TARGET_NT4 410 static const char* v boxServiceWTSStateToString(DWORD dwEvent)410 static const char* vgsvcWTSStateToString(DWORD dwEvent) 411 411 { 412 412 switch (dwEvent) … … 455 455 456 456 #ifdef TARGET_NT4 457 static VOID WINAPI v boxServiceWinCtrlHandler(DWORD dwControl)457 static VOID WINAPI vgsvcWinCtrlHandler(DWORD dwControl) 458 458 #else 459 static DWORD WINAPI v boxServiceWinCtrlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)459 static DWORD WINAPI vgsvcWinCtrlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext) 460 460 #endif 461 461 { … … 463 463 464 464 #ifdef TARGET_NT4 465 V BoxServiceVerbose(2, "Control handler: Control=%#x\n", dwControl);465 VGSvcVerbose(2, "Control handler: Control=%#x\n", dwControl); 466 466 #else 467 V BoxServiceVerbose(2, "Control handler: Control=%#x, EventType=%#x\n", dwControl, dwEventType);467 VGSvcVerbose(2, "Control handler: Control=%#x, EventType=%#x\n", dwControl, dwEventType); 468 468 #endif 469 469 … … 471 471 { 472 472 case SERVICE_CONTROL_INTERROGATE: 473 v boxServiceWinSetStatus(g_dwWinServiceLastStatus, 0);473 vgsvcWinSetStatus(g_dwWinServiceLastStatus, 0); 474 474 break; 475 475 … … 477 477 case SERVICE_CONTROL_SHUTDOWN: 478 478 { 479 v boxServiceWinSetStatus(SERVICE_STOP_PENDING, 0);480 481 int rc2 = V BoxServiceStopServices();479 vgsvcWinSetStatus(SERVICE_STOP_PENDING, 0); 480 481 int rc2 = VGSvcStopServices(); 482 482 if (RT_FAILURE(rc2)) 483 483 rcRet = ERROR_GEN_FAILURE; 484 484 else 485 485 { 486 rc2 = V BoxServiceReportStatus(VBoxGuestFacilityStatus_Terminated);486 rc2 = VGSvcReportStatus(VBoxGuestFacilityStatus_Terminated); 487 487 AssertRC(rc2); 488 488 } 489 489 490 v boxServiceWinSetStatus(SERVICE_STOPPED, 0);490 vgsvcWinSetStatus(SERVICE_STOPPED, 0); 491 491 break; 492 492 } … … 499 499 Assert(pNotify->cbSize == sizeof(WTSSESSION_NOTIFICATION)); 500 500 501 V BoxServiceVerbose(1, "Control handler: %s (Session=%ld, Event=%#x)\n",502 v boxServiceWTSStateToString(dwEventType),501 VGSvcVerbose(1, "Control handler: %s (Session=%ld, Event=%#x)\n", 502 vgsvcWTSStateToString(dwEventType), 503 503 pNotify->dwSessionId, dwEventType); 504 504 505 505 /* Handle all events, regardless of dwEventType. */ 506 int rc2 = V BoxServiceVMInfoSignal();506 int rc2 = VGSvcVMInfoSignal(); 507 507 AssertRC(rc2); 508 508 break; … … 511 511 512 512 default: 513 V BoxServiceVerbose(1, "Control handler: Function not implemented: %#x\n", dwControl);513 VGSvcVerbose(1, "Control handler: Function not implemented: %#x\n", dwControl); 514 514 rcRet = ERROR_CALL_NOT_IMPLEMENTED; 515 515 break; … … 522 522 523 523 524 static void WINAPI v boxServiceWinMain(DWORD argc, LPTSTR *argv)525 { 526 V BoxServiceVerbose(2, "Registering service control handler ...\n");524 static void WINAPI vgsvcWinMain(DWORD argc, LPTSTR *argv) 525 { 526 VGSvcVerbose(2, "Registering service control handler ...\n"); 527 527 #ifdef TARGET_NT4 528 g_hWinServiceStatus = RegisterServiceCtrlHandler(VBOXSERVICE_NAME, v boxServiceWinCtrlHandler);528 g_hWinServiceStatus = RegisterServiceCtrlHandler(VBOXSERVICE_NAME, vgsvcWinCtrlHandler); 529 529 #else 530 g_hWinServiceStatus = RegisterServiceCtrlHandlerEx(VBOXSERVICE_NAME, v boxServiceWinCtrlHandler, NULL);530 g_hWinServiceStatus = RegisterServiceCtrlHandlerEx(VBOXSERVICE_NAME, vgsvcWinCtrlHandler, NULL); 531 531 #endif 532 532 if (g_hWinServiceStatus != NULL) 533 533 { 534 V BoxServiceVerbose(2, "Service control handler registered.\n");535 v boxServiceWinStart();534 VGSvcVerbose(2, "Service control handler registered.\n"); 535 vgsvcWinStart(); 536 536 } 537 537 else … … 541 541 { 542 542 case ERROR_INVALID_NAME: 543 V BoxServiceError("Invalid service name!\n");543 VGSvcError("Invalid service name!\n"); 544 544 break; 545 545 case ERROR_SERVICE_DOES_NOT_EXIST: 546 V BoxServiceError("Service does not exist!\n");546 VGSvcError("Service does not exist!\n"); 547 547 break; 548 548 default: 549 V BoxServiceError("Could not register service control handle! Error: %ld\n", dwErr);549 VGSvcError("Could not register service control handle! Error: %ld\n", dwErr); 550 550 break; 551 551 } -
trunk/src/VBox/Additions/common/VBoxService/VBoxService.cpp
r57966 r58029 141 141 }; 142 142 143 /* Default call-backs for services which do not need special behaviour. */ 144 145 /** @copydoc VBOXSERVICE::pfnPreInit */ 146 DECLCALLBACK(int) VBoxServiceDefaultPreInit(void) 143 144 /* 145 * Default call-backs for services which do not need special behaviour. 146 */ 147 148 /** 149 * @interface_method_impl{VBOXSERVICE,pfnPreInit, Default Implementation} 150 */ 151 DECLCALLBACK(int) VGSvcDefaultPreInit(void) 147 152 { 148 153 return VINF_SUCCESS; 149 154 } 150 155 151 /** @copydoc VBOXSERVICE::pfnOption */ 152 DECLCALLBACK(int) VBoxServiceDefaultOption(const char **ppszShort, int argc, 156 157 /** 158 * @interface_method_impl{VBOXSERVICE,pfnOption, Default Implementation} 159 */ 160 DECLCALLBACK(int) VGSvcDefaultOption(const char **ppszShort, int argc, 153 161 char **argv, int *pi) 154 162 { … … 161 169 } 162 170 163 /** @copydoc VBOXSERVICE::pfnInit */ 164 DECLCALLBACK(int) VBoxServiceDefaultInit(void) 171 172 /** 173 * @interface_method_impl{VBOXSERVICE,pfnInit, Default Implementation} 174 */ 175 DECLCALLBACK(int) VGSvcDefaultInit(void) 165 176 { 166 177 return VINF_SUCCESS; 167 178 } 168 179 169 /** @copydoc VBOXSERVICE::pfnTerm */ 170 DECLCALLBACK(void) VBoxServiceDefaultTerm(void) 180 181 /** 182 * @interface_method_impl{VBOXSERVICE,pfnTerm, Default Implementation} 183 */ 184 DECLCALLBACK(void) VGSvcDefaultTerm(void) 171 185 { 172 186 return; 173 187 } 174 188 175 /** 176 * Release logger callback. 177 * 178 * @return IPRT status code. 179 * @param pLoggerRelease 180 * @param enmPhase 181 * @param pfnLog 182 */ 183 static DECLCALLBACK(void) VBoxServiceLogHeaderFooter(PRTLOGGER pLoggerRelease, RTLOGPHASE enmPhase, PFNRTLOGPHASEMSG pfnLog) 189 190 /** 191 * @callback_method_impl{FNRTLOGPHASE, Release logger callback} 192 */ 193 static DECLCALLBACK(void) vgsvcLogHeaderFooter(PRTLOGGER pLoggerRelease, RTLOGPHASE enmPhase, PFNRTLOGPHASEMSG pfnLog) 184 194 { 185 195 /* Some introductory information. */ … … 195 205 { 196 206 pfnLog(pLoggerRelease, 197 "VBoxService %s r%s (verbosity: % d) %s (%s %s) release log\n"207 "VBoxService %s r%s (verbosity: %u) %s (%s %s) release log\n" 198 208 "Log opened %s\n", 199 209 RTBldCfgVersion(), RTBldCfgRevisionStr(), g_cVerbosity, VBOX_BUILD_TARGET, … … 209 219 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) 210 220 pfnLog(pLoggerRelease, "OS Version: %s\n", szTmp); 221 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_SERVICE_PACK, szTmp, sizeof(szTmp)); 211 222 if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) 212 223 pfnLog(pLoggerRelease, "OS Service Pack: %s\n", szTmp); … … 242 253 243 254 default: 244 /* nothing */; 255 /* nothing */ 256 break; 245 257 } 246 258 } … … 249 261 /** 250 262 * Creates the default release logger outputting to the specified file. 251 * Pass NULL for disabled logging. 263 * 264 * Pass NULL to disabled logging. 252 265 * 253 266 * @return IPRT status code. 254 * @param pszLogFile Filename for log output. Optional.255 */ 256 int V BoxServiceLogCreate(const char *pszLogFile)267 * @param pszLogFile Filename for log output. NULL disables logging. 268 */ 269 int VGSvcLogCreate(const char *pszLogFile) 257 270 { 258 271 /* Create release logger (stdout + file). */ … … 271 284 RT_ELEMENTS(s_apszGroups), s_apszGroups, 272 285 RTLOGDEST_STDOUT | RTLOGDEST_USER, 273 VBoxServiceLogHeaderFooter, g_cHistory, g_uHistoryFileSize, g_uHistoryFileTime,286 vgsvcLogHeaderFooter, g_cHistory, g_uHistoryFileSize, g_uHistoryFileTime, 274 287 szError, sizeof(szError), pszLogFile); 275 288 if (RT_SUCCESS(rc)) … … 286 299 287 300 288 void V BoxServiceLogDestroy(void)301 void VGSvcLogDestroy(void) 289 302 { 290 303 RTLogDestroy(RTLogRelSetDefaultInstance(NULL)); … … 297 310 * @returns 1. 298 311 */ 299 static int v boxServiceUsage(void)312 static int vgsvcUsage(void) 300 313 { 301 314 RTPrintf("Usage:\n" … … 349 362 * @param ... Format arguments. 350 363 */ 351 RTEXITCODE V BoxServiceError(const char *pszFormat, ...)364 RTEXITCODE VGSvcError(const char *pszFormat, ...) 352 365 { 353 366 va_list args; … … 373 386 * @param ... Format arguments. 374 387 */ 375 void V BoxServiceVerbose(unsigned iLevel, const char *pszFormat, ...)388 void VGSvcVerbose(unsigned iLevel, const char *pszFormat, ...) 376 389 { 377 390 if (iLevel <= g_cVerbosity) … … 408 421 * @param enmStatus Status to report to the host. 409 422 */ 410 int V BoxServiceReportStatus(VBoxGuestFacilityStatus enmStatus)423 int VGSvcReportStatus(VBoxGuestFacilityStatus enmStatus) 411 424 { 412 425 /* … … 414 427 */ 415 428 static VBoxGuestFacilityStatus s_enmLastStatus = VBoxGuestFacilityStatus_Inactive; 416 V BoxServiceVerbose(4, "Setting VBoxService status to %u\n", enmStatus);429 VGSvcVerbose(4, "Setting VBoxService status to %u\n", enmStatus); 417 430 if (s_enmLastStatus != VBoxGuestFacilityStatus_Failed) 418 431 { … … 421 434 if (RT_FAILURE(rc)) 422 435 { 423 V BoxServiceError("Could not report VBoxService status (%u), rc=%Rrc\n", enmStatus, rc);436 VGSvcError("Could not report VBoxService status (%u), rc=%Rrc\n", enmStatus, rc); 424 437 return rc; 425 438 } … … 432 445 /** 433 446 * Gets a 32-bit value argument. 434 * @todo Get rid of this and V BoxServiceArgString() as soon as we have RTOpt handling.447 * @todo Get rid of this and VGSvcArgString() as soon as we have RTOpt handling. 435 448 * 436 449 * @returns 0 on success, non-zero exit code on error. … … 443 456 * @param u32Max The maximum value. 444 457 */ 445 int V BoxServiceArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32, uint32_t u32Min, uint32_t u32Max)458 int VGSvcArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32, uint32_t u32Min, uint32_t u32Max) 446 459 { 447 460 if (*psz == ':' || *psz == '=') … … 464 477 } 465 478 466 /** @todo Get rid of this and VBoxServiceArgUInt32() as soon as we have RTOpt handling. */ 467 int VBoxServiceArgString(int argc, char **argv, const char *psz, int *pi, char *pszBuf, size_t cbBuf) 479 480 /** @todo Get rid of this and VGSvcArgUInt32() as soon as we have RTOpt handling. */ 481 static int vgsvcArgString(int argc, char **argv, const char *psz, int *pi, char *pszBuf, size_t cbBuf) 468 482 { 469 483 AssertPtrReturn(pszBuf, VERR_INVALID_POINTER); … … 485 499 486 500 487 488 501 /** 489 502 * The service thread. … … 493 506 * @param pvUser The service index. 494 507 */ 495 static DECLCALLBACK(int) v boxServiceThread(RTTHREAD ThreadSelf, void *pvUser)508 static DECLCALLBACK(int) vgsvcThread(RTTHREAD ThreadSelf, void *pvUser) 496 509 { 497 510 const unsigned i = (uintptr_t)pvUser; … … 518 531 * @returns VBox status code, error message displayed. 519 532 */ 520 static RTEXITCODE v boxServiceLazyPreInit(void)533 static RTEXITCODE vgsvcLazyPreInit(void) 521 534 { 522 535 for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++) … … 525 538 int rc = g_aServices[j].pDesc->pfnPreInit(); 526 539 if (RT_FAILURE(rc)) 527 return V BoxServiceError("Service '%s' failed pre-init: %Rrc\n", g_aServices[j].pDesc->pszName, rc);540 return VGSvcError("Service '%s' failed pre-init: %Rrc\n", g_aServices[j].pDesc->pszName, rc); 528 541 g_aServices[j].fPreInited = true; 529 542 } … … 535 548 * Count the number of enabled services. 536 549 */ 537 static unsigned v boxServiceCountEnabledServices(void)550 static unsigned vgsvcCountEnabledServices(void) 538 551 { 539 552 unsigned cEnabled = 0; … … 545 558 546 559 #ifdef RT_OS_WINDOWS 547 static BOOL WINAPI VBoxServiceConsoleControlHandler(DWORD dwCtrlType) 560 /** 561 * Console control event callback. 562 * 563 * @returns TRUE if handled, FALSE if not. 564 * @param dwCtrlType The control event type. 565 * 566 * @remarks This is generally called on a new thread, so we're racing every 567 * other thread in the process. 568 */ 569 static BOOL WINAPI vgsvcWinConsoleControlHandler(DWORD dwCtrlType) 548 570 { 549 571 int rc = VINF_SUCCESS; … … 556 578 case CTRL_CLOSE_EVENT: 557 579 case CTRL_C_EVENT: 558 V BoxServiceVerbose(2, "ControlHandler: Received break/close event\n");559 rc = V BoxServiceStopServices();580 VGSvcVerbose(2, "ControlHandler: Received break/close event\n"); 581 rc = VGSvcStopServices(); 560 582 fEventHandled = TRUE; 561 583 break; … … 566 588 567 589 if (RT_FAILURE(rc)) 568 V BoxServiceError("ControlHandler: Event %ld handled with error rc=%Rrc\n",590 VGSvcError("ControlHandler: Event %ld handled with error rc=%Rrc\n", 569 591 dwCtrlType, rc); 570 592 return fEventHandled; … … 577 599 * 578 600 * @returns VBox status code, errors are fully bitched. 579 */ 580 int VBoxServiceStartServices(void) 601 * 602 * @remarks Also called from VBoxService-win.cpp, thus not static. 603 */ 604 int VGSvcStartServices(void) 581 605 { 582 606 int rc; 583 607 584 V BoxServiceReportStatus(VBoxGuestFacilityStatus_Init);608 VGSvcReportStatus(VBoxGuestFacilityStatus_Init); 585 609 586 610 /* 587 611 * Initialize the services. 588 612 */ 589 V BoxServiceVerbose(2, "Initializing services ...\n");613 VGSvcVerbose(2, "Initializing services ...\n"); 590 614 for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++) 591 615 if (g_aServices[j].fEnabled) … … 596 620 if (rc != VERR_SERVICE_DISABLED) 597 621 { 598 V BoxServiceError("Service '%s' failed to initialize: %Rrc\n",622 VGSvcError("Service '%s' failed to initialize: %Rrc\n", 599 623 g_aServices[j].pDesc->pszName, rc); 600 V BoxServiceReportStatus(VBoxGuestFacilityStatus_Failed);624 VGSvcReportStatus(VBoxGuestFacilityStatus_Failed); 601 625 return rc; 602 626 } 603 627 g_aServices[j].fEnabled = false; 604 VBoxServiceVerbose(0, "Service '%s' was disabled because of missing functionality\n", 605 g_aServices[j].pDesc->pszName); 628 VGSvcVerbose(0, "Service '%s' was disabled because of missing functionality\n", g_aServices[j].pDesc->pszName); 606 629 607 630 } … … 611 634 * Start the service(s). 612 635 */ 613 V BoxServiceVerbose(2, "Starting services ...\n");636 VGSvcVerbose(2, "Starting services ...\n"); 614 637 rc = VINF_SUCCESS; 615 638 for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++) … … 618 641 continue; 619 642 620 V BoxServiceVerbose(2, "Starting service '%s' ...\n", g_aServices[j].pDesc->pszName);621 rc = RTThreadCreate(&g_aServices[j].Thread, v boxServiceThread, (void *)(uintptr_t)j, 0,643 VGSvcVerbose(2, "Starting service '%s' ...\n", g_aServices[j].pDesc->pszName); 644 rc = RTThreadCreate(&g_aServices[j].Thread, vgsvcThread, (void *)(uintptr_t)j, 0, 622 645 RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, g_aServices[j].pDesc->pszName); 623 646 if (RT_FAILURE(rc)) 624 647 { 625 V BoxServiceError("RTThreadCreate failed, rc=%Rrc\n", rc);648 VGSvcError("RTThreadCreate failed, rc=%Rrc\n", rc); 626 649 break; 627 650 } … … 642 665 if (g_aServices[j].fShutdown) 643 666 { 644 V BoxServiceError("Service '%s' failed to start!\n", g_aServices[j].pDesc->pszName);667 VGSvcError("Service '%s' failed to start!\n", g_aServices[j].pDesc->pszName); 645 668 rc = VERR_GENERAL_FAILURE; 646 669 } … … 648 671 649 672 if (RT_SUCCESS(rc)) 650 V BoxServiceVerbose(1, "All services started.\n");673 VGSvcVerbose(1, "All services started.\n"); 651 674 else 652 675 { 653 V BoxServiceError("An error occcurred while the services!\n");654 V BoxServiceReportStatus(VBoxGuestFacilityStatus_Failed);676 VGSvcError("An error occcurred while the services!\n"); 677 VGSvcReportStatus(VBoxGuestFacilityStatus_Failed); 655 678 } 656 679 return rc; … … 663 686 * This should be called even when VBoxServiceStartServices fails so it can 664 687 * clean up anything that we succeeded in starting. 665 */ 666 int VBoxServiceStopServices(void) 667 { 668 VBoxServiceReportStatus(VBoxGuestFacilityStatus_Terminating); 688 * 689 * @remarks Also called from VBoxService-win.cpp, thus not static. 690 */ 691 int VGSvcStopServices(void) 692 { 693 VGSvcReportStatus(VBoxGuestFacilityStatus_Terminating); 669 694 670 695 /* … … 680 705 if (g_aServices[j].fStarted) 681 706 { 682 V BoxServiceVerbose(3, "Calling stop function for service '%s' ...\n", g_aServices[j].pDesc->pszName);707 VGSvcVerbose(3, "Calling stop function for service '%s' ...\n", g_aServices[j].pDesc->pszName); 683 708 g_aServices[j].pDesc->pfnStop(); 684 709 } 685 710 686 V BoxServiceVerbose(3, "All stop functions for services called\n");711 VGSvcVerbose(3, "All stop functions for services called\n"); 687 712 688 713 /* … … 696 721 if (g_aServices[j].Thread != NIL_RTTHREAD) 697 722 { 698 V BoxServiceVerbose(2, "Waiting for service '%s' to stop ...\n", g_aServices[j].pDesc->pszName);723 VGSvcVerbose(2, "Waiting for service '%s' to stop ...\n", g_aServices[j].pDesc->pszName); 699 724 int rc2 = VINF_SUCCESS; 700 725 for (int i = 0; i < 30; i++) /* Wait 30 seconds in total */ … … 705 730 #ifdef RT_OS_WINDOWS 706 731 /* Notify SCM that it takes a bit longer ... */ 707 V BoxServiceWinSetStopPendingStatus(i + j*32);732 VGSvcWinSetStopPendingStatus(i + j*32); 708 733 #endif 709 734 } 710 735 if (RT_FAILURE(rc2)) 711 736 { 712 V BoxServiceError("Service '%s' failed to stop. (%Rrc)\n", g_aServices[j].pDesc->pszName, rc2);737 VGSvcError("Service '%s' failed to stop. (%Rrc)\n", g_aServices[j].pDesc->pszName, rc2); 713 738 rc = rc2; 714 739 } 715 740 } 716 V BoxServiceVerbose(3, "Terminating service '%s' (%d) ...\n", g_aServices[j].pDesc->pszName, j);741 VGSvcVerbose(3, "Terminating service '%s' (%d) ...\n", g_aServices[j].pDesc->pszName, j); 717 742 g_aServices[j].pDesc->pfnTerm(); 718 743 } … … 726 751 if (g_hEvtWindowsService != NIL_RTSEMEVENT) 727 752 { 728 V BoxServiceVerbose(3, "Stopping the main thread...\n");753 VGSvcVerbose(3, "Stopping the main thread...\n"); 729 754 int rc2 = RTSemEventSignal(g_hEvtWindowsService); 730 755 AssertRC(rc2); … … 732 757 #endif 733 758 734 V BoxServiceVerbose(2, "Stopping services returning: %Rrc\n", rc);735 V BoxServiceReportStatus(RT_SUCCESS(rc) ? VBoxGuestFacilityStatus_Paused : VBoxGuestFacilityStatus_Failed);759 VGSvcVerbose(2, "Stopping services returning: %Rrc\n", rc); 760 VGSvcReportStatus(RT_SUCCESS(rc) ? VBoxGuestFacilityStatus_Paused : VBoxGuestFacilityStatus_Failed); 736 761 return rc; 737 762 } … … 740 765 /** 741 766 * Block the main thread until the service shuts down. 742 */ 743 void VBoxServiceMainWait(void) 767 * 768 * @remarks Also called from VBoxService-win.cpp, thus not static. 769 */ 770 void VGSvcMainWait(void) 744 771 { 745 772 int rc; 746 773 747 V BoxServiceReportStatus(VBoxGuestFacilityStatus_Active);774 VGSvcReportStatus(VBoxGuestFacilityStatus_Active); 748 775 749 776 #ifdef RT_OS_WINDOWS … … 751 778 * Wait for the semaphore to be signalled. 752 779 */ 753 V BoxServiceVerbose(1, "Waiting in main thread\n");780 VGSvcVerbose(1, "Waiting in main thread\n"); 754 781 rc = RTSemEventCreate(&g_hEvtWindowsService); 755 782 AssertRC(rc); … … 790 817 ); 791 818 792 V BoxServiceVerbose(3, "VBoxServiceMainWait: Received signal %d (rc=%d)\n", iSignal, rc);819 VGSvcVerbose(3, "VBoxServiceMainWait: Received signal %d (rc=%d)\n", iSignal, rc); 793 820 #endif /* !RT_OS_WINDOWS */ 794 821 } … … 818 845 * global mutex restrictions. 819 846 */ 820 if (V BoxServiceToolboxMain(argc, argv, &rcExit))847 if (VGSvcToolboxMain(argc, argv, &rcExit)) 821 848 return rcExit; 822 849 #endif … … 843 870 else 844 871 rc = VbglR3Init(); 845 846 872 if (RT_FAILURE(rc)) 847 873 { … … 855 881 /* 856 882 * Check if we're the specially spawned VBoxService.exe process that 857 * handles page fusion. This saves an extra executable.883 * handles page fusion. This saves an extra statically linked executable. 858 884 */ 859 885 if ( argc == 2 860 886 && !RTStrICmp(argv[1], "pagefusion")) 861 return V BoxServicePageSharingWorkerChild();887 return VGSvcPageSharingWorkerChild(); 862 888 #endif 863 889 … … 868 894 */ 869 895 if (fUserSession) 870 return V BoxServiceControlSessionSpawnInit(argc, argv);896 return VGSvcGstCtrlSessionSpawnInit(argc, argv); 871 897 #endif 872 898 … … 941 967 if (!fFound) 942 968 { 943 rcExit = v boxServiceLazyPreInit();969 rcExit = vgsvcLazyPreInit(); 944 970 if (rcExit != RTEXITCODE_SUCCESS) 945 971 return rcExit; … … 967 993 { 968 994 case 'i': 969 rc = V BoxServiceArgUInt32(argc, argv, psz + 1, &i,995 rc = VGSvcArgUInt32(argc, argv, psz + 1, &i, 970 996 &g_DefaultInterval, 1, (UINT32_MAX / 1000) - 1); 971 997 if (rc) … … 988 1014 case 'h': 989 1015 case '?': 990 return v boxServiceUsage();1016 return vgsvcUsage(); 991 1017 992 1018 #ifdef RT_OS_WINDOWS 993 1019 case 'r': 994 return V BoxServiceWinInstall();1020 return VGSvcWinInstall(); 995 1021 996 1022 case 'u': 997 return V BoxServiceWinUninstall();1023 return VGSvcWinUninstall(); 998 1024 #endif 999 1025 1000 1026 case 'l': 1001 1027 { 1002 rc = VBoxServiceArgString(argc, argv, psz + 1, &i,1028 rc = vgsvcArgString(argc, argv, psz + 1, &i, 1003 1029 g_szLogFile, sizeof(g_szLogFile)); 1004 1030 if (rc) … … 1010 1036 case 'p': 1011 1037 { 1012 rc = VBoxServiceArgString(argc, argv, psz + 1, &i,1038 rc = vgsvcArgString(argc, argv, psz + 1, &i, 1013 1039 g_szPidFile, sizeof(g_szPidFile)); 1014 1040 if (rc) … … 1020 1046 default: 1021 1047 { 1022 rcExit = v boxServiceLazyPreInit();1048 rcExit = vgsvcLazyPreInit(); 1023 1049 if (rcExit != RTEXITCODE_SUCCESS) 1024 1050 return rcExit; … … 1043 1069 1044 1070 /* Check that at least one service is enabled. */ 1045 if (v boxServiceCountEnabledServices() == 0)1071 if (vgsvcCountEnabledServices() == 0) 1046 1072 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "At least one service must be enabled\n"); 1047 1073 1048 rc = V BoxServiceLogCreate(strlen(g_szLogFile)? g_szLogFile : NULL);1074 rc = VGSvcLogCreate(g_szLogFile[0] ? g_szLogFile : NULL); 1049 1075 if (RT_FAILURE(rc)) 1050 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to create release log \"%s\", rc=%Rrc\n",1051 strlen(g_szLogFile)? g_szLogFile : "<None>", rc);1076 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to create release log '%s', rc=%Rrc\n", 1077 g_szLogFile[0] ? g_szLogFile : "<None>", rc); 1052 1078 1053 1079 /* Call pre-init if we didn't do it already. */ 1054 rcExit = v boxServiceLazyPreInit();1080 rcExit = vgsvcLazyPreInit(); 1055 1081 if (rcExit != RTEXITCODE_SUCCESS) 1056 1082 return rcExit; … … 1084 1110 || dwErr == ERROR_ACCESS_DENIED) 1085 1111 { 1086 V BoxServiceError("%s is already running! Terminating.\n", g_pszProgName);1112 VGSvcError("%s is already running! Terminating.\n", g_pszProgName); 1087 1113 return RTEXITCODE_FAILURE; 1088 1114 } 1089 1115 1090 V BoxServiceError("CreateMutex failed with last error %u! Terminating.\n", GetLastError());1116 VGSvcError("CreateMutex failed with last error %u! Terminating.\n", GetLastError()); 1091 1117 return RTEXITCODE_FAILURE; 1092 1118 } … … 1096 1122 #endif /* !RT_OS_WINDOWS */ 1097 1123 1098 VBoxServiceVerbose(0, "%s r%s started. Verbose level = %d\n", 1099 RTBldCfgVersion(), RTBldCfgRevisionStr(), g_cVerbosity); 1124 VGSvcVerbose(0, "%s r%s started. Verbose level = %d\n", RTBldCfgVersion(), RTBldCfgRevisionStr(), g_cVerbosity); 1100 1125 1101 1126 /* … … 1105 1130 { 1106 1131 #ifdef RT_OS_WINDOWS 1107 V BoxServiceVerbose(2, "Starting service dispatcher ...\n");1108 rcExit = V BoxServiceWinEnterCtrlDispatcher();1132 VGSvcVerbose(2, "Starting service dispatcher ...\n"); 1133 rcExit = VGSvcWinEnterCtrlDispatcher(); 1109 1134 #else 1110 V BoxServiceVerbose(1, "Daemonizing...\n");1135 VGSvcVerbose(1, "Daemonizing...\n"); 1111 1136 rc = VbglR3Daemonize(false /* fNoChDir */, false /* fNoClose */, 1112 1137 false /* fRespawn */, NULL /* pcRespawn */); 1113 1138 if (RT_FAILURE(rc)) 1114 return V BoxServiceError("Daemon failed: %Rrc\n", rc);1139 return VGSvcError("Daemon failed: %Rrc\n", rc); 1115 1140 /* in-child */ 1116 1141 #endif … … 1129 1154 */ 1130 1155 #ifdef RT_OS_WINDOWS 1131 # ifndef RT_OS_NT4 1156 # ifndef RT_OS_NT4 /** @todo r=bird: What's RT_OS_NT4??? */ 1132 1157 /* Install console control handler. */ 1133 if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE) VBoxServiceConsoleControlHandler, TRUE /* Add handler */))1134 { 1135 V BoxServiceError("Unable to add console control handler, error=%ld\n", GetLastError());1158 if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)vgsvcWinConsoleControlHandler, TRUE /* Add handler */)) 1159 { 1160 VGSvcError("Unable to add console control handler, error=%ld\n", GetLastError()); 1136 1161 /* Just skip this error, not critical. */ 1137 1162 } 1138 1163 # endif /* !RT_OS_NT4 */ 1139 1164 #endif /* RT_OS_WINDOWS */ 1140 rc = V BoxServiceStartServices();1165 rc = VGSvcStartServices(); 1141 1166 RTFILE hPidFile = NIL_RTFILE; 1142 1167 if (RT_SUCCESS(rc)) … … 1145 1170 rcExit = RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 1146 1171 if (RT_SUCCESS(rc)) 1147 V BoxServiceMainWait();1172 VGSvcMainWait(); 1148 1173 if (g_szPidFile[0] && hPidFile != NIL_RTFILE) 1149 1174 VbglR3ClosePidFile(g_szPidFile, hPidFile); … … 1153 1178 if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)NULL, FALSE /* Remove handler */)) 1154 1179 { 1155 V BoxServiceError("Unable to remove console control handler, error=%ld\n", GetLastError());1180 VGSvcError("Unable to remove console control handler, error=%ld\n", GetLastError()); 1156 1181 /* Just skip this error, not critical. */ 1157 1182 } … … 1161 1186 * through the console control handler. So only do the stopping of services here on other platforms 1162 1187 * where the break/shutdown/whatever signal was just received. */ 1163 V BoxServiceStopServices();1188 VGSvcStopServices(); 1164 1189 #endif /* RT_OS_WINDOWS */ 1165 1190 } 1166 V BoxServiceReportStatus(VBoxGuestFacilityStatus_Terminated);1191 VGSvcReportStatus(VBoxGuestFacilityStatus_Terminated); 1167 1192 1168 1193 #ifdef RT_OS_WINDOWS … … 1173 1198 #endif 1174 1199 1175 V BoxServiceVerbose(0, "Ended.\n");1200 VGSvcVerbose(0, "Ended.\n"); 1176 1201 1177 1202 #ifdef DEBUG … … 1180 1205 #endif 1181 1206 1182 V BoxServiceLogDestroy();1207 VGSvcLogDestroy(); 1183 1208 1184 1209 return rcExit; -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceAutoMount.cpp
r57358 r58029 1 1 /* $Id$ */ 2 2 /** @file 3 * VBoxService - Auto-mounting for Shared Folders .3 * VBoxService - Auto-mounting for Shared Folders, only Linux & Solaris atm. 4 4 */ 5 5 … … 54 54 55 55 #ifndef _PATH_MOUNTED 56 #ifdef RT_OS_SOLARIS57 #define _PATH_MOUNTED "/etc/mnttab"58 #else59 #define _PATH_MOUNTED "/etc/mtab"60 #endif56 # ifdef RT_OS_SOLARIS 57 # define _PATH_MOUNTED "/etc/mnttab" 58 # else 59 # define _PATH_MOUNTED "/etc/mtab" 60 # endif 61 61 #endif 62 62 … … 71 71 72 72 73 /** @copydoc VBOXSERVICE::pfnInit */ 74 static DECLCALLBACK(int) VBoxServiceAutoMountInit(void) 75 { 76 VBoxServiceVerbose(3, "VBoxServiceAutoMountInit\n"); 73 /** 74 * @interface_method_impl{VBOXSERVICE,pfnInit} 75 */ 76 static DECLCALLBACK(int) vbsvcAutoMountInit(void) 77 { 78 VGSvcVerbose(3, "vbsvcAutoMountInit\n"); 77 79 78 80 int rc = RTSemEventMultiCreate(&g_AutoMountEvent); … … 82 84 if (RT_SUCCESS(rc)) 83 85 { 84 V BoxServiceVerbose(3, "VBoxServiceAutoMountInit: Service Client ID: %#x\n", g_SharedFoldersSvcClientID);86 VGSvcVerbose(3, "vbsvcAutoMountInit: Service Client ID: %#x\n", g_SharedFoldersSvcClientID); 85 87 } 86 88 else … … 90 92 if (rc == VERR_HGCM_SERVICE_NOT_FOUND) /* Host service is not available. */ 91 93 { 92 V BoxServiceVerbose(0, "VBoxServiceAutoMountInit: Shared Folders service is not available\n");94 VGSvcVerbose(0, "vbsvcAutoMountInit: Shared Folders service is not available\n"); 93 95 rc = VERR_SERVICE_DISABLED; 94 96 } 95 97 else 96 V BoxServiceError("Control: Failed to connect to the Shared Folders service! Error: %Rrc\n", rc);98 VGSvcError("Control: Failed to connect to the Shared Folders service! Error: %Rrc\n", rc); 97 99 RTSemEventMultiDestroy(g_AutoMountEvent); 98 100 g_AutoMountEvent = NIL_RTSEMEVENTMULTI; … … 103 105 104 106 105 /** @todo Integrate into RTFsQueryMountpoint(). */ 106 static bool VBoxServiceAutoMountShareIsMounted(const char *pszShare, 107 char *pszMountPoint, size_t cbMountPoint) 107 /** 108 * @todo Integrate into RTFsQueryMountpoint()? 109 */ 110 static bool vbsvcAutoMountShareIsMounted(const char *pszShare, char *pszMountPoint, size_t cbMountPoint) 108 111 { 109 112 AssertPtrReturn(pszShare, VERR_INVALID_PARAMETER); … … 112 115 113 116 bool fMounted = false; 114 /* @todo What to do if we have a relative path in mtab instead117 /** @todo What to do if we have a relative path in mtab instead 115 118 * of an absolute one ("temp" vs. "/media/temp")? 116 119 * procfs contains the full path but not the actual share name ... … … 119 122 FILE *pFh = fopen(_PATH_MOUNTED, "r"); 120 123 if (!pFh) 121 VBoxServiceError("VBoxServiceAutoMountShareIsMounted: Could not open mount tab \"%s\"!\n", 122 _PATH_MOUNTED); 124 VGSvcError("vbsvcAutoMountShareIsMounted: Could not open mount tab '%s'!\n", _PATH_MOUNTED); 123 125 else 124 126 { … … 136 138 } 137 139 #else 138 FILE *pFh = setmntent(_PATH_MOUNTED, "r+t"); 140 FILE *pFh = setmntent(_PATH_MOUNTED, "r+t"); /** @todo r=bird: why open it for writing? (the '+') */ 139 141 if (pFh == NULL) 140 VBoxServiceError("VBoxServiceAutoMountShareIsMounted: Could not open mount tab \"%s\"!\n", 141 _PATH_MOUNTED); 142 VGSvcError("vbsvcAutoMountShareIsMounted: Could not open mount tab '%s'!\n", _PATH_MOUNTED); 142 143 else 143 144 { … … 156 157 #endif 157 158 158 V BoxServiceVerbose(4, "VBoxServiceAutoMountShareIsMounted: Share \"%s\" at mount point \"%s\"= %s\n",159 VGSvcVerbose(4, "vbsvcAutoMountShareIsMounted: Share '%s' at mount point '%s' = %s\n", 159 160 pszShare, fMounted ? pszMountPoint : "<None>", fMounted ? "Yes" : "No"); 160 161 return fMounted; … … 162 163 163 164 164 static int VBoxServiceAutoMountUnmount(const char *pszMountPoint) 165 /** 166 * Unmounts a shared folder. 167 * 168 * @returns VBox status code 169 * @param pszMountPoint The shared folder mount point. 170 */ 171 static int vbsvcAutoMountUnmount(const char *pszMountPoint) 165 172 { 166 173 AssertPtrReturn(pszMountPoint, VERR_INVALID_PARAMETER); … … 174 181 if (r == 0) 175 182 break; 183 /** @todo r=bird: Why do sleep 5 seconds after the final retry? 184 * May also be a good idea to check for EINVAL or other signs that someone 185 * else have already unmounted the share. */ 176 186 RTThreadSleep(5000); /* Wait a while ... */ 177 187 } 178 if (r == -1) 188 if (r == -1) /** @todo r=bird: RTThreadSleep set errno. */ 179 189 rc = RTErrConvertFromErrno(errno); 180 190 return rc; … … 182 192 183 193 184 static int VBoxServiceAutoMountPrepareMountPoint(const char *pszMountPoint, const char *pszShareName, 185 vbsf_mount_opts *pOpts) 194 /** 195 * Prepares a mount point (create it, set group and mode). 196 * 197 * @returns VBox status code 198 * @param pszMountPoint The mount point. 199 * @param pszShareName Unused. 200 * @param pOpts For getting the group ID. 201 */ 202 static int vbsvcAutoMountPrepareMountPoint(const char *pszMountPoint, const char *pszShareName, vbsf_mount_opts *pOpts) 186 203 { 187 204 AssertPtrReturn(pOpts, VERR_INVALID_PARAMETER); … … 201 218 if (rc == VERR_WRITE_PROTECT) 202 219 { 203 VBoxServiceVerbose(3, "VBoxServiceAutoMountPrepareMountPoint: Mount directory \"%s\" already is used/mounted\n", pszMountPoint); 220 VGSvcVerbose(3, "vbsvcAutoMountPrepareMountPoint: Mount directory '%s' already is used/mounted\n", 221 pszMountPoint); 204 222 rc = VINF_SUCCESS; 205 223 } 206 224 else 207 V BoxServiceError("VBoxServiceAutoMountPrepareMountPoint: Could not set mode %RTfmode for mount directory \"%s\", rc = %Rrc\n",225 VGSvcError("vbsvcAutoMountPrepareMountPoint: Could not set mode %RTfmode for mount directory '%s', rc = %Rrc\n", 208 226 fMode, pszMountPoint, rc); 209 227 } 210 228 } 211 229 else 212 V BoxServiceError("VBoxServiceAutoMountPrepareMountPoint: Could not set permissions for mount directory \"%s\", rc = %Rrc\n",230 VGSvcError("vbsvcAutoMountPrepareMountPoint: Could not set permissions for mount directory '%s', rc = %Rrc\n", 213 231 pszMountPoint, rc); 214 232 } 215 233 else 216 V BoxServiceError("VBoxServiceAutoMountPrepareMountPoint: Could not create mount directory \"%s\"with mode %RTfmode, rc = %Rrc\n",234 VGSvcError("vbsvcAutoMountPrepareMountPoint: Could not create mount directory '%s' with mode %RTfmode, rc = %Rrc\n", 217 235 pszMountPoint, fMode, rc); 218 236 return rc; … … 220 238 221 239 222 static int VBoxServiceAutoMountSharedFolder(const char *pszShareName, const char *pszMountPoint, 223 vbsf_mount_opts *pOpts) 240 /** 241 * Mounts a shared folder. 242 * 243 * @returns VBox status code reflecting unmount and mount point preparation 244 * results, but not actual mounting 245 * 246 * @param pszShareName The shared folder name. 247 * @param pszMountPoint The mount point. 248 * @param pOpts The mount options. 249 */ 250 static int vbsvcAutoMountSharedFolder(const char *pszShareName, const char *pszMountPoint, struct vbsf_mount_opts *pOpts) 224 251 { 225 252 AssertPtr(pOpts); 226 253 227 254 int rc = VINF_SUCCESS; 255 bool fSkip = false; 256 257 /* Already mounted? */ 228 258 char szAlreadyMountedTo[RTPATH_MAX]; 229 bool fSkip = false; 230 231 /* Already mounted? */ 232 if (VBoxServiceAutoMountShareIsMounted(pszShareName, szAlreadyMountedTo, sizeof(szAlreadyMountedTo))) 259 if (vbsvcAutoMountShareIsMounted(pszShareName, szAlreadyMountedTo, sizeof(szAlreadyMountedTo))) 233 260 { 234 261 fSkip = true; … … 236 263 if (RTStrICmp(pszMountPoint, szAlreadyMountedTo)) 237 264 { 238 V BoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Shared folder \"%s\" already mounted to \"%s\", unmounting ...\n",265 VGSvcVerbose(3, "vbsvcAutoMountWorker: Shared folder '%s' already mounted to '%s', unmounting ...\n", 239 266 pszShareName, szAlreadyMountedTo); 240 rc = VBoxServiceAutoMountUnmount(szAlreadyMountedTo); 241 if (RT_FAILURE(rc)) 242 VBoxServiceError("VBoxServiceAutoMountWorker: Failed to unmount \"%s\", %s (%d)!\n", 243 szAlreadyMountedTo, strerror(errno), errno); 267 rc = vbsvcAutoMountUnmount(szAlreadyMountedTo); 268 if (RT_SUCCESS(rc)) 269 fSkip = false; 244 270 else 245 fSkip = false; 271 VGSvcError("vbsvcAutoMountWorker: Failed to unmount '%s', %s (%d)! (rc=%Rrc)\n", 272 szAlreadyMountedTo, strerror(errno), errno, rc); /** @todo errno isn't reliable at this point */ 246 273 } 247 274 if (fSkip) 248 V BoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Shared folder \"%s\" already mounted to \"%s\", skipping\n",275 VGSvcVerbose(3, "vbsvcAutoMountWorker: Shared folder '%s' already mounted to '%s', skipping\n", 249 276 pszShareName, szAlreadyMountedTo); 250 277 } 251 278 252 279 if (!fSkip && RT_SUCCESS(rc)) 253 rc = VBoxServiceAutoMountPrepareMountPoint(pszMountPoint, pszShareName, pOpts);280 rc = vbsvcAutoMountPrepareMountPoint(pszMountPoint, pszShareName, pOpts); 254 281 if (!fSkip && RT_SUCCESS(rc)) 255 282 { 256 283 #ifdef RT_OS_SOLARIS 257 char achOptBuf[MAX_MNTOPT_STR] = { '\0', };258 int f lags = 0;284 char szOptBuf[MAX_MNTOPT_STR] = { '\0', }; 285 int fFlags = 0; 259 286 if (pOpts->ronly) 260 f lags |= MS_RDONLY;261 RTStrPrintf( achOptBuf, sizeof(achOptBuf), "uid=%d,gid=%d,dmode=%0o,fmode=%0o,dmask=%0o,fmask=%0o",287 fFlags |= MS_RDONLY; 288 RTStrPrintf(szOptBuf, sizeof(szOptBuf), "uid=%d,gid=%d,dmode=%0o,fmode=%0o,dmask=%0o,fmask=%0o", 262 289 pOpts->uid, pOpts->gid, pOpts->dmode, pOpts->fmode, pOpts->dmask, pOpts->fmask); 263 290 int r = mount(pszShareName, 264 291 pszMountPoint, 265 f lags | MS_OPTIONSTR,292 fFlags | MS_OPTIONSTR, 266 293 "vboxfs", 267 294 NULL, /* char *dataptr */ 268 295 0, /* int datalen */ 269 achOptBuf,270 sizeof( achOptBuf));296 szOptBuf, 297 sizeof(szOptBuf)); 271 298 if (r == 0) 272 { 273 VBoxServiceVerbose(0, "VBoxServiceAutoMountWorker: Shared folder \"%s\" was mounted to \"%s\"\n", pszShareName, pszMountPoint); 274 } 275 else 276 { 277 if (errno != EBUSY) /* Share is already mounted? Then skip error msg. */ 278 VBoxServiceError("VBoxServiceAutoMountWorker: Could not mount shared folder \"%s\" to \"%s\", error = %s\n", 279 pszShareName, pszMountPoint, strerror(errno)); 280 } 281 #else /* !RT_OS_SOLARIS */ 282 unsigned long flags = MS_NODEV; 299 VGSvcVerbose(0, "vbsvcAutoMountWorker: Shared folder '%s' was mounted to '%s'\n", pszShareName, pszMountPoint); 300 else if (errno != EBUSY) /* Share is already mounted? Then skip error msg. */ 301 VGSvcError("vbsvcAutoMountWorker: Could not mount shared folder '%s' to '%s', error = %s\n", 302 pszShareName, pszMountPoint, strerror(errno)); 303 304 #elif defined(RT_OS_LINUX) 305 unsigned long fFlags = MS_NODEV; 283 306 284 307 const char *szOptions = { "rw" }; … … 305 328 pszMountPoint, 306 329 "vboxsf", 307 f lags,330 fFlags, 308 331 &mntinf); 309 332 if (r == 0) 310 333 { 311 VBoxServiceVerbose(0, "VBoxServiceAutoMountWorker: Shared folder \"%s\" was mounted to \"%s\"\n", pszShareName, pszMountPoint); 334 VGSvcVerbose(0, "vbsvcAutoMountWorker: Shared folder '%s' was mounted to '%s'\n", 335 pszShareName, pszMountPoint); 312 336 313 337 r = vbsfmount_complete(pszShareName, pszMountPoint, flags, pOpts); … … 319 343 320 344 case 1: 321 VBoxServiceError("VBoxServiceAutoMountWorker: Could not update mount table (failed to create memstream): %s\n", strerror(errno)); 345 VGSvcError("vbsvcAutoMountWorker: Could not update mount table (failed to create memstream): %s\n", 346 strerror(errno)); 322 347 break; 323 348 324 349 case 2: 325 V BoxServiceError("VBoxServiceAutoMountWorker: Could not open mount table for update: %s\n", strerror(errno));350 VGSvcError("vbsvcAutoMountWorker: Could not open mount table for update: %s\n", strerror(errno)); 326 351 break; 327 352 328 353 case 3: 329 /* V BoxServiceError("VBoxServiceAutoMountWorker: Could not add an entry to the mount table: %s\n", strerror(errno)); */354 /* VGSvcError("vbsvcAutoMountWorker: Could not add an entry to the mount table: %s\n", strerror(errno)); */ 330 355 errno = 0; 331 356 break; 332 357 333 358 default: 334 V BoxServiceError("VBoxServiceAutoMountWorker: Unknown error while completing mount operation: %d\n", r);359 VGSvcError("vbsvcAutoMountWorker: Unknown error while completing mount operation: %d\n", r); 335 360 break; 336 361 } … … 340 365 if (errno == EPROTO) 341 366 { 342 VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Messed up share name, re-trying ...\n"); 367 VGSvcVerbose(3, "vbsvcAutoMountWorker: Messed up share name, re-trying ...\n"); 368 369 /** @todo r=bird: What on earth is going on here????? Why can't you 370 * strcpy(mntinf.name, pszShareName) to fix it again? */ 343 371 344 372 /* Sometimes the mount utility messes up the share name. Try to 345 373 * un-mangle it again. */ 346 char szCWD[ 4096];374 char szCWD[RTPATH_MAX]; 347 375 size_t cchCWD; 348 376 if (!getcwd(szCWD, sizeof(szCWD))) 349 VBoxServiceError("VBoxServiceAutoMountWorker: Failed to get the current working directory\n"); 377 { 378 VGSvcError("vbsvcAutoMountWorker: Failed to get the current working directory\n"); 379 szCWD[0] = '\0'; 380 } 350 381 cchCWD = strlen(szCWD); 351 382 if (!strncmp(pszMountPoint, szCWD, cchCWD)) … … 360 391 if (errno == EPROTO) 361 392 { 362 V BoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Re-trying with old mounting structure ...\n");393 VGSvcVerbose(3, "vbsvcAutoMountWorker: Re-trying with old mounting structure ...\n"); 363 394 364 395 /* New mount tool with old vboxsf module? Try again using the old … … 379 410 * mount point. */ 380 411 case EINVAL: 381 V BoxServiceVerbose(0, "VBoxServiceAutoMountWorker: Shared folder \"%s\"already is mounted!\n", pszShareName);412 VGSvcVerbose(0, "vbsvcAutoMountWorker: Shared folder '%s' already is mounted!\n", pszShareName); 382 413 /* Ignore this error! */ 383 414 break; … … 387 418 388 419 default: 389 V BoxServiceError("VBoxServiceAutoMountWorker: Could not mount shared folder \"%s\" to \"%s\": %s (%d)\n",420 VGSvcError("vbsvcAutoMountWorker: Could not mount shared folder '%s' to '%s': %s (%d)\n", 390 421 pszShareName, pszMountPoint, strerror(errno), errno); 391 422 rc = RTErrConvertFromErrno(errno); … … 394 425 } 395 426 } 396 #endif /* !RT_OS_SOLARIS */ 397 } 398 VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Mounting returned with rc=%Rrc\n", rc); 427 #else 428 # error "PORTME" 429 #endif 430 } 431 VGSvcVerbose(3, "vbsvcAutoMountWorker: Mounting returned with rc=%Rrc\n", rc); 399 432 return rc; 400 433 } 401 434 402 static int VBoxServiceAutoMountProcessMappings(PVBGLR3SHAREDFOLDERMAPPING paMappings, uint32_t cMappings, 403 const char *pszMountDir, const char *pszSharePrefix, uint32_t uClientID) 435 436 /** 437 * Processes shared folder mappings retrieved from the host. 438 * 439 * @returns VBox status code. 440 * @param paMappings The mappings. 441 * @param cMappings The number of mappings. 442 * @param pszMountDir The mount directory. 443 * @param pszSharePrefix The share prefix. 444 * @param uClientID The shared folder service (HGCM) client ID. 445 */ 446 static int vbsvcAutoMountProcessMappings(PCVBGLR3SHAREDFOLDERMAPPING paMappings, uint32_t cMappings, 447 const char *pszMountDir, const char *pszSharePrefix, uint32_t uClientID) 404 448 { 405 449 if (cMappings == 0) … … 410 454 AssertReturn(uClientID > 0, VERR_INVALID_PARAMETER); 411 455 456 /** @todo r=bird: Why is this loop schitzoid about status codes? It quits if 457 * RTPathJoin fails (i.e. if the user specifies a very long name), but happily 458 * continues if RTStrAPrintf failes (mem alloc). 459 * 460 * It also happily continues if the 'vboxsf' group is missing, which is a waste 461 * of effort... In fact, retrieving the group ID could probably be done up 462 * front, outside the loop. */ 412 463 int rc = VINF_SUCCESS; 413 464 for (uint32_t i = 0; i < cMappings && RT_SUCCESS(rc); i++) … … 418 469 && *pszShareName) 419 470 { 420 VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Connecting share %u (%s) ...\n", i+1, pszShareName); 421 471 VGSvcVerbose(3, "vbsvcAutoMountWorker: Connecting share %u (%s) ...\n", i+1, pszShareName); 472 473 /** @todo r=bird: why do you copy things twice here and waste heap space? 474 * szMountPoint has a fixed size. 475 * @code 476 * char szMountPoint[RTPATH_MAX]; 477 * rc = RTPathJoin(szMountPoint, sizeof(szMountPoint), pszMountDir, *pszSharePrefix ? pszSharePrefix : pszShareName); 478 * if (RT_SUCCESS(rc) && *pszSharePrefix) 479 * rc = RTStrCat(szMountPoint, sizeof(szMountPoint), pszShareName); 480 * @endcode */ 422 481 char *pszShareNameFull = NULL; 423 482 if (RTStrAPrintf(&pszShareNameFull, "%s%s", pszSharePrefix, pszShareName) > 0) … … 427 486 if (RT_SUCCESS(rc)) 428 487 { 429 V BoxServiceVerbose(4, "VBoxServiceAutoMountWorker: Processing mount point \"%s\"\n", szMountPoint);488 VGSvcVerbose(4, "vbsvcAutoMountWorker: Processing mount point '%s'\n", szMountPoint); 430 489 431 490 struct group *grp_vboxsf = getgrnam("vboxsf"); … … 451 510 }; 452 511 453 rc = VBoxServiceAutoMountSharedFolder(pszShareName, szMountPoint, &mount_opts);512 rc = vbsvcAutoMountSharedFolder(pszShareName, szMountPoint, &mount_opts); 454 513 } 455 514 else 456 V BoxServiceError("VBoxServiceAutoMountWorker: Group \"vboxsf\"does not exist\n");515 VGSvcError("vbsvcAutoMountWorker: Group 'vboxsf' does not exist\n"); 457 516 } 458 517 else 459 V BoxServiceError("VBoxServiceAutoMountWorker: Unable to join mount point/prefix/shrae, rc = %Rrc\n", rc);518 VGSvcError("vbsvcAutoMountWorker: Unable to join mount point/prefix/shrae, rc = %Rrc\n", rc); 460 519 RTStrFree(pszShareNameFull); 461 520 } 462 521 else 463 V BoxServiceError("VBoxServiceAutoMountWorker: Unable to allocate full share name\n");522 VGSvcError("vbsvcAutoMountWorker: Unable to allocate full share name\n"); 464 523 RTStrFree(pszShareName); 465 524 } 466 525 else 467 V BoxServiceError("VBoxServiceAutoMountWorker: Error while getting the shared folder name for root node = %u, rc = %Rrc\n",526 VGSvcError("vbsvcAutoMountWorker: Error while getting the shared folder name for root node = %u, rc = %Rrc\n", 468 527 paMappings[i].u32Root, rc); 469 528 } /* for cMappings. */ … … 472 531 473 532 474 /** @copydoc VBOXSERVICE::pfnWorker */ 475 DECLCALLBACK(int) VBoxServiceAutoMountWorker(bool volatile *pfShutdown) 533 /** 534 * @interface_method_impl{VBOXSERVICE,pfnWorker} 535 */ 536 static DECLCALLBACK(int) vbsvcAutoMountWorker(bool volatile *pfShutdown) 476 537 { 477 538 /* … … 494 555 if (RT_SUCCESS(rc)) 495 556 { 496 V BoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Shared folder mount dir set to \"%s\"\n", pszMountDir);557 VGSvcVerbose(3, "vbsvcAutoMountWorker: Shared folder mount dir set to '%s'\n", pszMountDir); 497 558 498 559 char *pszSharePrefix; … … 500 561 if (RT_SUCCESS(rc)) 501 562 { 502 V BoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Shared folder mount prefix set to \"%s\"\n", pszSharePrefix);563 VGSvcVerbose(3, "vbsvcAutoMountWorker: Shared folder mount prefix set to '%s'\n", pszSharePrefix); 503 564 #ifdef USE_VIRTUAL_SHARES 504 565 /* Check for a fixed/virtual auto-mount share. */ 505 566 if (VbglR3SharedFolderExists(g_SharedFoldersSvcClientID, "vbsfAutoMount")) 506 567 { 507 V BoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Host supports auto-mount root\n");568 VGSvcVerbose(3, "vbsvcAutoMountWorker: Host supports auto-mount root\n"); 508 569 } 509 570 else 510 571 { 511 572 #endif 512 V BoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Got %u shared folder mappings\n", cMappings);513 rc = VBoxServiceAutoMountProcessMappings(paMappings, cMappings, pszMountDir, pszSharePrefix, g_SharedFoldersSvcClientID);573 VGSvcVerbose(3, "vbsvcAutoMountWorker: Got %u shared folder mappings\n", cMappings); 574 rc = vbsvcAutoMountProcessMappings(paMappings, cMappings, pszMountDir, pszSharePrefix, g_SharedFoldersSvcClientID); 514 575 #ifdef USE_VIRTUAL_SHARES 515 576 } … … 518 579 } /* Mount share prefix. */ 519 580 else 520 V BoxServiceError("VBoxServiceAutoMountWorker: Error while getting the shared folder mount prefix, rc = %Rrc\n", rc);581 VGSvcError("vbsvcAutoMountWorker: Error while getting the shared folder mount prefix, rc = %Rrc\n", rc); 521 582 RTStrFree(pszMountDir); 522 583 } 523 584 else 524 V BoxServiceError("VBoxServiceAutoMountWorker: Error while getting the shared folder directory, rc = %Rrc\n", rc);585 VGSvcError("vbsvcAutoMountWorker: Error while getting the shared folder directory, rc = %Rrc\n", rc); 525 586 VbglR3SharedFolderFreeMappings(paMappings); 526 587 } 527 588 else if (RT_FAILURE(rc)) 528 V BoxServiceError("VBoxServiceAutoMountWorker: Error while getting the shared folder mappings, rc = %Rrc\n", rc);589 VGSvcError("vbsvcAutoMountWorker: Error while getting the shared folder mappings, rc = %Rrc\n", rc); 529 590 else 530 V BoxServiceVerbose(3, "VBoxServiceAutoMountWorker: No shared folder mappings found\n");591 VGSvcVerbose(3, "vbsvcAutoMountWorker: No shared folder mappings found\n"); 531 592 532 593 /* … … 534 595 * the semantics of the main thread's start/stop sub-threads handling. 535 596 * 536 * This thread exits so fast while doing its own startup in V BoxServiceStartServices()537 * that this->fShutdown flag is set to true in V BoxServiceThread() before we have the538 * chance to check for a service failure in V BoxServiceStartServices() to indicate597 * This thread exits so fast while doing its own startup in VGSvcStartServices() 598 * that this->fShutdown flag is set to true in VGSvcThread() before we have the 599 * chance to check for a service failure in VGSvcStartServices() to indicate 539 600 * a VBoxService startup error. 540 601 * … … 555 616 g_AutoMountEvent = NIL_RTSEMEVENTMULTI; 556 617 557 V BoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Finished with rc=%Rrc\n", rc);618 VGSvcVerbose(3, "vbsvcAutoMountWorker: Finished with rc=%Rrc\n", rc); 558 619 return VINF_SUCCESS; 559 620 } 560 621 561 /** @copydoc VBOXSERVICE::pfnTerm */ 562 static DECLCALLBACK(void) VBoxServiceAutoMountTerm(void) 563 { 564 VBoxServiceVerbose(3, "VBoxServiceAutoMountTerm\n"); 622 623 /** 624 * @interface_method_impl{VBOXSERVICE,pfnTerm} 625 */ 626 static DECLCALLBACK(void) vbsvcAutoMountTerm(void) 627 { 628 VGSvcVerbose(3, "vbsvcAutoMountTerm\n"); 565 629 566 630 VbglR3SharedFolderDisconnect(g_SharedFoldersSvcClientID); … … 576 640 577 641 578 /** @copydoc VBOXSERVICE::pfnStop */ 579 static DECLCALLBACK(void) VBoxServiceAutoMountStop(void) 642 /** 643 * @interface_method_impl{VBOXSERVICE,pfnStop} 644 */ 645 static DECLCALLBACK(void) vbsvcAutoMountStop(void) 580 646 { 581 647 /* … … 603 669 NULL, 604 670 /* methods */ 605 V BoxServiceDefaultPreInit,606 V BoxServiceDefaultOption,607 VBoxServiceAutoMountInit,608 VBoxServiceAutoMountWorker,609 VBoxServiceAutoMountStop,610 VBoxServiceAutoMountTerm671 VGSvcDefaultPreInit, 672 VGSvcDefaultOption, 673 vbsvcAutoMountInit, 674 vbsvcAutoMountWorker, 675 vbsvcAutoMountStop, 676 vbsvcAutoMountTerm 611 677 }; -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceBalloon.cpp
r57358 r58029 60 60 * Check whether madvise() works. 61 61 */ 62 static void VBoxServiceBalloonInitMadvise(void)62 static void vgsvcBalloonInitMadvise(void) 63 63 { 64 64 #ifdef RT_OS_LINUX … … 77 77 * and protect it against fork() in R0. See also suplibOsPageAlloc(). 78 78 */ 79 static void * VBoxServiceBalloonAllocChunk(void)79 static void *VGSvcBalloonAllocChunk(void) 80 80 { 81 81 size_t cb = VMMDEV_MEMORY_BALLOON_CHUNK_SIZE; … … 126 126 127 127 /** 128 * Free an allocated chunk undoing V BoxServiceBalloonAllocChunk().129 */ 130 static void VBoxServiceBalloonFreeChunk(void *pv)128 * Free an allocated chunk undoing VGSvcBalloonAllocChunk(). 129 */ 130 static void vgsvcBalloonFreeChunk(void *pv) 131 131 { 132 132 char *pu8 = (char*)pv; … … 159 159 * @param cNewChunks The new number of 1MB chunks in the balloon. 160 160 */ 161 static int VBoxServiceBalloonSetUser(uint32_t cNewChunks)161 static int vgsvcBalloonSetUser(uint32_t cNewChunks) 162 162 { 163 163 if (cNewChunks == g_cMemBalloonChunks) 164 164 return VINF_SUCCESS; 165 165 166 V BoxServiceVerbose(3, "VBoxServiceBalloonSetUser: cNewChunks=%u g_cMemBalloonChunks=%u\n", cNewChunks, g_cMemBalloonChunks);166 VGSvcVerbose(3, "VBoxServiceBalloonSetUser: cNewChunks=%u g_cMemBalloonChunks=%u\n", cNewChunks, g_cMemBalloonChunks); 167 167 int rc = VINF_SUCCESS; 168 168 if (cNewChunks > g_cMemBalloonChunks) … … 173 173 for (i = g_cMemBalloonChunks; i < cNewChunks; i++) 174 174 { 175 void *pv = V BoxServiceBalloonAllocChunk();175 void *pv = VGSvcBalloonAllocChunk(); 176 176 if (!pv) 177 177 break; … … 193 193 else 194 194 { 195 VBoxServiceBalloonFreeChunk(pv);195 vgsvcBalloonFreeChunk(pv); 196 196 break; 197 197 } 198 198 } 199 V BoxServiceVerbose(3, "VBoxServiceBalloonSetUser: inflation complete. chunks=%u rc=%d\n", i, rc);199 VGSvcVerbose(3, "VBoxServiceBalloonSetUser: inflation complete. chunks=%u rc=%d\n", i, rc); 200 200 } 201 201 else … … 213 213 RTMemProtect(pv, VMMDEV_MEMORY_BALLOON_CHUNK_SIZE, RTMEM_PROT_READ | RTMEM_PROT_WRITE); 214 214 #endif 215 VBoxServiceBalloonFreeChunk(pv);215 vgsvcBalloonFreeChunk(pv); 216 216 g_pavBalloon[i] = NULL; 217 217 g_cMemBalloonChunks--; … … 219 219 else 220 220 break; 221 V BoxServiceVerbose(3, "VBoxServiceBalloonSetUser: deflation complete. chunks=%u rc=%d\n", i, rc);221 VGSvcVerbose(3, "VBoxServiceBalloonSetUser: deflation complete. chunks=%u rc=%d\n", i, rc); 222 222 } 223 223 } … … 227 227 228 228 229 /** @copydoc VBOXSERVICE::pfnInit */ 230 static DECLCALLBACK(int) VBoxServiceBalloonInit(void) 231 { 232 VBoxServiceVerbose(3, "VBoxServiceBalloonInit\n"); 229 /** 230 * @interface_method_impl{VBOXSERVICE,pfnInit} 231 */ 232 static DECLCALLBACK(int) vgsvcBalloonInit(void) 233 { 234 VGSvcVerbose(3, "VBoxServiceBalloonInit\n"); 233 235 234 236 int rc = RTSemEventMultiCreate(&g_MemBalloonEvent); 235 237 AssertRCReturn(rc, rc); 236 238 237 VBoxServiceBalloonInitMadvise();239 vgsvcBalloonInitMadvise(); 238 240 239 241 g_cMemBalloonChunks = 0; … … 245 247 if (RT_SUCCESS(rc)) 246 248 { 247 V BoxServiceVerbose(3, "MemBalloon: New balloon size %d MB (%s memory)\n",249 VGSvcVerbose(3, "MemBalloon: New balloon size %d MB (%s memory)\n", 248 250 cNewChunks, fHandleInR3 ? "R3" : "R0"); 249 251 if (fHandleInR3) 250 rc = VBoxServiceBalloonSetUser(cNewChunks);252 rc = vgsvcBalloonSetUser(cNewChunks); 251 253 else 252 254 g_cMemBalloonChunks = cNewChunks; … … 263 265 ) 264 266 { 265 V BoxServiceVerbose(0, "MemBalloon: Memory ballooning support is not available\n");267 VGSvcVerbose(0, "MemBalloon: Memory ballooning support is not available\n"); 266 268 rc = VERR_SERVICE_DISABLED; 267 269 } 268 270 else 269 271 { 270 V BoxServiceVerbose(3, "MemBalloon: VbglR3MemBalloonRefresh failed with %Rrc\n", rc);272 VGSvcVerbose(3, "MemBalloon: VbglR3MemBalloonRefresh failed with %Rrc\n", rc); 271 273 rc = VERR_SERVICE_DISABLED; /** @todo Playing safe for now, figure out the exact status codes here. */ 272 274 } … … 285 287 * @param cbPage The page size. 286 288 */ 287 uint32_t V BoxServiceBalloonQueryPages(uint32_t cbPage)289 uint32_t VGSvcBalloonQueryPages(uint32_t cbPage) 288 290 { 289 291 Assert(cbPage > 0); … … 292 294 293 295 294 /** @copydoc VBOXSERVICE::pfnWorker */ 295 DECLCALLBACK(int) VBoxServiceBalloonWorker(bool volatile *pfShutdown) 296 /** 297 * @interface_method_impl{VBOXSERVICE,pfnWorker} 298 */ 299 static DECLCALLBACK(int) vgsvcBalloonWorker(bool volatile *pfShutdown) 296 300 { 297 301 /* Start monitoring of the stat event change event. */ … … 299 303 if (RT_FAILURE(rc)) 300 304 { 301 V BoxServiceVerbose(3, "VBoxServiceBalloonWorker: VbglR3CtlFilterMask failed with %Rrc\n", rc);305 VGSvcVerbose(3, "VBoxServiceBalloonWorker: VbglR3CtlFilterMask failed with %Rrc\n", rc); 302 306 return rc; 303 307 } … … 326 330 if (RT_SUCCESS(rc)) 327 331 { 328 V BoxServiceVerbose(3, "VBoxServiceBalloonWorker: new balloon size %d MB (%s memory)\n",332 VGSvcVerbose(3, "VBoxServiceBalloonWorker: new balloon size %d MB (%s memory)\n", 329 333 cNewChunks, fHandleInR3 ? "R3" : "R0"); 330 334 if (fHandleInR3) 331 335 { 332 rc = VBoxServiceBalloonSetUser(cNewChunks);336 rc = vgsvcBalloonSetUser(cNewChunks); 333 337 if (RT_FAILURE(rc)) 334 338 { 335 V BoxServiceVerbose(3, "VBoxServiceBalloonWorker: failed to set balloon size %d MB (%s memory)\n",339 VGSvcVerbose(3, "VBoxServiceBalloonWorker: failed to set balloon size %d MB (%s memory)\n", 336 340 cNewChunks, fHandleInR3 ? "R3" : "R0"); 337 341 } 338 342 else 339 V BoxServiceVerbose(3, "VBoxServiceBalloonWorker: successfully set requested balloon size %d.\n", cNewChunks);343 VGSvcVerbose(3, "VBoxServiceBalloonWorker: successfully set requested balloon size %d.\n", cNewChunks); 340 344 } 341 345 else … … 343 347 } 344 348 else 345 V BoxServiceVerbose(3, "VBoxServiceBalloonWorker: VbglR3MemBalloonRefresh failed with %Rrc\n", rc);349 VGSvcVerbose(3, "VBoxServiceBalloonWorker: VbglR3MemBalloonRefresh failed with %Rrc\n", rc); 346 350 } 347 351 … … 359 363 if (rc2 != VERR_TIMEOUT && RT_FAILURE(rc2)) 360 364 { 361 V BoxServiceError("VBoxServiceBalloonWorker: RTSemEventMultiWait failed; rc2=%Rrc\n", rc2);365 VGSvcError("VBoxServiceBalloonWorker: RTSemEventMultiWait failed; rc2=%Rrc\n", rc2); 362 366 rc = rc2; 363 367 break; … … 368 372 rc = VbglR3CtlFilterMask(0, VMMDEV_EVENT_BALLOON_CHANGE_REQUEST); 369 373 if (RT_FAILURE(rc)) 370 V BoxServiceVerbose(3, "VBoxServiceBalloonWorker: VbglR3CtlFilterMask failed with %Rrc\n", rc);374 VGSvcVerbose(3, "VBoxServiceBalloonWorker: VbglR3CtlFilterMask failed with %Rrc\n", rc); 371 375 372 376 RTSemEventMultiDestroy(g_MemBalloonEvent); 373 377 g_MemBalloonEvent = NIL_RTSEMEVENTMULTI; 374 378 375 V BoxServiceVerbose(3, "VBoxServiceBalloonWorker: finished mem balloon change request thread\n");379 VGSvcVerbose(3, "VBoxServiceBalloonWorker: finished mem balloon change request thread\n"); 376 380 return 0; 377 381 } 378 382 379 /** @copydoc VBOXSERVICE::pfnStop */ 380 static DECLCALLBACK(void) VBoxServiceBalloonStop(void) 383 384 /** 385 * @interface_method_impl{VBOXSERVICE,pfnStop} 386 */ 387 static DECLCALLBACK(void) vgsvcBalloonStop(void) 381 388 { 382 389 RTSemEventMultiSignal(g_MemBalloonEvent); … … 398 405 NULL, 399 406 /* methods */ 400 V BoxServiceDefaultPreInit,401 V BoxServiceDefaultOption,402 VBoxServiceBalloonInit,403 VBoxServiceBalloonWorker,404 VBoxServiceBalloonStop,405 V BoxServiceDefaultTerm407 VGSvcDefaultPreInit, 408 VGSvcDefaultOption, 409 vgsvcBalloonInit, 410 vgsvcBalloonWorker, 411 vgsvcBalloonStop, 412 VGSvcDefaultTerm 406 413 }; -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceClipboard-os2.cpp
r57358 r58029 124 124 125 125 126 /** @copydoc VBOXSERVICE::pfnPreInit */ 127 static DECLCALLBACK(int) VBoxServiceClipboardOS2PreInit(void) 126 /** 127 * @interface_method_impl{VBOXSERVICE,pfnPreInit} 128 */ 129 static DECLCALLBACK(int) vgsvcClipboardOs2PreInit(void) 128 130 { 129 131 return VINF_SUCCESS; … … 131 133 132 134 133 /** @copydoc VBOXSERVICE::pfnOption */ 134 static DECLCALLBACK(int) VBoxServiceClipboardOS2Option(const char **ppszShort, int argc, char **argv, int *pi) 135 /** 136 * @interface_method_impl{VBOXSERVICE,pfnOption} 137 */ 138 static DECLCALLBACK(int) vgsvcClipboardOs2Option(const char **ppszShort, int argc, char **argv, int *pi) 135 139 { 136 140 NOREF(ppszShort); … … 143 147 144 148 145 /** @copydoc VBOXSERVICE::pfnInit */ 146 static DECLCALLBACK(int) VBoxServiceClipboardOS2Init(void) 149 /** 150 * @interface_method_impl{VBOXSERVICE,pfnInit} 151 */ 152 static DECLCALLBACK(int) vgsvcClipboardOs2Init(void) 147 153 { 148 154 int rc = VERR_GENERAL_FAILURE; … … 164 170 if (g_habCtrl == NULLHANDLE) 165 171 { 166 V BoxServiceError("WinInitialize(0) failed, lasterr=%lx\n", WinGetLastError(NULLHANDLE));172 VGSvcError("WinInitialize(0) failed, lasterr=%lx\n", WinGetLastError(NULLHANDLE)); 167 173 return VERR_GENERAL_FAILURE; 168 174 } … … 184 190 * Connect to the clipboard service. 185 191 */ 186 V BoxServiceVerbose(4, "clipboard: connecting\n");192 VGSvcVerbose(4, "clipboard: connecting\n"); 187 193 rc = VbglR3ClipboardConnect(&g_u32ClientId); 188 194 if (RT_SUCCESS(rc)) … … 196 202 g_atomOdin32UnicodeText = WinFindAtom(WinQuerySystemAtomTable(), SZFMT_ODIN32_UNICODETEXT); 197 203 if (g_atomOdin32UnicodeText == 0) 198 V BoxServiceError("WinAddAtom() failed, lasterr=%lx; WinFindAtom() failed, lasterror=%lx\n",204 VGSvcError("WinAddAtom() failed, lasterr=%lx; WinFindAtom() failed, lasterror=%lx\n", 199 205 lLastError, WinGetLastError(g_habCtrl)); 200 206 201 V BoxServiceVerbose(2, "g_u32ClientId=%RX32 g_atomNothingChanged=%#x g_atomOdin32UnicodeText=%#x\n",207 VGSvcVerbose(2, "g_u32ClientId=%RX32 g_atomNothingChanged=%#x g_atomOdin32UnicodeText=%#x\n", 202 208 g_u32ClientId, g_atomNothingChanged, g_atomOdin32UnicodeText); 203 209 return VINF_SUCCESS; 204 210 } 205 211 206 V BoxServiceError("Failed to connect to the clipboard service, rc=%Rrc!\n", rc);212 VGSvcError("Failed to connect to the clipboard service, rc=%Rrc!\n", rc); 207 213 } 208 214 else 209 V BoxServiceError("WinAddAtom() failed, lasterr=%lx; WinFindAtom() failed, lasterror=%lx\n",215 VGSvcError("WinAddAtom() failed, lasterr=%lx; WinFindAtom() failed, lasterror=%lx\n", 210 216 lLastError, WinGetLastError(g_habCtrl)); 211 217 } 212 218 else 213 V BoxServiceError("WinCreateMsgQueue(,0) failed, lasterr=%lx\n", WinGetLastError(g_habCtrl));219 VGSvcError("WinCreateMsgQueue(,0) failed, lasterr=%lx\n", WinGetLastError(g_habCtrl)); 214 220 WinTerminate(g_habCtrl); 215 221 return rc; … … 220 226 * Check that we're still the view / try make us the viewer. 221 227 */ 222 static void VBoxServiceClipboardOS2PollViewer(void)228 static void vgsvcClipboardOs2PollViewer(void) 223 229 { 224 230 const int iOrgState = g_enmState; … … 242 248 { 243 249 if (g_enmState == kClipboardState_Viewer) 244 V BoxServiceVerbose(3, "clipboard: viewer\n");250 VGSvcVerbose(3, "clipboard: viewer\n"); 245 251 else 246 V BoxServiceVerbose(3, "clipboard: poller\n");252 VGSvcVerbose(3, "clipboard: poller\n"); 247 253 } 248 254 } … … 251 257 /** 252 258 * Advertise the formats available from the host. 253 */ 254 static void VBoxServiceClipboardOS2AdvertiseHostFormats(uint32_t fFormats) 259 * 260 * @param fFormats The formats available on the host. 261 */ 262 static void vgsvcClipboardOs2AdvertiseHostFormats(uint32_t fFormats) 255 263 { 256 264 /* … … 282 290 { 283 291 if (!WinSetClipbrdData(g_habWorker, 0, CF_TEXT, CFI_POINTER)) 284 V BoxServiceError("WinSetClipbrdData(,,CF_TEXT,) failed, lasterr=%lx\n", WinGetLastError(g_habWorker));292 VGSvcError("WinSetClipbrdData(,,CF_TEXT,) failed, lasterr=%lx\n", WinGetLastError(g_habWorker)); 285 293 if ( g_atomOdin32UnicodeText 286 294 && !WinSetClipbrdData(g_habWorker, 0, g_atomOdin32UnicodeText, CFI_POINTER)) 287 V BoxServiceError("WinSetClipbrdData(,,g_atomOdin32UnicodeText,) failed, lasterr=%lx\n", WinGetLastError(g_habWorker));295 VGSvcError("WinSetClipbrdData(,,g_atomOdin32UnicodeText,) failed, lasterr=%lx\n", WinGetLastError(g_habWorker)); 288 296 } 289 297 if (fFormats & VBOX_SHARED_CLIPBOARD_FMT_BITMAP) … … 294 302 else 295 303 { 296 V BoxServiceError("WinSetClipbrdOwner failed, lasterr=%lx\n", WinGetLastError(g_habWorker));304 VGSvcError("WinSetClipbrdOwner failed, lasterr=%lx\n", WinGetLastError(g_habWorker)); 297 305 g_enmState = kClipboardState_Polling; 298 306 } … … 300 308 else 301 309 { 302 V BoxServiceError("WinEmptyClipbrd failed, lasterr=%lx\n", WinGetLastError(g_habWorker));310 VGSvcError("WinEmptyClipbrd failed, lasterr=%lx\n", WinGetLastError(g_habWorker)); 303 311 g_enmState = kClipboardState_Polling; 304 312 } … … 307 315 { 308 316 g_fEmptyClipboard = true; 309 VBoxServiceClipboardOS2PollViewer();317 vgsvcClipboardOs2PollViewer(); 310 318 } 311 319 … … 313 321 } 314 322 else 315 VBoxServiceError("VBoxServiceClipboardOS2AdvertiseHostFormats: WinOpenClipbrd failed, lasterr=%lx\n", WinGetLastError(g_habWorker)); 316 } 317 318 319 static void *VBoxServiceClipboardOs2ConvertToOdin32(uint32_t fFormat, USHORT usFmt, void *pv, uint32_t cb) 323 VGSvcError("vgsvcClipboardOs2AdvertiseHostFormats: WinOpenClipbrd failed, lasterr=%lx\n", WinGetLastError(g_habWorker)); 324 } 325 326 327 /** 328 * Converts (render) to an Odin32 clipboard format. 329 * 330 * We ASSUME we get windows data from the host and all we've got to do here is 331 * slapping an Odin32 header on it. 332 * 333 * @returns Pointer to the data (DosFreeMem). 334 * @param fFormat The host format. 335 * @param usFmt The PM/Odin32 format. 336 * @param pv The data in host formatting. 337 * @param cb The size of the data. 338 */ 339 static void *vgsvcClipboardOs2ConvertToOdin32(uint32_t fFormat, USHORT usFmt, void *pv, uint32_t cb) 320 340 { 321 341 PVOID pvPM = NULL; … … 334 354 else 335 355 { 336 V BoxServiceError("DosAllocSharedMem(,,%#x,,) -> %ld\n", cb + sizeof(CLIPHEADER), rc);356 VGSvcError("DosAllocSharedMem(,,%#x,,) -> %ld\n", cb + sizeof(CLIPHEADER), rc); 337 357 pvPM = NULL; 338 358 } … … 341 361 342 362 343 static void *VBoxServiceClipboardOs2ConvertToPM(uint32_t fFormat, USHORT usFmt, void *pv, uint32_t cb) 363 /** 364 * Converts (render) to a PM clipboard format. 365 * 366 * @returns Pointer to the data (DosFreeMem). 367 * @param fFormat The host format. 368 * @param usFmt The PM/Odin32 format. 369 * @param pv The data in host formatting. 370 * @param cb The size of the data. 371 */ 372 static void *vgsvcClipboardOs2ConvertToPM(uint32_t fFormat, USHORT usFmt, void *pv, uint32_t cb) 344 373 { 345 374 void *pvPM = NULL; … … 354 383 ) 355 384 ) 356 pvPM = VBoxServiceClipboardOs2ConvertToOdin32(fFormat, usFmt, pv, cb);385 pvPM = vgsvcClipboardOs2ConvertToOdin32(fFormat, usFmt, pv, cb); 357 386 else if (usFmt == CF_TEXT) 358 387 { … … 379 408 else 380 409 { 381 V BoxServiceError("DosAllocSharedMem(,,%#x,,) -> %ld\n", cb + sizeof(CLIPHEADER), orc);410 VGSvcError("DosAllocSharedMem(,,%#x,,) -> %ld\n", cb + sizeof(CLIPHEADER), orc); 382 411 pvPM = NULL; 383 412 } … … 385 414 } 386 415 else 387 V BoxServiceError("RTStrUtf8ToCurrentCP() -> %Rrc\n", rc);416 VGSvcError("RTStrUtf8ToCurrentCP() -> %Rrc\n", rc); 388 417 RTStrFree(pszUtf8); 389 418 } 390 419 else 391 V BoxServiceError("RTUtf16ToUtf8() -> %Rrc\n", rc);420 VGSvcError("RTUtf16ToUtf8() -> %Rrc\n", rc); 392 421 } 393 422 … … 404 433 * request send synchronously by someone who has already opened the 405 434 * clipboard. We would enter a deadlock trying to open it here. 406 * 407 */ 408 static void VBoxServiceClipboardOS2RenderFormat(USHORT usFmt) 435 */ 436 static void vgsvcClipboardOs2RenderFormat(USHORT usFmt) 409 437 { 410 438 bool fSucceeded = false; … … 431 459 if (pv) 432 460 { 433 V BoxServiceVerbose(4, "clipboard: reading host data (%#x)\n", fFormat);461 VGSvcVerbose(4, "clipboard: reading host data (%#x)\n", fFormat); 434 462 rc = VbglR3ClipboardReadData(g_u32ClientId, fFormat, pv, cb, &cb); 435 463 if (rc == VINF_BUFFER_OVERFLOW) … … 445 473 if (RT_SUCCESS(rc)) 446 474 { 447 V BoxServiceVerbose(4, "clipboard: read %u bytes\n", cb);475 VGSvcVerbose(4, "clipboard: read %u bytes\n", cb); 448 476 449 477 /* 450 478 * Convert the host clipboard data to PM clipboard data and set it. 451 479 */ 452 PVOID pvPM = VBoxServiceClipboardOs2ConvertToPM(fFormat, usFmt, pv, cb);480 PVOID pvPM = vgsvcClipboardOs2ConvertToPM(fFormat, usFmt, pv, cb); 453 481 if (pvPM) 454 482 { … … 457 485 else 458 486 { 459 V BoxServiceError("VBoxServiceClipboardOS2RenderFormat: WinSetClipbrdData(,%p,%#x, CF_POINTER) failed, lasterror=%lx\n",487 VGSvcError("vgsvcClipboardOs2RenderFormat: WinSetClipbrdData(,%p,%#x, CF_POINTER) failed, lasterror=%lx\n", 460 488 pvPM, usFmt, WinGetLastError(g_habWorker)); 461 489 DosFreeMem(pvPM); … … 465 493 } 466 494 else 467 V BoxServiceError("VBoxServiceClipboardOS2RenderFormat: Failed to query / allocate data. rc=%Rrc cb=%#RX32\n", rc, cb);495 VGSvcError("vgsvcClipboardOs2RenderFormat: Failed to query / allocate data. rc=%Rrc cb=%#RX32\n", rc, cb); 468 496 } 469 497 … … 478 506 g_enmState = kClipboardState_Polling; 479 507 g_fEmptyClipboard = true; 480 VBoxServiceClipboardOS2PollViewer(); 481 } 482 } 483 484 485 static void VBoxServiceClipboardOS2SendDataToHost(uint32_t fFormat) 508 vgsvcClipboardOs2PollViewer(); 509 } 510 } 511 512 513 /** 514 * Sends data to the host. 515 * 516 * @param fFormat The data format the host is requesting. 517 */ 518 static void vgsvcClipboardOs2SendDataToHost(uint32_t fFormat) 486 519 { 487 520 if (WinOpenClipbrd(g_habWorker)) … … 523 556 } 524 557 if (!pv) 525 V BoxServiceError("VBoxServiceClipboardOS2SendDataToHost: couldn't find data for %#x\n", fFormat);558 VGSvcError("vgsvcClipboardOs2SendDataToHost: couldn't find data for %#x\n", fFormat); 526 559 527 560 /* 528 561 * Now, sent whatever we've got to the host (it's waiting). 529 562 */ 530 V BoxServiceVerbose(4, "clipboard: writing %pv/%#d (fFormat=%#x)\n", pv, cb, fFormat);563 VGSvcVerbose(4, "clipboard: writing %pv/%#d (fFormat=%#x)\n", pv, cb, fFormat); 531 564 VbglR3ClipboardWriteData(g_u32ClientId, fFormat, pv, cb); 532 565 RTUtf16Free(pwszFree); … … 536 569 else 537 570 { 538 V BoxServiceError("VBoxServiceClipboardOS2SendDataToHost: WinOpenClipbrd failed, lasterr=%lx\n", WinGetLastError(g_habWorker));539 V BoxServiceVerbose(4, "clipboard: writing NULL/0 (fFormat=%x)\n", fFormat);571 VGSvcError("vgsvcClipboardOs2SendDataToHost: WinOpenClipbrd failed, lasterr=%lx\n", WinGetLastError(g_habWorker)); 572 VGSvcVerbose(4, "clipboard: writing NULL/0 (fFormat=%x)\n", fFormat); 540 573 VbglR3ClipboardWriteData(g_u32ClientId, fFormat, NULL, 0); 541 574 } … … 546 579 * Figure out what's on the clipboard and report it to the host. 547 580 */ 548 static void VBoxServiceClipboardOS2ReportFormats(void)581 static void vgsvcClipboardOs2ReportFormats(void) 549 582 { 550 583 uint32_t fFormats = 0; … … 557 590 /** @todo else bitmaps and stuff. */ 558 591 } 559 V BoxServiceVerbose(4, "clipboard: reporting fFormats=%#x\n", fFormats);592 VGSvcVerbose(4, "clipboard: reporting fFormats=%#x\n", fFormats); 560 593 VbglR3ClipboardReportFormats(g_u32ClientId, fFormats); 561 594 } … … 569 602 * notify the host. 570 603 */ 571 static void VBoxServiceClipboardOS2Poll(void)604 static void vgsvcClipboardOs2Poll(void) 572 605 { 573 606 if (WinOpenClipbrd(g_habWorker)) … … 583 616 { 584 617 g_fEmptyClipboard = false; 585 VBoxServiceClipboardOS2ReportFormats();618 vgsvcClipboardOs2ReportFormats(); 586 619 587 620 /* inject the dummy */ … … 591 624 { 592 625 if (WinSetClipbrdData(g_habWorker, (ULONG)pv, g_atomNothingChanged, CFI_POINTER)) 593 V BoxServiceVerbose(4, "clipboard: Added dummy item.\n");626 VGSvcVerbose(4, "clipboard: Added dummy item.\n"); 594 627 else 595 628 { 596 V BoxServiceError("VBoxServiceClipboardOS2Poll: WinSetClipbrdData failed, lasterr=%#lx\n", WinGetLastError(g_habWorker));629 VGSvcError("vgsvcClipboardOs2Poll: WinSetClipbrdData failed, lasterr=%#lx\n", WinGetLastError(g_habWorker)); 597 630 DosFreeMem(pv); 598 631 } 599 632 } 600 633 else 601 V BoxServiceError("VBoxServiceClipboardOS2Poll: DosAllocSharedMem(,,1,) -> %ld\n", rc);634 VGSvcError("vgsvcClipboardOs2Poll: DosAllocSharedMem(,,1,) -> %ld\n", rc); 602 635 } 603 636 else if (!g_fEmptyClipboard) 604 637 { 605 638 g_fEmptyClipboard = true; 606 V BoxServiceVerbose(3, "Reporting empty clipboard\n");639 VGSvcVerbose(3, "Reporting empty clipboard\n"); 607 640 VbglR3ClipboardReportFormats(g_u32ClientId, 0); 608 641 } … … 611 644 } 612 645 else 613 V BoxServiceError("VBoxServiceClipboardOS2Poll: WinOpenClipbrd failed, lasterr=%lx\n", WinGetLastError(g_habWorker));646 VGSvcError("vgsvcClipboardOs2Poll: WinOpenClipbrd failed, lasterr=%lx\n", WinGetLastError(g_habWorker)); 614 647 } 615 648 … … 618 651 * The clipboard we owned was destroyed by someone else. 619 652 */ 620 static void VBoxServiceClipboardOS2Destroyed(void)653 static void vgsvcClipboardOs2Destroyed(void) 621 654 { 622 655 /* make sure we're no longer the owner. */ … … 627 660 g_enmState = kClipboardState_Polling; 628 661 g_fEmptyClipboard = true; 629 V BoxServiceVerbose(3, "Reporting empty clipboard\n");662 VGSvcVerbose(3, "Reporting empty clipboard\n"); 630 663 VbglR3ClipboardReportFormats(g_u32ClientId, 0); 631 664 632 VBoxServiceClipboardOS2PollViewer();665 vgsvcClipboardOs2PollViewer(); 633 666 } 634 667 … … 644 677 * @param mp2 Message parameter 2. 645 678 */ 646 static MRESULT EXPENTRY VBoxServiceClipboardOS2WinProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)679 static MRESULT EXPENTRY vgsvcClipboardOs2WinProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) 647 680 { 648 681 if (msg != WM_TIMER) 649 V BoxServiceVerbose(6, "VBoxServiceClipboardOS2WinProc: hwnd=%#lx msg=%#lx mp1=%#lx mp2=%#lx\n", hwnd, msg, mp1, mp2);682 VGSvcVerbose(6, "vgsvcClipboardOs2WinProc: hwnd=%#lx msg=%#lx mp1=%#lx mp2=%#lx\n", hwnd, msg, mp1, mp2); 650 683 651 684 switch (msg) … … 678 711 break; 679 712 AssertMsgBreak(g_enmState == kClipboardState_Viewer, ("g_enmState=%d\n", g_enmState)); 680 VBoxServiceClipboardOS2Poll();713 vgsvcClipboardOs2Poll(); 681 714 break; 682 715 … … 689 722 break; /* it's us doing the replacing, ignore. */ 690 723 AssertMsgBreak(g_enmState == kClipboardState_Owner, ("g_enmState=%d\n", g_enmState)); 691 VBoxServiceClipboardOS2Destroyed();724 vgsvcClipboardOs2Destroyed(); 692 725 break; 693 726 … … 698 731 case WM_RENDERFMT: 699 732 AssertMsgBreak(g_enmState == kClipboardState_Owner, ("g_enmState=%d\n", g_enmState)); 700 VBoxServiceClipboardOS2RenderFormat(SHORT1FROMMP(mp1));733 vgsvcClipboardOs2RenderFormat(SHORT1FROMMP(mp1)); 701 734 break; 702 735 … … 723 756 */ 724 757 case WM_USER + VBOX_SHARED_CLIPBOARD_HOST_MSG_FORMATS: 725 VBoxServiceClipboardOS2AdvertiseHostFormats(LONGFROMMP(mp1));758 vgsvcClipboardOs2AdvertiseHostFormats(LONGFROMMP(mp1)); 726 759 break; 727 760 … … 730 763 */ 731 764 case WM_USER + VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA: 732 VBoxServiceClipboardOS2SendDataToHost(LONGFROMMP(mp1));765 vgsvcClipboardOs2SendDataToHost(LONGFROMMP(mp1)); 733 766 break; 734 767 … … 757 790 758 791 /* poll for changes */ 759 VBoxServiceClipboardOS2Poll();760 VBoxServiceClipboardOS2PollViewer();792 vgsvcClipboardOs2Poll(); 793 vgsvcClipboardOs2PollViewer(); 761 794 break; 762 795 … … 801 834 * @param pvUser Pointer to the clipboard service shutdown indicator. 802 835 */ 803 static DECLCALLBACK(int) VBoxServiceClipboardOS2Listener(RTTHREAD ThreadSelf, void *pvUser)836 static DECLCALLBACK(int) vgsvcClipboardOs2Listener(RTTHREAD ThreadSelf, void *pvUser) 804 837 { 805 838 bool volatile *pfShutdown = (bool volatile *)pvUser; 806 839 int rc = VERR_GENERAL_FAILURE; 807 V BoxServiceVerbose(3, "VBoxServiceClipboardOS2Listener: ThreadSelf=%RTthrd\n", ThreadSelf);840 VGSvcVerbose(3, "vgsvcClipboardOs2Listener: ThreadSelf=%RTthrd\n", ThreadSelf); 808 841 809 842 g_habListener = WinInitialize(0); … … 821 854 ASMAtomicXchgBool(&g_fListenerOkay, true); 822 855 RTThreadUserSignal(ThreadSelf); 823 V BoxServiceVerbose(3, "VBoxServiceClipboardOS2Listener: Started successfully\n");856 VGSvcVerbose(3, "vgsvcClipboardOs2Listener: Started successfully\n"); 824 857 825 858 /* … … 834 867 if (RT_SUCCESS(rc)) 835 868 { 836 V BoxServiceVerbose(3, "VBoxServiceClipboardOS2Listener: Msg=%#x fFormats=%#x\n", Msg, fFormats);869 VGSvcVerbose(3, "vgsvcClipboardOs2Listener: Msg=%#x fFormats=%#x\n", Msg, fFormats); 837 870 switch (Msg) 838 871 { … … 845 878 if (!WinPostMsg(g_hwndWorker, WM_USER + VBOX_SHARED_CLIPBOARD_HOST_MSG_FORMATS, 846 879 MPFROMLONG(fFormats), 0)) 847 V BoxServiceError("WinPostMsg(%lx, FORMATS,,) failed, lasterr=%#lx\n",880 VGSvcError("WinPostMsg(%lx, FORMATS,,) failed, lasterr=%#lx\n", 848 881 g_hwndWorker, WinGetLastError(g_habListener)); 849 882 break; … … 855 888 if (!WinPostMsg(g_hwndWorker, WM_USER + VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA, 856 889 MPFROMLONG(fFormats), 0)) 857 V BoxServiceError("WinPostMsg(%lx, READ_DATA,,) failed, lasterr=%#lx\n",890 VGSvcError("WinPostMsg(%lx, READ_DATA,,) failed, lasterr=%#lx\n", 858 891 g_hwndWorker, WinGetLastError(g_habListener)); 859 892 break; … … 867 900 868 901 default: 869 V BoxServiceVerbose(1, "VBoxServiceClipboardOS2Listener: Unknown message %RU32\n", Msg);902 VGSvcVerbose(1, "vgsvcClipboardOs2Listener: Unknown message %RU32\n", Msg); 870 903 break; 871 904 } … … 875 908 if (*pfShutdown) 876 909 break; 877 V BoxServiceError("VbglR3ClipboardGetHostMsg failed, rc=%Rrc\n", rc);910 VGSvcError("VbglR3ClipboardGetHostMsg failed, rc=%Rrc\n", rc); 878 911 RTThreadSleep(1000); 879 912 } … … 888 921 /* Signal our semaphore to make the worker catch on. */ 889 922 RTThreadUserSignal(ThreadSelf); 890 V BoxServiceVerbose(3, "VBoxServiceClipboardOS2Listener: terminating, rc=%Rrc\n", rc);923 VGSvcVerbose(3, "vgsvcClipboardOs2Listener: terminating, rc=%Rrc\n", rc); 891 924 return rc; 892 925 } 893 926 894 927 895 /** @copydoc VBOXSERVICE::pfnWorker */ 896 static DECLCALLBACK(int) VBoxServiceClipboardOS2Worker(bool volatile *pfShutdown) 928 /** 929 * @interface_method_impl{VBOXSERVICE,pfnWorker} 930 */ 931 static DECLCALLBACK(int) vgsvcClipboardOs2Worker(bool volatile *pfShutdown) 897 932 { 898 933 int rc = VERR_GENERAL_FAILURE; … … 913 948 * Create the object window. 914 949 */ 915 if (WinRegisterClass(g_habWorker, (PCSZ)"VBoxServiceClipboardClass", VBoxServiceClipboardOS2WinProc, 0, 0))950 if (WinRegisterClass(g_habWorker, (PCSZ)"VBoxServiceClipboardClass", vgsvcClipboardOs2WinProc, 0, 0)) 916 951 { 917 952 g_hwndWorker = WinCreateWindow(HWND_OBJECT, /* hwndParent */ … … 927 962 if (g_hwndWorker != NULLHANDLE) 928 963 { 929 V BoxServiceVerbose(3, "g_hwndWorker=%#lx g_habWorker=%#lx g_hmqWorker=%#lx\n", g_hwndWorker, g_habWorker, g_hmqWorker);964 VGSvcVerbose(3, "g_hwndWorker=%#lx g_habWorker=%#lx g_hmqWorker=%#lx\n", g_hwndWorker, g_habWorker, g_hmqWorker); 930 965 931 966 /* … … 933 968 */ 934 969 g_fListenerOkay = false; 935 rc = RTThreadCreate(&g_ThreadListener, VBoxServiceClipboardOS2Listener, (void *)pfShutdown, 0,970 rc = RTThreadCreate(&g_ThreadListener, vgsvcClipboardOs2Listener, (void *)pfShutdown, 0, 936 971 RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "CLIPLISTEN"); 937 972 if (RT_SUCCESS(rc)) … … 952 987 * The PM event pump. 953 988 */ 954 V BoxServiceVerbose(2, "clipboard: Entering PM message loop.\n");989 VGSvcVerbose(2, "clipboard: Entering PM message loop.\n"); 955 990 rc = VINF_SUCCESS; 956 991 QMSG qmsg; … … 958 993 { 959 994 if (qmsg.msg != WM_TIMER) 960 V BoxServiceVerbose(6, "WinGetMsg -> hwnd=%p msg=%#x mp1=%p mp2=%p time=%#x ptl=%d,%d rsrv=%#x\n",995 VGSvcVerbose(6, "WinGetMsg -> hwnd=%p msg=%#x mp1=%p mp2=%p time=%#x ptl=%d,%d rsrv=%#x\n", 961 996 qmsg.hwnd, qmsg.msg, qmsg.mp1, qmsg.mp2, qmsg.time, qmsg.ptl.x, qmsg.ptl.y, qmsg.reserved); 962 997 WinDispatchMsg(g_habWorker, &qmsg); 963 998 } 964 V BoxServiceVerbose(2, "clipboard: Exited PM message loop. *pfShutdown=%RTbool\n", *pfShutdown);999 VGSvcVerbose(2, "clipboard: Exited PM message loop. *pfShutdown=%RTbool\n", *pfShutdown); 965 1000 966 1001 RTThreadWait(g_ThreadListener, 60*1000, NULL); … … 979 1014 } 980 1015 else 981 V BoxServiceError("WinCreateWindow() failed, lasterr=%lx\n", WinGetLastError(g_habWorker));1016 VGSvcError("WinCreateWindow() failed, lasterr=%lx\n", WinGetLastError(g_habWorker)); 982 1017 /* no class deregistration in PM. */ 983 1018 } 984 1019 else 985 V BoxServiceError("WinRegisterClass() failed, lasterr=%lx\n", WinGetLastError(g_habWorker));1020 VGSvcError("WinRegisterClass() failed, lasterr=%lx\n", WinGetLastError(g_habWorker)); 986 1021 987 1022 if (g_hmqCtrl != g_hmqWorker) … … 990 1025 } 991 1026 else 992 V BoxServiceError("WinCreateMsgQueue(,0) failed, lasterr=%lx\n", WinGetLastError(g_habWorker));1027 VGSvcError("WinCreateMsgQueue(,0) failed, lasterr=%lx\n", WinGetLastError(g_habWorker)); 993 1028 994 1029 if (g_habCtrl != g_habWorker) … … 997 1032 } 998 1033 else 999 V BoxServiceError("WinInitialize(0) failed, lasterr=%lx\n", WinGetLastError(NULLHANDLE));1034 VGSvcError("WinInitialize(0) failed, lasterr=%lx\n", WinGetLastError(NULLHANDLE)); 1000 1035 1001 1036 return rc; … … 1003 1038 1004 1039 1005 /** @copydoc VBOXSERVICE::pfnStop */ 1006 static DECLCALLBACK(void) VBoxServiceClipboardOS2Stop(void) 1040 /** 1041 * @interface_method_impl{VBOXSERVICE,pfnStop} 1042 */ 1043 static DECLCALLBACK(void) vgsvcClipboardOs2Stop(void) 1007 1044 { 1008 1045 if ( g_hmqWorker != NULLHANDLE 1009 1046 && !WinPostQueueMsg(g_hmqWorker, WM_QUIT, NULL, NULL)) 1010 V BoxServiceError("WinPostQueueMsg(g_hmqWorker, WM_QUIT, 0,0) failed, lasterr=%lx\n", WinGetLastError(g_habCtrl));1047 VGSvcError("WinPostQueueMsg(g_hmqWorker, WM_QUIT, 0,0) failed, lasterr=%lx\n", WinGetLastError(g_habCtrl)); 1011 1048 1012 1049 /* Must disconnect the clipboard here otherwise the listner won't quit and … … 1017 1054 RTThreadSleep(32); /* fudge */ 1018 1055 1019 V BoxServiceVerbose(4, "clipboard: disconnecting %#x\n", g_u32ClientId);1056 VGSvcVerbose(4, "clipboard: disconnecting %#x\n", g_u32ClientId); 1020 1057 int rc = VbglR3ClipboardDisconnect(g_u32ClientId); 1021 1058 if (RT_SUCCESS(rc)) 1022 1059 g_u32ClientId = 0; 1023 1060 else 1024 VBoxServiceError("clipboard: VbglR3ClipboardDisconnect(%#x) -> %Rrc\n", g_u32ClientId, rc); 1025 } 1026 } 1027 1028 1029 /** @copydoc VBOXSERVICE::pfnTerm */ 1030 static DECLCALLBACK(void) VBoxServiceClipboardOS2Term(void) 1061 VGSvcError("clipboard: VbglR3ClipboardDisconnect(%#x) -> %Rrc\n", g_u32ClientId, rc); 1062 } 1063 } 1064 1065 1066 /** 1067 * @interface_method_impl{VBOXSERVICE,pfnTerm} 1068 */ 1069 static DECLCALLBACK(void) vgsvcClipboardOs2Term(void) 1031 1070 { 1032 1071 if (g_u32ClientId != 0) 1033 1072 { 1034 V BoxServiceVerbose(4, "clipboard: disconnecting %#x\n", g_u32ClientId);1073 VGSvcVerbose(4, "clipboard: disconnecting %#x\n", g_u32ClientId); 1035 1074 int rc = VbglR3ClipboardDisconnect(g_u32ClientId); 1036 1075 if (RT_SUCCESS(rc)) 1037 1076 g_u32ClientId = 0; 1038 1077 else 1039 V BoxServiceError("clipboard: VbglR3ClipboardDisconnect(%#x) -> %Rrc\n", g_u32ClientId, rc);1078 VGSvcError("clipboard: VbglR3ClipboardDisconnect(%#x) -> %Rrc\n", g_u32ClientId, rc); 1040 1079 } 1041 1080 WinDestroyMsgQueue(g_hmqCtrl); … … 1062 1101 , 1063 1102 /* methods */ 1064 VBoxServiceClipboardOS2PreInit,1065 VBoxServiceClipboardOS2Option,1066 VBoxServiceClipboardOS2Init,1067 VBoxServiceClipboardOS2Worker,1068 VBoxServiceClipboardOS2Stop,1069 VBoxServiceClipboardOS2Term1103 vgsvcClipboardOs2PreInit, 1104 vgsvcClipboardOs2Option, 1105 vgsvcClipboardOs2Init, 1106 vgsvcClipboardOs2Worker, 1107 vgsvcClipboardOs2Stop, 1108 vgsvcClipboardOs2Term 1070 1109 }; 1071 1110 -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControl.cpp
r57659 r58029 43 43 *********************************************************************************************************************************/ 44 44 /** The control interval (milliseconds). */ 45 static uint32_t g_ uControlIntervalMS= 0;45 static uint32_t g_msControlInterval = 0; 46 46 /** The semaphore we're blocking our main control thread on. */ 47 47 static RTSEMEVENTMULTI g_hControlEvent = NIL_RTSEMEVENTMULTI; … … 70 70 * Internal Functions * 71 71 *********************************************************************************************************************************/ 72 static int gstcntlHandleSessionOpen(PVBGLR3GUESTCTRLCMDCTX pHostCtx); 73 static int gstcntlHandleSessionClose(PVBGLR3GUESTCTRLCMDCTX pHostCtx); 74 static void VBoxServiceControlShutdown(void); 75 76 77 /** @copydoc VBOXSERVICE::pfnPreInit */ 78 static DECLCALLBACK(int) VBoxServiceControlPreInit(void) 72 static int vgsvcGstCtrlHandleSessionOpen(PVBGLR3GUESTCTRLCMDCTX pHostCtx); 73 static int vgsvcGstCtrlHandleSessionClose(PVBGLR3GUESTCTRLCMDCTX pHostCtx); 74 static void vgsvcGstCtrlShutdown(void); 75 76 77 /** 78 * @interface_method_impl{VBOXSERVICE,pfnPreInit} 79 */ 80 static DECLCALLBACK(int) vgsvcGstCtrlPreInit(void) 79 81 { 80 82 int rc; … … 90 92 if (rc == VERR_HGCM_SERVICE_NOT_FOUND) /* Host service is not available. */ 91 93 { 92 V BoxServiceVerbose(0, "Guest property service is not available, skipping\n");94 VGSvcVerbose(0, "Guest property service is not available, skipping\n"); 93 95 rc = VINF_SUCCESS; 94 96 } 95 97 else 96 V BoxServiceError("Failed to connect to the guest property service, rc=%Rrc\n", rc);98 VGSvcError("Failed to connect to the guest property service, rc=%Rrc\n", rc); 97 99 } 98 100 else 99 {100 101 VbglR3GuestPropDisconnect(uGuestPropSvcClientID); 101 }102 102 103 103 if (rc == VERR_NOT_FOUND) /* If a value is not found, don't be sad! */ … … 111 111 { 112 112 /* Init session object. */ 113 rc = GstCntlSessionInit(&g_Session, 0 /* Flags */);113 rc = VGSvcGstCtrlSessionInit(&g_Session, 0 /* Flags */); 114 114 } 115 115 … … 118 118 119 119 120 /** @copydoc VBOXSERVICE::pfnOption */ 121 static DECLCALLBACK(int) VBoxServiceControlOption(const char **ppszShort, int argc, char **argv, int *pi) 120 /** 121 * @interface_method_impl{VBOXSERVICE,pfnOption} 122 */ 123 static DECLCALLBACK(int) vgsvcGstCtrlOption(const char **ppszShort, int argc, char **argv, int *pi) 122 124 { 123 125 int rc = -1; … … 125 127 /* no short options */; 126 128 else if (!strcmp(argv[*pi], "--control-interval")) 127 rc = V BoxServiceArgUInt32(argc, argv, "", pi,128 &g_ uControlIntervalMS, 1, UINT32_MAX - 1);129 rc = VGSvcArgUInt32(argc, argv, "", pi, 130 &g_msControlInterval, 1, UINT32_MAX - 1); 129 131 #ifdef DEBUG 130 132 else if (!strcmp(argv[*pi], "--control-dump-stdout")) … … 143 145 144 146 145 /** @copydoc VBOXSERVICE::pfnInit */ 146 static DECLCALLBACK(int) VBoxServiceControlInit(void) 147 /** 148 * @interface_method_impl{VBOXSERVICE,pfnInit} 149 */ 150 static DECLCALLBACK(int) vgsvcGstCtrlInit(void) 147 151 { 148 152 /* … … 150 154 * Then create the event sem to block on. 151 155 */ 152 if (!g_ uControlIntervalMS)153 g_ uControlIntervalMS= 1000;156 if (!g_msControlInterval) 157 g_msControlInterval = 1000; 154 158 155 159 int rc = RTSemEventMultiCreate(&g_hControlEvent); … … 163 167 if (RT_SUCCESS(rc)) 164 168 { 165 VBoxServiceVerbose(3, "Guest control service client ID=%RU32\n", 166 g_uControlSvcClientID); 169 VGSvcVerbose(3, "Guest control service client ID=%RU32\n", g_uControlSvcClientID); 167 170 168 171 /* Init session thread list. */ … … 175 178 if (rc == VERR_HGCM_SERVICE_NOT_FOUND) /* Host service is not available. */ 176 179 { 177 V BoxServiceVerbose(0, "Guest control service is not available\n");180 VGSvcVerbose(0, "Guest control service is not available\n"); 178 181 rc = VERR_SERVICE_DISABLED; 179 182 } 180 183 else 181 V BoxServiceError("Failed to connect to the guest control service! Error: %Rrc\n", rc);184 VGSvcError("Failed to connect to the guest control service! Error: %Rrc\n", rc); 182 185 RTSemEventMultiDestroy(g_hControlEvent); 183 186 g_hControlEvent = NIL_RTSEMEVENTMULTI; … … 187 190 188 191 189 /** @copydoc VBOXSERVICE::pfnWorker */ 190 DECLCALLBACK(int) VBoxServiceControlWorker(bool volatile *pfShutdown) 192 /** 193 * @interface_method_impl{VBOXSERVICE,pfnWorker} 194 */ 195 static DECLCALLBACK(int) vgsvcGstCtrlWorker(bool volatile *pfShutdown) 191 196 { 192 197 /* … … 213 218 for (;;) 214 219 { 215 V BoxServiceVerbose(3, "Waiting for host msg ...\n");220 VGSvcVerbose(3, "Waiting for host msg ...\n"); 216 221 uint32_t uMsg = 0; 217 222 uint32_t cParms = 0; … … 220 225 { 221 226 #ifdef DEBUG 222 V BoxServiceVerbose(4, "Message requires %ld parameters, but only 2 supplied -- retrying request (no error!)...\n",223 227 VGSvcVerbose(4, "Message requires %ld parameters, but only 2 supplied -- retrying request (no error!)...\n", 228 cParms); 224 229 #endif 225 230 rc = VINF_SUCCESS; /* Try to get "real" message in next block below. */ … … 228 233 { 229 234 /* Note: VERR_GEN_IO_FAILURE seems to be normal if ran into timeout. */ 230 V BoxServiceError("Getting host message failed with %Rrc\n", rc);235 VGSvcError("Getting host message failed with %Rrc\n", rc); 231 236 232 237 /* Check for VM session change. */ … … 236 241 && (idNewSession != g_idControlSession)) 237 242 { 238 V BoxServiceVerbose(1, "The VM session ID changed\n");243 VGSvcVerbose(1, "The VM session ID changed\n"); 239 244 g_idControlSession = idNewSession; 240 245 241 246 /* Close all opened guest sessions -- all context IDs, sessions etc. 242 247 * are now invalid. */ 243 rc2 = GstCntlSessionClose(&g_Session);248 rc2 = VGSvcGstCtrlSessionClose(&g_Session); 244 249 AssertRC(rc2); 245 250 246 251 /* Do a reconnect. */ 247 V BoxServiceVerbose(1, "Reconnecting to HGCM service ...\n");252 VGSvcVerbose(1, "Reconnecting to HGCM service ...\n"); 248 253 rc2 = VbglR3GuestCtrlConnect(&g_uControlSvcClientID); 249 254 if (RT_SUCCESS(rc2)) 250 255 { 251 VBoxServiceVerbose(3, "Guest control service client ID=%RU32\n", 252 g_uControlSvcClientID); 256 VGSvcVerbose(3, "Guest control service client ID=%RU32\n", g_uControlSvcClientID); 253 257 cRetrievalFailed = 0; 254 258 continue; /* Skip waiting. */ … … 256 260 else 257 261 { 258 V BoxServiceError("Unable to re-connect to HGCM service, rc=%Rrc, bailing out\n", rc);262 VGSvcError("Unable to re-connect to HGCM service, rc=%Rrc, bailing out\n", rc); 259 263 break; 260 264 } … … 263 267 if (++cRetrievalFailed > 16) /** @todo Make this configurable? */ 264 268 { 265 V BoxServiceError("Too many failed attempts in a row to get next message, bailing out\n");269 VGSvcError("Too many failed attempts in a row to get next message, bailing out\n"); 266 270 break; 267 271 } … … 272 276 if (RT_SUCCESS(rc)) 273 277 { 274 V BoxServiceVerbose(4, "Msg=%RU32 (%RU32 parms) retrieved\n", uMsg, cParms);278 VGSvcVerbose(4, "Msg=%RU32 (%RU32 parms) retrieved\n", uMsg, cParms); 275 279 cRetrievalFailed = 0; /* Reset failed retrieval count. */ 276 280 … … 284 288 && (idNewSession != g_idControlSession)) 285 289 { 286 V BoxServiceVerbose(1, "The VM session ID changed\n");290 VGSvcVerbose(1, "The VM session ID changed\n"); 287 291 g_idControlSession = idNewSession; 288 292 289 293 /* Close all opened guest sessions -- all context IDs, sessions etc. 290 294 * are now invalid. */ 291 rc2 = GstCntlSessionClose(&g_Session);295 rc2 = VGSvcGstCtrlSessionClose(&g_Session); 292 296 AssertRC(rc2); 293 297 } … … 296 300 { 297 301 case HOST_CANCEL_PENDING_WAITS: 298 V BoxServiceVerbose(1, "We were asked to quit ...\n");302 VGSvcVerbose(1, "We were asked to quit ...\n"); 299 303 break; 300 304 301 305 case HOST_SESSION_CREATE: 302 rc = gstcntlHandleSessionOpen(&ctxHost);306 rc = vgsvcGstCtrlHandleSessionOpen(&ctxHost); 303 307 break; 304 308 305 309 case HOST_SESSION_CLOSE: 306 rc = gstcntlHandleSessionClose(&ctxHost);310 rc = vgsvcGstCtrlHandleSessionClose(&ctxHost); 307 311 break; 308 312 … … 320 324 */ 321 325 if (ctxHost.uProtocol == 1) 322 { 323 rc = GstCntlSessionHandler(&g_Session, uMsg, &ctxHost, 324 pvScratchBuf, cbScratchBuf, pfShutdown); 325 } 326 rc = VGSvcGstCtrlSessionHandler(&g_Session, uMsg, &ctxHost, pvScratchBuf, cbScratchBuf, pfShutdown); 326 327 else 327 328 { … … 332 333 */ 333 334 rc = VbglR3GuestCtrlMsgSkip(g_uControlSvcClientID); 334 VBoxServiceVerbose(3, "Skipping uMsg=%RU32, cParms=%RU32, rc=%Rrc\n", 335 uMsg, cParms, rc); 335 VGSvcVerbose(3, "Skipping uMsg=%RU32, cParms=%RU32, rc=%Rrc\n", uMsg, cParms, rc); 336 336 } 337 337 break; … … 351 351 } 352 352 353 V BoxServiceVerbose(0, "Guest control service stopped\n");353 VGSvcVerbose(0, "Guest control service stopped\n"); 354 354 355 355 /* Delete scratch buffer. */ … … 357 357 RTMemFree(pvScratchBuf); 358 358 359 V BoxServiceVerbose(0, "Guest control worker returned with rc=%Rrc\n", rc);359 VGSvcVerbose(0, "Guest control worker returned with rc=%Rrc\n", rc); 360 360 return rc; 361 361 } 362 362 363 363 364 static int gstcntlHandleSessionOpen(PVBGLR3GUESTCTRLCMDCTX pHostCtx)364 static int vgsvcGstCtrlHandleSessionOpen(PVBGLR3GUESTCTRLCMDCTX pHostCtx) 365 365 { 366 366 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER); … … 379 379 * host wants to use in subsequent calls. */ 380 380 pHostCtx->uProtocol = ssInfo.uProtocol; 381 VBoxServiceVerbose(3, "Client ID=%RU32 now is using protocol %RU32\n", 382 pHostCtx->uClientID, pHostCtx->uProtocol); 383 384 rc = GstCntlSessionThreadCreate(&g_lstControlSessionThreads, 385 &ssInfo, NULL /* ppSessionThread */); 381 VGSvcVerbose(3, "Client ID=%RU32 now is using protocol %RU32\n", pHostCtx->uClientID, pHostCtx->uProtocol); 382 383 rc = VGSvcGstCtrlSessionThreadCreate(&g_lstControlSessionThreads, &ssInfo, NULL /* ppSessionThread */); 386 384 } 387 385 … … 390 388 /* Report back on failure. On success this will be done 391 389 * by the forked session thread. */ 392 int rc2 = VbglR3GuestCtrlSessionNotify(pHostCtx, 393 GUEST_SESSION_NOTIFYTYPE_ERROR, rc /* uint32_t vs. int */); 390 int rc2 = VbglR3GuestCtrlSessionNotify(pHostCtx, GUEST_SESSION_NOTIFYTYPE_ERROR, rc /* uint32_t vs. int */); 394 391 if (RT_FAILURE(rc2)) 395 V BoxServiceError("Reporting session error status on open failed with rc=%Rrc\n", rc2);396 } 397 398 V BoxServiceVerbose(3, "Opening a new guest session returned rc=%Rrc\n", rc);392 VGSvcError("Reporting session error status on open failed with rc=%Rrc\n", rc2); 393 } 394 395 VGSvcVerbose(3, "Opening a new guest session returned rc=%Rrc\n", rc); 399 396 return rc; 400 397 } 401 398 402 399 403 static int gstcntlHandleSessionClose(PVBGLR3GUESTCTRLCMDCTX pHostCtx)400 static int vgsvcGstCtrlHandleSessionClose(PVBGLR3GUESTCTRLCMDCTX pHostCtx) 404 401 { 405 402 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER); 406 403 407 uint32_t uSessionID, uFlags; 408 int rc = VbglR3GuestCtrlSessionGetClose(pHostCtx, &uFlags, &uSessionID); 404 uint32_t uSessionID; 405 uint32_t fFlags; 406 int rc = VbglR3GuestCtrlSessionGetClose(pHostCtx, &fFlags, &uSessionID); 409 407 if (RT_SUCCESS(rc)) 410 408 { … … 416 414 if (pThread->StartupInfo.uSessionID == uSessionID) 417 415 { 418 rc = GstCntlSessionThreadDestroy(pThread, uFlags);416 rc = VGSvcGstCtrlSessionThreadDestroy(pThread, fFlags); 419 417 break; 420 418 } … … 429 427 if (RT_FAILURE(rc2)) 430 428 { 431 V BoxServiceError("Reporting session error status on close failed with rc=%Rrc\n", rc2);429 VGSvcError("Reporting session error status on close failed with rc=%Rrc\n", rc2); 432 430 if (RT_SUCCESS(rc)) 433 431 rc = rc2; … … 435 433 } 436 434 #endif 437 VBoxServiceVerbose(2, "Closing guest session %RU32 returned rc=%Rrc\n", 438 uSessionID, rc); 435 VGSvcVerbose(2, "Closing guest session %RU32 returned rc=%Rrc\n", uSessionID, rc); 439 436 } 440 437 else 441 VBoxServiceError("Closing guest session %RU32 failed with rc=%Rrc\n", 442 uSessionID, rc); 438 VGSvcError("Closing guest session %RU32 failed with rc=%Rrc\n", uSessionID, rc); 443 439 return rc; 444 440 } 445 441 446 442 447 /** @copydoc VBOXSERVICE::pfnStop */ 448 static DECLCALLBACK(void) VBoxServiceControlStop(void) 449 { 450 VBoxServiceVerbose(3, "Stopping ...\n"); 443 /** 444 * @interface_method_impl{VBOXSERVICE,pfnStop} 445 */ 446 static DECLCALLBACK(void) vgsvcGstCtrlStop(void) 447 { 448 VGSvcVerbose(3, "Stopping ...\n"); 451 449 452 450 /** @todo Later, figure what to do if we're in RTProcWait(). It's a very … … 461 459 if (g_uControlSvcClientID) 462 460 { 463 V BoxServiceVerbose(3, "Cancelling pending waits (client ID=%u) ...\n",461 VGSvcVerbose(3, "Cancelling pending waits (client ID=%u) ...\n", 464 462 g_uControlSvcClientID); 465 463 466 464 int rc = VbglR3GuestCtrlCancelPendingWaits(g_uControlSvcClientID); 467 465 if (RT_FAILURE(rc)) 468 V BoxServiceError("Cancelling pending waits failed; rc=%Rrc\n", rc);466 VGSvcError("Cancelling pending waits failed; rc=%Rrc\n", rc); 469 467 } 470 468 } … … 474 472 * Destroys all guest process threads which are still active. 475 473 */ 476 static void VBoxServiceControlShutdown(void) 477 { 478 VBoxServiceVerbose(2, "Shutting down ...\n"); 479 480 int rc2 = GstCntlSessionThreadDestroyAll(&g_lstControlSessionThreads, 481 0 /* Flags */); 474 static void vgsvcGstCtrlShutdown(void) 475 { 476 VGSvcVerbose(2, "Shutting down ...\n"); 477 478 int rc2 = VGSvcGstCtrlSessionThreadDestroyAll(&g_lstControlSessionThreads, 0 /* Flags */); 482 479 if (RT_FAILURE(rc2)) 483 V BoxServiceError("Closing session threads failed with rc=%Rrc\n", rc2);484 485 rc2 = GstCntlSessionClose(&g_Session);480 VGSvcError("Closing session threads failed with rc=%Rrc\n", rc2); 481 482 rc2 = VGSvcGstCtrlSessionClose(&g_Session); 486 483 if (RT_FAILURE(rc2)) 487 VBoxServiceError("Closing session failed with rc=%Rrc\n", rc2); 488 489 VBoxServiceVerbose(2, "Shutting down complete\n"); 490 } 491 492 493 /** @copydoc VBOXSERVICE::pfnTerm */ 494 static DECLCALLBACK(void) VBoxServiceControlTerm(void) 495 { 496 VBoxServiceVerbose(3, "Terminating ...\n"); 497 498 VBoxServiceControlShutdown(); 499 500 VBoxServiceVerbose(3, "Disconnecting client ID=%u ...\n", 501 g_uControlSvcClientID); 484 VGSvcError("Closing session failed with rc=%Rrc\n", rc2); 485 486 VGSvcVerbose(2, "Shutting down complete\n"); 487 } 488 489 490 /** 491 * @interface_method_impl{VBOXSERVICE,pfnTerm} 492 */ 493 static DECLCALLBACK(void) vgsvcGstCtrlTerm(void) 494 { 495 VGSvcVerbose(3, "Terminating ...\n"); 496 497 vgsvcGstCtrlShutdown(); 498 499 VGSvcVerbose(3, "Disconnecting client ID=%u ...\n", g_uControlSvcClientID); 502 500 VbglR3GuestCtrlDisconnect(g_uControlSvcClientID); 503 501 g_uControlSvcClientID = 0; … … 537 535 , 538 536 /* methods */ 539 VBoxServiceControlPreInit,540 VBoxServiceControlOption,541 VBoxServiceControlInit,542 VBoxServiceControlWorker,543 VBoxServiceControlStop,544 VBoxServiceControlTerm537 vgsvcGstCtrlPreInit, 538 vgsvcGstCtrlOption, 539 vgsvcGstCtrlInit, 540 vgsvcGstCtrlWorker, 541 vgsvcGstCtrlStop, 542 vgsvcGstCtrlTerm 545 543 }; 546 544 -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControl.h
r57659 r58029 284 284 RT_C_DECLS_BEGIN 285 285 286 /** 287 * Note on naming conventions: 288 * - VBoxServiceControl* is named everything sub service module related, e.g. 289 * everything which is callable by main() and/or the service dispatcher(s). 290 * - GstCntl* is named everything which declared extern and thus can be called 291 * by different guest control modules as needed.292 * - gstcntl (all lowercase) is a purely static function to split up functionality 293 * inside a module. 294 */ 295 296 /* Guest session thread handling. */ 297 extern int GstCntlSessionThreadCreate(PRTLISTANCHOR pList, const PVBOXSERVICECTRLSESSIONSTARTUPINFO pSessionStartupInfo, PVBOXSERVICECTRLSESSIONTHREAD *ppSessionThread); 298 extern int GstCntlSessionThreadDestroy(PVBOXSERVICECTRLSESSIONTHREAD pSession, uint32_t uFlags); 299 extern int GstCntlSessionThreadDestroyAll(PRTLISTANCHOR pList, uint32_t uFlags); 300 extern int GstCntlSessionThreadTerminate(PVBOXSERVICECTRLSESSIONTHREAD pSession);301 extern RTEXITCODE VBoxServiceControlSessionSpawnInit(int argc, char **argv);302 /* Per-session functions. */ 303 extern PVBOXSERVICECTRLPROCESS GstCntlSessionRetainProcess(PVBOXSERVICECTRLSESSION pSession, uint32_t uPID);304 extern int GstCntlSessionClose(PVBOXSERVICECTRLSESSION pSession);305 extern int GstCntlSessionDestroy(PVBOXSERVICECTRLSESSION pSession);306 extern int GstCntlSessionInit(PVBOXSERVICECTRLSESSION pSession, uint32_t uFlags);307 extern int GstCntlSessionHandler(PVBOXSERVICECTRLSESSION pSession, uint32_t uMsg, PVBGLR3GUESTCTRLCMDCTX pHostCtx, void *pvScratchBuf, size_t cbScratchBuf, volatile bool *pfShutdown);308 extern int GstCntlSessionProcessAdd(PVBOXSERVICECTRLSESSION pSession, PVBOXSERVICECTRLPROCESS pProcess);309 extern int GstCntlSessionProcessRemove(PVBOXSERVICECTRLSESSION pSession, PVBOXSERVICECTRLPROCESS pProcess); 310 extern int GstCntlSessionProcessStartAllowed(const PVBOXSERVICECTRLSESSION pSession, bool *pbAllowed); 311 extern int GstCntlSessionReapProcesses(PVBOXSERVICECTRLSESSION pSession); 312 /* Per-guest process functions. */ 313 extern int GstCntlProcessFree(PVBOXSERVICECTRLPROCESS pProcess);314 extern int GstCntlProcessHandleInput(PVBOXSERVICECTRLPROCESS pProcess, PVBGLR3GUESTCTRLCMDCTX pHostCtx, bool fPendingClose, void *pvBuf, uint32_t cbBuf);315 extern int GstCntlProcessHandleOutput(PVBOXSERVICECTRLPROCESS pProcess, PVBGLR3GUESTCTRLCMDCTX pHostCtx, uint32_t uHandle, uint32_t cbToRead, uint32_t uFlags);316 extern int GstCntlProcessHandleTerm(PVBOXSERVICECTRLPROCESS pProcess);317 extern void GstCntlProcessRelease(PVBOXSERVICECTRLPROCESS pProcess);318 extern int GstCntlProcessStart(const PVBOXSERVICECTRLSESSION pSession, const PVBOXSERVICECTRLPROCSTARTUPINFO pStartupInfo, uint32_t uContext);319 extern int GstCntlProcessStop(PVBOXSERVICECTRLPROCESS pProcess);320 extern int GstCntlProcessWait(const PVBOXSERVICECTRLPROCESS pProcess, RTMSINTERVAL msTimeout, int *pRc); 286 extern RTLISTANCHOR g_lstControlSessionThreads; 287 extern VBOXSERVICECTRLSESSION g_Session; 288 289 290 /** @name Guest session thread handling. 291 * @{ */ 292 extern int VGSvcGstCtrlSessionThreadCreate(PRTLISTANCHOR pList, const PVBOXSERVICECTRLSESSIONSTARTUPINFO pSessionStartupInfo, PVBOXSERVICECTRLSESSIONTHREAD *ppSessionThread); 293 extern int VGSvcGstCtrlSessionThreadDestroy(PVBOXSERVICECTRLSESSIONTHREAD pSession, uint32_t uFlags); 294 extern int VGSvcGstCtrlSessionThreadDestroyAll(PRTLISTANCHOR pList, uint32_t uFlags); 295 extern int VGSvcGstCtrlSessionThreadTerminate(PVBOXSERVICECTRLSESSIONTHREAD pSession); 296 extern RTEXITCODE VGSvcGstCtrlSessionSpawnInit(int argc, char **argv); 297 /** @} */ 298 /** @name Per-session functions. 299 * @{ */ 300 extern PVBOXSERVICECTRLPROCESS VGSvcGstCtrlSessionRetainProcess(PVBOXSERVICECTRLSESSION pSession, uint32_t uPID); 301 extern int VGSvcGstCtrlSessionClose(PVBOXSERVICECTRLSESSION pSession); 302 extern int VGSvcGstCtrlSessionDestroy(PVBOXSERVICECTRLSESSION pSession); 303 extern int VGSvcGstCtrlSessionInit(PVBOXSERVICECTRLSESSION pSession, uint32_t uFlags); 304 extern int VGSvcGstCtrlSessionHandler(PVBOXSERVICECTRLSESSION pSession, uint32_t uMsg, PVBGLR3GUESTCTRLCMDCTX pHostCtx, void *pvScratchBuf, size_t cbScratchBuf, volatile bool *pfShutdown); 305 extern int VGSvcGstCtrlSessionProcessAdd(PVBOXSERVICECTRLSESSION pSession, PVBOXSERVICECTRLPROCESS pProcess); 306 extern int VGSvcGstCtrlSessionProcessRemove(PVBOXSERVICECTRLSESSION pSession, PVBOXSERVICECTRLPROCESS pProcess); 307 extern int VGSvcGstCtrlSessionProcessStartAllowed(const PVBOXSERVICECTRLSESSION pSession, bool *pbAllowed); 308 extern int VGSvcGstCtrlSessionReapProcesses(PVBOXSERVICECTRLSESSION pSession); 309 /** @} */ 310 /** @name Per-guest process functions. 311 * @{ */ 312 extern int VGSvcGstCtrlProcessFree(PVBOXSERVICECTRLPROCESS pProcess); 313 extern int VGSvcGstCtrlProcessHandleInput(PVBOXSERVICECTRLPROCESS pProcess, PVBGLR3GUESTCTRLCMDCTX pHostCtx, bool fPendingClose, void *pvBuf, uint32_t cbBuf); 314 extern int VGSvcGstCtrlProcessHandleOutput(PVBOXSERVICECTRLPROCESS pProcess, PVBGLR3GUESTCTRLCMDCTX pHostCtx, uint32_t uHandle, uint32_t cbToRead, uint32_t uFlags); 315 extern int VGSvcGstCtrlProcessHandleTerm(PVBOXSERVICECTRLPROCESS pProcess); 316 extern void VGSvcGstCtrlProcessRelease(PVBOXSERVICECTRLPROCESS pProcess); 317 extern int VGSvcGstCtrlProcessStart(const PVBOXSERVICECTRLSESSION pSession, const PVBOXSERVICECTRLPROCSTARTUPINFO pStartupInfo, uint32_t uContext); 318 extern int VGSvcGstCtrlProcessStop(PVBOXSERVICECTRLPROCESS pProcess); 319 extern int VGSvcGstCtrlProcessWait(const PVBOXSERVICECTRLPROCESS pProcess, RTMSINTERVAL msTimeout, int *pRc); 320 /** @} */ 321 321 322 322 RT_C_DECLS_END 323 323 324 #endif /* ___VBoxServiceControl_h */325 324 #endif 325 -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlProcess.cpp
r57753 r58029 47 47 * Internal Functions * 48 48 *********************************************************************************************************************************/ 49 static int gstcntlProcessAssignPID(PVBOXSERVICECTRLPROCESS pThread, uint32_t uPID); 50 static int gstcntlProcessLock(PVBOXSERVICECTRLPROCESS pProcess); 51 static int gstcntlProcessRequest(PVBOXSERVICECTRLPROCESS pProcess, const PVBGLR3GUESTCTRLCMDCTX pHostCtx, PFNRT pfnFunction, unsigned cArgs, ...); 52 static int gstcntlProcessSetupPipe(const char *pszHowTo, int fd, PRTHANDLE ph, PRTHANDLE *pph, PRTPIPE phPipe); 53 static int gstcntlProcessUnlock(PVBOXSERVICECTRLPROCESS pProcess); 49 static int vgsvcGstCtrlProcessAssignPID(PVBOXSERVICECTRLPROCESS pThread, uint32_t uPID); 50 static int vgsvcGstCtrlProcessLock(PVBOXSERVICECTRLPROCESS pProcess); 51 static int vgsvcGstCtrlProcessRequest(PVBOXSERVICECTRLPROCESS pProcess, const PVBGLR3GUESTCTRLCMDCTX pHostCtx, 52 PFNRT pfnFunction, unsigned cArgs, ...); 53 static int vgsvcGstCtrlProcessSetupPipe(const char *pszHowTo, int fd, PRTHANDLE ph, PRTHANDLE *pph, 54 PRTPIPE phPipe); 55 static int vgsvcGstCtrlProcessUnlock(PVBOXSERVICECTRLPROCESS pProcess); 54 56 /* Request handlers. */ 55 static DECLCALLBACK(int) gstcntlProcessOnInput(PVBOXSERVICECTRLPROCESS pThis, const PVBGLR3GUESTCTRLCMDCTX pHostCtx, bool fPendingClose, void *pvBuf, uint32_t cbBuf); 56 static DECLCALLBACK(int) gstcntlProcessOnOutput(PVBOXSERVICECTRLPROCESS pThis, const PVBGLR3GUESTCTRLCMDCTX pHostCtx, uint32_t uHandle, uint32_t cbToRead, uint32_t uFlags); 57 static DECLCALLBACK(int) gstcntlProcessOnTerm(PVBOXSERVICECTRLPROCESS pThis); 57 static DECLCALLBACK(int) vgsvcGstCtrlProcessOnInput(PVBOXSERVICECTRLPROCESS pThis, const PVBGLR3GUESTCTRLCMDCTX pHostCtx, 58 bool fPendingClose, void *pvBuf, uint32_t cbBuf); 59 static DECLCALLBACK(int) vgsvcGstCtrlProcessOnOutput(PVBOXSERVICECTRLPROCESS pThis, const PVBGLR3GUESTCTRLCMDCTX pHostCtx, 60 uint32_t uHandle, uint32_t cbToRead, uint32_t uFlags); 61 static DECLCALLBACK(int) vgsvcGstCtrlProcessOnTerm(PVBOXSERVICECTRLPROCESS pThis); 62 58 63 59 64 /** … … 66 71 * @param u32ContextID The context ID bound to this request / command. 67 72 */ 68 static int gstcntlProcessInit(PVBOXSERVICECTRLPROCESS pProcess,69 const PVBOXSERVICECTRLSESSION pSession,70 const PVBOXSERVICECTRLPROCSTARTUPINFO pStartupInfo,71 uint32_t u32ContextID)73 static int vgsvcGstCtrlProcessInit(PVBOXSERVICECTRLPROCESS pProcess, 74 const PVBOXSERVICECTRLSESSION pSession, 75 const PVBOXSERVICECTRLPROCSTARTUPINFO pStartupInfo, 76 uint32_t u32ContextID) 72 77 { 73 78 AssertPtrReturn(pProcess, VERR_INVALID_POINTER); … … 122 127 123 128 if (RT_FAILURE(rc)) /* Clean up on failure. */ 124 GstCntlProcessFree(pProcess);129 VGSvcGstCtrlProcessFree(pProcess); 125 130 return rc; 126 131 } … … 134 139 * @param pProcess Guest process to free. 135 140 */ 136 int GstCntlProcessFree(PVBOXSERVICECTRLPROCESS pProcess)141 int VGSvcGstCtrlProcessFree(PVBOXSERVICECTRLPROCESS pProcess) 137 142 { 138 143 AssertPtrReturn(pProcess, VERR_INVALID_POINTER); 139 144 140 VBoxServiceVerbose(3, "[PID %RU32]: Freeing (cRefs=%RU32)...\n", 141 pProcess->uPID, pProcess->cRefs); 145 VGSvcVerbose(3, "[PID %RU32]: Freeing (cRefs=%RU32)...\n", pProcess->uPID, pProcess->cRefs); 142 146 Assert(pProcess->cRefs == 0); 143 147 … … 155 159 */ 156 160 AssertPtr(pProcess->pSession); 157 rc = GstCntlSessionProcessRemove(pProcess->pSession, pProcess);161 rc = VGSvcGstCtrlSessionProcessRemove(pProcess->pSession, pProcess); 158 162 AssertRC(rc); 159 163 … … 175 179 * @param pProcess Process to stop. 176 180 */ 177 int GstCntlProcessStop(PVBOXSERVICECTRLPROCESS pProcess)181 int VGSvcGstCtrlProcessStop(PVBOXSERVICECTRLPROCESS pProcess) 178 182 { 179 183 AssertPtrReturn(pProcess, VERR_INVALID_POINTER); 180 184 181 VBoxServiceVerbose(3, "[PID %RU32]: Stopping ...\n", 182 pProcess->uPID); 185 VGSvcVerbose(3, "[PID %RU32]: Stopping ...\n", pProcess->uPID); 183 186 184 187 /* Do *not* set pThread->fShutdown or other stuff here! 185 188 * The guest thread loop will clean up itself. */ 186 189 187 return GstCntlProcessHandleTerm(pProcess);190 return VGSvcGstCtrlProcessHandleTerm(pProcess); 188 191 } 189 192 … … 194 197 * @param pProcess Process to unlock. 195 198 */ 196 void GstCntlProcessRelease(PVBOXSERVICECTRLPROCESS pProcess)199 void VGSvcGstCtrlProcessRelease(PVBOXSERVICECTRLPROCESS pProcess) 197 200 { 198 201 AssertPtrReturnVoid(pProcess); … … 212 215 213 216 if (fShutdown) 214 GstCntlProcessFree(pProcess);217 VGSvcGstCtrlProcessFree(pProcess); 215 218 } 216 219 … … 222 225 * @param pProcess Process to wait shutting down for. 223 226 * @param RTMSINTERVAL Timeout in ms to wait for shutdown. 224 * @param p Rc Where to store the thread's return code. Optional.225 * /226 int GstCntlProcessWait(const PVBOXSERVICECTRLPROCESS pProcess, 227 RTMSINTERVAL msTimeout, int *pRc)227 * @param prc Where to store the thread's return code. 228 * Optional. 229 */ 230 int VGSvcGstCtrlProcessWait(const PVBOXSERVICECTRLPROCESS pProcess, RTMSINTERVAL msTimeout, int *prc) 228 231 { 229 232 AssertPtrReturn(pProcess, VERR_INVALID_POINTER); 230 /* pRc is optional. */231 232 int rc = gstcntlProcessLock(pProcess);233 AssertPtrNullReturn(prc, VERR_INVALID_POINTER); 234 235 int rc = vgsvcGstCtrlProcessLock(pProcess); 233 236 if (RT_SUCCESS(rc)) 234 237 { 235 VBoxServiceVerbose(2, "[PID %RU32]: Waiting for shutdown (%RU32ms) ...\n", 236 pProcess->uPID, msTimeout); 238 VGSvcVerbose(2, "[PID %RU32]: Waiting for shutdown (%RU32ms) ...\n", pProcess->uPID, msTimeout); 237 239 238 240 AssertMsgReturn(pProcess->fStarted, … … 244 246 { 245 247 /* Unlock process before waiting. */ 246 rc = gstcntlProcessUnlock(pProcess);248 rc = vgsvcGstCtrlProcessUnlock(pProcess); 247 249 AssertRC(rc); 248 250 … … 251 253 Assert(pProcess->Thread != NIL_RTTHREAD); 252 254 rc = RTThreadWait(pProcess->Thread, msTimeout, &rcThread); 253 if (RT_ FAILURE(rc))255 if (RT_SUCCESS(rc)) 254 256 { 255 VBoxServiceError("[PID %RU32]: Waiting for shutting down thread returned error rc=%Rrc\n", 256 pProcess->uPID, rc); 257 VGSvcVerbose(3, "[PID %RU32]: Thread shutdown complete, thread rc=%Rrc\n", pProcess->uPID, rcThread); 258 if (prc) 259 *prc = rcThread; 257 260 } 258 261 else 259 { 260 VBoxServiceVerbose(3, "[PID %RU32]: Thread shutdown complete, thread rc=%Rrc\n", 261 pProcess->uPID, rcThread); 262 if (pRc) 263 *pRc = rcThread; 264 } 262 VGSvcError("[PID %RU32]: Waiting for shutting down thread returned error rc=%Rrc\n", pProcess->uPID, rc); 265 263 } 266 264 else 267 265 { 268 VBoxServiceVerbose(3, "[PID %RU32]: Thread already shut down, no waiting needed\n", 269 pProcess->uPID); 270 271 int rc2 = gstcntlProcessUnlock(pProcess); 266 VGSvcVerbose(3, "[PID %RU32]: Thread already shut down, no waiting needed\n", pProcess->uPID); 267 268 int rc2 = vgsvcGstCtrlProcessUnlock(pProcess); 272 269 AssertRC(rc2); 273 270 } 274 271 } 275 272 276 VBoxServiceVerbose(3, "[PID %RU32]: Waiting resulted in rc=%Rrc\n", 277 pProcess->uPID, rc); 273 VGSvcVerbose(3, "[PID %RU32]: Waiting resulted in rc=%Rrc\n", pProcess->uPID, rc); 278 274 return rc; 279 275 } … … 287 283 * @param phStdInW The standard input pipe handle. 288 284 */ 289 static int gstcntlProcessPollsetCloseInput(PVBOXSERVICECTRLPROCESS pProcess, 290 PRTPIPE phStdInW) 285 static int vgsvcGstCtrlProcessPollsetCloseInput(PVBOXSERVICECTRLPROCESS pProcess, PRTPIPE phStdInW) 291 286 { 292 287 AssertPtrReturn(pProcess, VERR_INVALID_POINTER); … … 308 303 309 304 310 static const char* gstcntlProcessPollHandleToString(uint32_t idPollHnd) 305 /** 306 * Names a poll handle ID. 307 * 308 * @returns Pointer to read-only string. 309 * @param idPollHnd What to name. 310 */ 311 static const char *vgsvcGstCtrlProcessPollHandleToString(uint32_t idPollHnd) 311 312 { 312 313 switch (idPollHnd) … … 325 326 return "ipc_notify"; 326 327 default: 327 break; 328 } 329 330 return "unknown"; 328 return "unknown"; 329 } 331 330 } 332 331 … … 340 339 * @param phStdInW The standard input pipe handle. 341 340 */ 342 static int gstcntlProcessPollsetOnInput(PVBOXSERVICECTRLPROCESS pProcess, 343 uint32_t fPollEvt, PRTPIPE phStdInW) 341 static int vgsvcGstCtrlProcessPollsetOnInput(PVBOXSERVICECTRLPROCESS pProcess, uint32_t fPollEvt, PRTPIPE phStdInW) 344 342 { 345 343 AssertPtrReturn(pProcess, VERR_INVALID_POINTER); … … 347 345 NOREF(fPollEvt); 348 346 349 return gstcntlProcessPollsetCloseInput(pProcess, phStdInW);347 return vgsvcGstCtrlProcessPollsetCloseInput(pProcess, phStdInW); 350 348 } 351 349 … … 359 357 * @param phPipeR The pipe handle. 360 358 * @param idPollHnd The pipe ID to handle. 361 * 362 */ 363 static int gstcntlProcessHandleOutputError(PVBOXSERVICECTRLPROCESS pProcess, 364 uint32_t fPollEvt, PRTPIPE phPipeR, uint32_t idPollHnd) 359 */ 360 static int vgsvcGstCtrlProcessHandleOutputError(PVBOXSERVICECTRLPROCESS pProcess, 361 uint32_t fPollEvt, PRTPIPE phPipeR, uint32_t idPollHnd) 365 362 { 366 363 AssertPtrReturn(pProcess, VERR_INVALID_POINTER); … … 370 367 371 368 #ifdef DEBUG 372 V BoxServiceVerbose(4, "[PID %RU32]: Output error: idPollHnd=%s, fPollEvt=0x%x\n",373 pProcess->uPID, gstcntlProcessPollHandleToString(idPollHnd), fPollEvt);369 VGSvcVerbose(4, "[PID %RU32]: Output error: idPollHnd=%s, fPollEvt=0x%x\n", 370 pProcess->uPID, vgsvcGstCtrlProcessPollHandleToString(idPollHnd), fPollEvt); 374 371 #endif 375 372 … … 389 386 { 390 387 #ifdef DEBUG 391 V BoxServiceVerbose(3, "[PID %RU32]: idPollHnd=%s has %zu bytes left, vetoing close\n",392 pProcess->uPID, gstcntlProcessPollHandleToString(idPollHnd), cbReadable);388 VGSvcVerbose(3, "[PID %RU32]: idPollHnd=%s has %zu bytes left, vetoing close\n", 389 pProcess->uPID, vgsvcGstCtrlProcessPollHandleToString(idPollHnd), cbReadable); 393 390 #endif 394 391 /* Veto closing the pipe yet because there's still stuff to read … … 400 397 #ifdef DEBUG 401 398 else 402 V BoxServiceVerbose(3, "[PID %RU32]: idPollHnd=%s will be closed\n",403 pProcess->uPID, gstcntlProcessPollHandleToString(idPollHnd));399 VGSvcVerbose(3, "[PID %RU32]: idPollHnd=%s will be closed\n", 400 pProcess->uPID, vgsvcGstCtrlProcessPollHandleToString(idPollHnd)); 404 401 #endif 405 402 … … 426 423 * 427 424 */ 428 static int gstcntlProcessPollsetOnOutput(PVBOXSERVICECTRLPROCESS pProcess,429 uint32_t fPollEvt, PRTPIPE phPipeR, uint32_t idPollHnd)425 static int vgsvcGstCtrlProcessPollsetOnOutput(PVBOXSERVICECTRLPROCESS pProcess, 426 uint32_t fPollEvt, PRTPIPE phPipeR, uint32_t idPollHnd) 430 427 { 431 428 AssertPtrReturn(pProcess, VERR_INVALID_POINTER); 432 429 433 430 #ifdef DEBUG 434 V BoxServiceVerbose(4, "[PID %RU32]: Output event phPipeR=%p, idPollHnd=%s, fPollEvt=0x%x\n",435 pProcess->uPID, phPipeR, gstcntlProcessPollHandleToString(idPollHnd), fPollEvt);431 VGSvcVerbose(4, "[PID %RU32]: Output event phPipeR=%p, idPollHnd=%s, fPollEvt=0x%x\n", 432 pProcess->uPID, phPipeR, vgsvcGstCtrlProcessPollHandleToString(idPollHnd), fPollEvt); 436 433 #endif 437 434 … … 449 446 && cbReadable) 450 447 { 451 VBoxServiceVerbose(4, "[PID %RU32]: Output event cbReadable=%zu\n", 452 pProcess->uPID, cbReadable); 448 VGSvcVerbose(4, "[PID %RU32]: Output event cbReadable=%zu\n", pProcess->uPID, cbReadable); 453 449 } 454 450 } … … 461 457 size_t cbRead = 0; 462 458 uint8_t byData[_64K]; 463 rc = RTPipeRead(*phPipeR, 464 byData, sizeof(byData), &cbRead); 465 VBoxServiceVerbose(4, "GstCntlProcessHandleOutputEvent cbRead=%u, rc=%Rrc\n", 466 cbRead, rc); 459 rc = RTPipeRead(*phPipeR, byData, sizeof(byData), &cbRead); 460 VGSvcVerbose(4, "VGSvcGstCtrlProcessHandleOutputEvent cbRead=%u, rc=%Rrc\n", cbRead, rc); 467 461 468 462 /* Make sure we go another poll round in case there was too much data … … 473 467 474 468 if (fPollEvt & RTPOLL_EVT_ERROR) 475 rc = gstcntlProcessHandleOutputError(pProcess, 476 fPollEvt, phPipeR, idPollHnd); 469 rc = vgsvcGstCtrlProcessHandleOutputError(pProcess, fPollEvt, phPipeR, idPollHnd); 477 470 return rc; 478 471 } … … 486 479 * @param pProcess The guest process to handle. 487 480 */ 488 static int gstcntlProcessProcLoop(PVBOXSERVICECTRLPROCESS pProcess)481 static int vgsvcGstCtrlProcessProcLoop(PVBOXSERVICECTRLPROCESS pProcess) 489 482 { 490 483 AssertPtrReturn(pProcess, VERR_INVALID_POINTER); … … 507 500 * the first (stale) entry will be found and we get really weird results! 508 501 */ 509 rc = gstcntlProcessAssignPID(pProcess, pProcess->hProcess /* Opaque PID handle */);502 rc = vgsvcGstCtrlProcessAssignPID(pProcess, pProcess->hProcess /* Opaque PID handle */); 510 503 if (RT_FAILURE(rc)) 511 504 { 512 VBoxServiceError("Unable to assign PID=%u, to new thread, rc=%Rrc\n", 513 pProcess->hProcess, rc); 505 VGSvcError("Unable to assign PID=%u, to new thread, rc=%Rrc\n", pProcess->hProcess, rc); 514 506 return rc; 515 507 } … … 519 511 * and that it's now OK to send input to the process. 520 512 */ 521 V BoxServiceVerbose(2, "[PID %RU32]: Process \"%s\"started, CID=%u, User=%s, cMsTimeout=%RU32\n",513 VGSvcVerbose(2, "[PID %RU32]: Process '%s' started, CID=%u, User=%s, cMsTimeout=%RU32\n", 522 514 pProcess->uPID, pProcess->StartupInfo.szCmd, pProcess->uContextID, 523 515 pProcess->StartupInfo.szUser, pProcess->StartupInfo.uTimeLimitMS); … … 529 521 rc = VINF_SUCCESS; /* SIGCHLD send by quick childs! */ 530 522 if (RT_FAILURE(rc)) 531 VBoxServiceError("[PID %RU32]: Error reporting starting status to host, rc=%Rrc\n", 532 pProcess->uPID, rc); 523 VGSvcError("[PID %RU32]: Error reporting starting status to host, rc=%Rrc\n", pProcess->uPID, rc); 533 524 534 525 /* … … 554 545 { 555 546 case VBOXSERVICECTRLPIPEID_STDIN: 556 rc = gstcntlProcessPollsetOnInput(pProcess, fPollEvt, 557 &pProcess->hPipeStdInW); 547 rc = vgsvcGstCtrlProcessPollsetOnInput(pProcess, fPollEvt, &pProcess->hPipeStdInW); 558 548 break; 559 549 560 550 case VBOXSERVICECTRLPIPEID_STDOUT: 561 rc = gstcntlProcessPollsetOnOutput(pProcess, fPollEvt, 562 &pProcess->hPipeStdOutR, idPollHnd); 551 rc = vgsvcGstCtrlProcessPollsetOnOutput(pProcess, fPollEvt, &pProcess->hPipeStdOutR, idPollHnd); 563 552 break; 564 553 565 554 case VBOXSERVICECTRLPIPEID_STDERR: 566 rc = gstcntlProcessPollsetOnOutput(pProcess, fPollEvt, 567 &pProcess->hPipeStdOutR, idPollHnd); 555 rc = vgsvcGstCtrlProcessPollsetOnOutput(pProcess, fPollEvt, &pProcess->hPipeStdOutR, idPollHnd); 568 556 break; 569 557 570 558 case VBOXSERVICECTRLPIPEID_IPC_NOTIFY: 571 559 #ifdef DEBUG_andy 572 V BoxServiceVerbose(4, "[PID %RU32]: IPC notify\n", pProcess->uPID);573 #endif 574 rc2 = gstcntlProcessLock(pProcess);560 VGSvcVerbose(4, "[PID %RU32]: IPC notify\n", pProcess->uPID); 561 #endif 562 rc2 = vgsvcGstCtrlProcessLock(pProcess); 575 563 if (RT_SUCCESS(rc2)) 576 564 { … … 578 566 uint8_t abBuf[8]; 579 567 size_t cbIgnore; 580 rc2 = RTPipeRead(pProcess->hNotificationPipeR, 581 abBuf, sizeof(abBuf), &cbIgnore); 568 rc2 = RTPipeRead(pProcess->hNotificationPipeR, abBuf, sizeof(abBuf), &cbIgnore); 582 569 if (RT_FAILURE(rc2)) 583 V BoxServiceError("Draining IPC notification pipe failed with rc=%Rrc\n", rc2);570 VGSvcError("Draining IPC notification pipe failed with rc=%Rrc\n", rc2); 584 571 585 572 /* Process all pending requests. */ 586 VBoxServiceVerbose(4, "[PID %RU32]: Processing pending requests ...\n", 587 pProcess->uPID); 573 VGSvcVerbose(4, "[PID %RU32]: Processing pending requests ...\n", pProcess->uPID); 588 574 Assert(pProcess->hReqQueue != NIL_RTREQQUEUE); 589 575 rc2 = RTReqQueueProcess(pProcess->hReqQueue, … … 591 577 if ( RT_FAILURE(rc2) 592 578 && rc2 != VERR_TIMEOUT) 593 V BoxServiceError("Processing requests failed with with rc=%Rrc\n", rc2);594 595 int rc3 = gstcntlProcessUnlock(pProcess);579 VGSvcError("Processing requests failed with with rc=%Rrc\n", rc2); 580 581 int rc3 = vgsvcGstCtrlProcessUnlock(pProcess); 596 582 AssertRC(rc3); 597 583 #ifdef DEBUG 598 VBoxServiceVerbose(4, "[PID %RU32]: Processing pending requests done, rc=%Rrc\n", 599 pProcess->uPID, rc2); 584 VGSvcVerbose(4, "[PID %RU32]: Processing pending requests done, rc=%Rrc\n", pProcess->uPID, rc2); 600 585 #endif 601 586 } … … 612 597 } 613 598 #if 0 614 V BoxServiceVerbose(4, "[PID %RU32]: Polling done, pollRc=%Rrc, pollCnt=%RU32, idPollHnd=%s, rc=%Rrc, fProcessAlive=%RTbool, fShutdown=%RTbool\n",615 pProcess->uPID, rc2, RTPollSetGetCount(hPollSet), gstcntlProcessPollHandleToString(idPollHnd), rc, fProcessAlive, pProcess->fShutdown);616 V BoxServiceVerbose(4, "[PID %RU32]: stdOut=%s, stdErrR=%s\n",617 618 619 599 VGSvcVerbose(4, "[PID %RU32]: Polling done, pollRc=%Rrc, pollCnt=%RU32, idPollHnd=%s, rc=%Rrc, fProcessAlive=%RTbool, fShutdown=%RTbool\n", 600 pProcess->uPID, rc2, RTPollSetGetCount(hPollSet), vgsvcGstCtrlProcessPollHandleToString(idPollHnd), rc, fProcessAlive, pProcess->fShutdown); 601 VGSvcVerbose(4, "[PID %RU32]: stdOut=%s, stdErrR=%s\n", 602 pProcess->uPID, 603 *phStdOutR == NIL_RTPIPE ? "closed" : "open", 604 *phStdErrR == NIL_RTPIPE ? "closed" : "open"); 620 605 #endif 621 606 if (RT_UNLIKELY(pProcess->fShutdown)) … … 629 614 rc2 = RTProcWaitNoResume(pProcess->hProcess, RTPROCWAIT_FLAGS_NOBLOCK, &ProcessStatus); 630 615 #if 0 631 VBoxServiceVerbose(4, "[PID %RU32]: RTProcWaitNoResume=%Rrc\n", 632 pProcess->uPID, rc2); 616 VGSvcVerbose(4, "[PID %RU32]: RTProcWaitNoResume=%Rrc\n", pProcess->uPID, rc2); 633 617 #endif 634 618 if (RT_SUCCESS_NP(rc2)) … … 687 671 break; /* Give up after 20 mins. */ 688 672 689 V BoxServiceVerbose(3, "[PID %RU32]: Timed out (%RU64ms elapsed > %RU32ms timeout), killing ...\n",690 673 VGSvcVerbose(3, "[PID %RU32]: Timed out (%RU64ms elapsed > %RU32ms timeout), killing ...\n", 674 pProcess->uPID, cMsElapsed, pProcess->StartupInfo.uTimeLimitMS); 691 675 692 676 rc2 = RTProcTerminate(pProcess->hProcess); 693 V BoxServiceVerbose(3, "[PID %RU32]: Killing process resulted in rc=%Rrc\n",694 677 VGSvcVerbose(3, "[PID %RU32]: Killing process resulted in rc=%Rrc\n", 678 pProcess->uPID, rc2); 695 679 MsProcessKilled = u64Now; 696 680 continue; … … 710 694 } 711 695 712 V BoxServiceVerbose(3, "[PID %RU32]: Loop ended: rc=%Rrc, fShutdown=%RTbool, fProcessAlive=%RTbool, fProcessTimedOut=%RTbool, MsProcessKilled=%RU64\n",713 714 V BoxServiceVerbose(3, "[PID %RU32]: *phStdOutR=%s, *phStdErrR=%s\n",715 716 717 696 VGSvcVerbose(3, "[PID %RU32]: Loop ended: rc=%Rrc, fShutdown=%RTbool, fProcessAlive=%RTbool, fProcessTimedOut=%RTbool, MsProcessKilled=%RU64\n", 697 pProcess->uPID, rc, pProcess->fShutdown, fProcessAlive, fProcessTimedOut, MsProcessKilled, MsProcessKilled); 698 VGSvcVerbose(3, "[PID %RU32]: *phStdOutR=%s, *phStdErrR=%s\n", 699 pProcess->uPID, 700 pProcess->hPipeStdOutR == NIL_RTPIPE ? "closed" : "open", 701 pProcess->hPipeStdErrR == NIL_RTPIPE ? "closed" : "open"); 718 702 719 703 /* Signal that this thread is in progress of shutting down. */ 720 ASMAtomic XchgBool(&pProcess->fShutdown, true);704 ASMAtomicWriteBool(&pProcess->fShutdown, true); 721 705 722 706 /* … … 727 711 if (MsProcessKilled == UINT64_MAX) 728 712 { 729 VBoxServiceVerbose(2, "[PID %RU32]: Is still alive and not killed yet\n", 730 pProcess->uPID); 713 VGSvcVerbose(2, "[PID %RU32]: Is still alive and not killed yet\n", pProcess->uPID); 731 714 732 715 MsProcessKilled = RTTimeMilliTS(); … … 737 720 } 738 721 else if (RT_FAILURE(rc2)) 739 VBoxServiceError("PID %RU32]: Killing process failed with rc=%Rrc\n", 740 pProcess->uPID, rc2); 722 VGSvcError("PID %RU32]: Killing process failed with rc=%Rrc\n", pProcess->uPID, rc2); 741 723 RTThreadSleep(500); 742 724 } … … 744 726 for (int i = 0; i < 10 && fProcessAlive; i++) 745 727 { 746 VBoxServiceVerbose(4, "[PID %RU32]: Kill attempt %d/10: Waiting to exit ...\n", 747 pProcess->uPID, i + 1); 728 VGSvcVerbose(4, "[PID %RU32]: Kill attempt %d/10: Waiting to exit ...\n", pProcess->uPID, i + 1); 748 729 rc2 = RTProcWait(pProcess->hProcess, RTPROCWAIT_FLAGS_NOBLOCK, &ProcessStatus); 749 730 if (RT_SUCCESS(rc2)) 750 731 { 751 VBoxServiceVerbose(4, "[PID %RU32]: Kill attempt %d/10: Exited\n", 752 pProcess->uPID, i + 1); 732 VGSvcVerbose(4, "[PID %RU32]: Kill attempt %d/10: Exited\n", pProcess->uPID, i + 1); 753 733 fProcessAlive = false; 754 734 break; … … 756 736 if (i >= 5) 757 737 { 758 VBoxServiceVerbose(4, "[PID %RU32]: Kill attempt %d/10: Trying to terminate ...\n", 759 pProcess->uPID, i + 1); 738 VGSvcVerbose(4, "[PID %RU32]: Kill attempt %d/10: Trying to terminate ...\n", pProcess->uPID, i + 1); 760 739 rc2 = RTProcTerminate(pProcess->hProcess); 761 740 if ( RT_FAILURE(rc) 762 741 && rc2 != VERR_NOT_FOUND) 763 V BoxServiceError("PID %RU32]: Killing process failed with rc=%Rrc\n",742 VGSvcError("PID %RU32]: Killing process failed with rc=%Rrc\n", 764 743 pProcess->uPID, rc2); 765 744 } … … 768 747 769 748 if (fProcessAlive) 770 V BoxServiceError("[PID %RU32]: Could not be killed\n", pProcess->uPID);749 VGSvcError("[PID %RU32]: Could not be killed\n", pProcess->uPID); 771 750 } 772 751 … … 783 762 */ 784 763 785 rc2 = gstcntlProcessLock(pProcess);764 rc2 = vgsvcGstCtrlProcessLock(pProcess); 786 765 if (RT_SUCCESS(rc2)) 787 766 { 788 VBoxServiceVerbose(3, "[PID %RU32]: Processing outstanding requests ...\n", 789 pProcess->uPID); 767 VGSvcVerbose(3, "[PID %RU32]: Processing outstanding requests ...\n", pProcess->uPID); 790 768 791 769 /* Process all pending requests (but don't wait for new ones). */ … … 794 772 if ( RT_FAILURE(rc2) 795 773 && rc2 != VERR_TIMEOUT) 796 VBoxServiceError("[PID %RU32]: Processing outstanding requests failed with with rc=%Rrc\n", 797 pProcess->uPID, rc2); 798 799 VBoxServiceVerbose(3, "[PID %RU32]: Processing outstanding requests done, rc=%Rrc\n", 800 pProcess->uPID, rc2); 801 802 rc2 = gstcntlProcessUnlock(pProcess); 774 VGSvcError("[PID %RU32]: Processing outstanding requests failed with with rc=%Rrc\n", pProcess->uPID, rc2); 775 776 VGSvcVerbose(3, "[PID %RU32]: Processing outstanding requests done, rc=%Rrc\n", pProcess->uPID, rc2); 777 778 rc2 = vgsvcGstCtrlProcessUnlock(pProcess); 803 779 AssertRC(rc2); 804 780 } … … 811 787 { 812 788 uint32_t uStatus = PROC_STS_UNDEFINED; 813 uint32_t uFlags = 0;789 uint32_t fFlags = 0; 814 790 815 791 if ( fProcessTimedOut && !fProcessAlive && MsProcessKilled != UINT64_MAX) 816 792 { 817 VBoxServiceVerbose(3, "[PID %RU32]: Timed out and got killed\n", 818 pProcess->uPID); 793 VGSvcVerbose(3, "[PID %RU32]: Timed out and got killed\n", pProcess->uPID); 819 794 uStatus = PROC_STS_TOK; 820 795 } 821 796 else if (fProcessTimedOut && fProcessAlive && MsProcessKilled != UINT64_MAX) 822 797 { 823 VBoxServiceVerbose(3, "[PID %RU32]: Timed out and did *not* get killed\n", 824 pProcess->uPID); 798 VGSvcVerbose(3, "[PID %RU32]: Timed out and did *not* get killed\n", pProcess->uPID); 825 799 uStatus = PROC_STS_TOA; 826 800 } 827 801 else if (pProcess->fShutdown && (fProcessAlive || MsProcessKilled != UINT64_MAX)) 828 802 { 829 VBoxServiceVerbose(3, "[PID %RU32]: Got terminated because system/service is about to shutdown\n", 830 pProcess->uPID); 803 VGSvcVerbose(3, "[PID %RU32]: Got terminated because system/service is about to shutdown\n", pProcess->uPID); 831 804 uStatus = PROC_STS_DWN; /* Service is stopping, process was killed. */ 832 uFlags= pProcess->StartupInfo.uFlags; /* Return handed-in execution flags back to the host. */805 fFlags = pProcess->StartupInfo.uFlags; /* Return handed-in execution flags back to the host. */ 833 806 } 834 807 else if (fProcessAlive) 835 { 836 VBoxServiceError("[PID %RU32]: Is alive when it should not!\n", 837 pProcess->uPID); 838 } 808 VGSvcError("[PID %RU32]: Is alive when it should not!\n", pProcess->uPID); 839 809 else if (MsProcessKilled != UINT64_MAX) 840 { 841 VBoxServiceError("[PID %RU32]: Has been killed when it should not!\n", 842 pProcess->uPID); 843 } 810 VGSvcError("[PID %RU32]: Has been killed when it should not!\n", pProcess->uPID); 844 811 else if (ProcessStatus.enmReason == RTPROCEXITREASON_NORMAL) 845 812 { 846 VBoxServiceVerbose(3, "[PID %RU32]: Ended with RTPROCEXITREASON_NORMAL (Exit code: %d)\n", 847 pProcess->uPID, ProcessStatus.iStatus); 848 813 VGSvcVerbose(3, "[PID %RU32]: Ended with RTPROCEXITREASON_NORMAL (Exit code: %d)\n", 814 pProcess->uPID, ProcessStatus.iStatus); 849 815 uStatus = PROC_STS_TEN; 850 uFlags= ProcessStatus.iStatus;816 fFlags = ProcessStatus.iStatus; 851 817 } 852 818 else if (ProcessStatus.enmReason == RTPROCEXITREASON_SIGNAL) 853 819 { 854 VBoxServiceVerbose(3, "[PID %RU32]: Ended with RTPROCEXITREASON_SIGNAL (Signal: %u)\n", 855 pProcess->uPID, ProcessStatus.iStatus); 856 820 VGSvcVerbose(3, "[PID %RU32]: Ended with RTPROCEXITREASON_SIGNAL (Signal: %u)\n", 821 pProcess->uPID, ProcessStatus.iStatus); 857 822 uStatus = PROC_STS_TES; 858 uFlags= ProcessStatus.iStatus;823 fFlags = ProcessStatus.iStatus; 859 824 } 860 825 else if (ProcessStatus.enmReason == RTPROCEXITREASON_ABEND) 861 826 { 862 827 /* ProcessStatus.iStatus will be undefined. */ 863 VBoxServiceVerbose(3, "[PID %RU32]: Ended with RTPROCEXITREASON_ABEND\n", 864 pProcess->uPID); 865 828 VGSvcVerbose(3, "[PID %RU32]: Ended with RTPROCEXITREASON_ABEND\n", pProcess->uPID); 866 829 uStatus = PROC_STS_TEA; 867 uFlags= ProcessStatus.iStatus;830 fFlags = ProcessStatus.iStatus; 868 831 } 869 832 else 870 VBoxServiceVerbose(1, "[PID %RU32]: Handling process status %u not implemented\n", 871 pProcess->uPID, ProcessStatus.enmReason); 872 873 VBoxServiceVerbose(2, "[PID %RU32]: Ended, ClientID=%u, CID=%u, Status=%u, Flags=0x%x\n", 874 pProcess->uPID, pProcess->uClientID, pProcess->uContextID, uStatus, uFlags); 833 VGSvcVerbose(1, "[PID %RU32]: Handling process status %u not implemented\n", pProcess->uPID, ProcessStatus.enmReason); 834 VGSvcVerbose(2, "[PID %RU32]: Ended, ClientID=%u, CID=%u, Status=%u, Flags=0x%x\n", 835 pProcess->uPID, pProcess->uClientID, pProcess->uContextID, uStatus, fFlags); 875 836 876 837 VBGLR3GUESTCTRLCMDCTX ctxEnd = { pProcess->uClientID, pProcess->uContextID }; 877 rc2 = VbglR3GuestCtrlProcCbStatus(&ctxEnd, 878 pProcess->uPID, uStatus, uFlags, 879 NULL /* pvData */, 0 /* cbData */); 838 rc2 = VbglR3GuestCtrlProcCbStatus(&ctxEnd, pProcess->uPID, uStatus, fFlags, NULL /* pvData */, 0 /* cbData */); 880 839 if ( RT_FAILURE(rc2) 881 840 && rc2 == VERR_NOT_FOUND) 882 VBoxServiceError("[PID %RU32]: Error reporting final status to host; rc=%Rrc\n", 883 pProcess->uPID, rc2); 884 } 885 886 VBoxServiceVerbose(3, "[PID %RU32]: Process loop returned with rc=%Rrc\n", 887 pProcess->uPID, rc); 841 VGSvcError("[PID %RU32]: Error reporting final status to host; rc=%Rrc\n", pProcess->uPID, rc2); 842 } 843 844 VGSvcVerbose(3, "[PID %RU32]: Process loop returned with rc=%Rrc\n", pProcess->uPID, rc); 888 845 return rc; 889 846 } … … 897 854 * @param phPipe The pipe's object to initialize. 898 855 */ 899 static int gstcntlProcessInitPipe(PRTHANDLE ph, PRTPIPE phPipe)856 static int vgsvcGstCtrlProcessInitPipe(PRTHANDLE ph, PRTPIPE phPipe) 900 857 { 901 858 AssertPtrReturn(ph, VERR_INVALID_PARAMETER); … … 924 881 * should service. 925 882 */ 926 static int gstcntlProcessSetupPipe(const char *pszHowTo, int fd, 927 PRTHANDLE ph, PRTHANDLE *pph, PRTPIPE phPipe) 883 static int vgsvcGstCtrlProcessSetupPipe(const char *pszHowTo, int fd, PRTHANDLE ph, PRTHANDLE *pph, PRTPIPE phPipe) 928 884 { 929 885 AssertPtrReturn(ph, VERR_INVALID_POINTER); … … 950 906 rc = RTPipeCreate(&ph->u.hPipe, phPipe, RTPIPE_C_INHERIT_READ); 951 907 } 952 else /* stdout or stderr ?*/908 else /* stdout or stderr. */ 953 909 { 954 910 /* Connect a read pipe specified by phPipe to stdout or stderr. */ … … 993 949 * @param cbExpanded Size (in bytes) of string to store the resolved path. 994 950 */ 995 static int gstcntlProcessMakeFullPath(const char *pszPath, char *pszExpanded, size_t cbExpanded)951 static int vgsvcGstCtrlProcessMakeFullPath(const char *pszPath, char *pszExpanded, size_t cbExpanded) 996 952 { 997 953 int rc = VINF_SUCCESS; 954 /** @todo r=bird: This feature shall be made optional, i.e. require a 955 * flag to be passed down. Further, it shall work on the environment 956 * block of the new process (i.e. include env changes passed down from 957 * the caller). I would also suggest using the unix variable expansion 958 * syntax, not the DOS one. 959 * 960 * Since this currently not available on non-windows guests, I suggest 961 * we disable it until such a time as it is implemented correctly. */ 998 962 #ifdef RT_OS_WINDOWS 999 if (!ExpandEnvironmentStrings(pszPath, pszExpanded, cbExpanded))963 if (!ExpandEnvironmentStrings(pszPath, pszExpanded, (DWORD)cbExpanded)) 1000 964 rc = RTErrConvertFromWin32(GetLastError()); 1001 965 #else … … 1004 968 #endif 1005 969 #ifdef DEBUG 1006 VBoxServiceVerbose(3, "VBoxServiceControlExecMakeFullPath: %s -> %s\n", 1007 pszPath, pszExpanded); 970 VGSvcVerbose(3, "VBoxServiceControlExecMakeFullPath: %s -> %s\n", pszPath, pszExpanded); 1008 971 #endif 1009 972 return rc; … … 1021 984 * @param cbResolved Size (in bytes) of resolved file name string. 1022 985 */ 1023 static int gstcntlProcessResolveExecutable(const char *pszFileName, 1024 char *pszResolved, size_t cbResolved) 986 static int vgsvcGstCtrlProcessResolveExecutable(const char *pszFileName, char *pszResolved, size_t cbResolved) 1025 987 { 1026 988 AssertPtrReturn(pszFileName, VERR_INVALID_POINTER); … … 1046 1008 if (RT_SUCCESS(rc)) 1047 1009 { 1048 rc = gstcntlProcessMakeFullPath(szPathToResolve, pszResolved, cbResolved);1010 rc = vgsvcGstCtrlProcessMakeFullPath(szPathToResolve, pszResolved, cbResolved); 1049 1011 if (RT_SUCCESS(rc)) 1050 VBoxServiceVerbose(3, "Looked up executable: %s -> %s\n", 1051 pszFileName, pszResolved); 1012 VGSvcVerbose(3, "Looked up executable: %s -> %s\n", pszFileName, pszResolved); 1052 1013 } 1053 1014 1054 1015 if (RT_FAILURE(rc)) 1055 VBoxServiceError("Failed to lookup executable \"%s\" with rc=%Rrc\n", 1056 pszFileName, rc); 1016 VGSvcError("Failed to lookup executable '%s' with rc=%Rrc\n", pszFileName, rc); 1057 1017 return rc; 1058 1018 } … … 1070 1030 * Needs to be freed with RTGetOptArgvFree. 1071 1031 */ 1072 static int gstcntlProcessAllocateArgv(const char *pszArgv0, const char * const *papszArgs, uint32_t fFlags,1073 char ***ppapszArgv)1032 static int vgsvcGstCtrlProcessAllocateArgv(const char *pszArgv0, const char * const *papszArgs, uint32_t fFlags, 1033 char ***ppapszArgv) 1074 1034 { 1075 1035 AssertPtrReturn(ppapszArgv, VERR_INVALID_POINTER); 1076 1036 1077 V BoxServiceVerbose(3, "GstCntlProcessPrepareArgv: pszArgv0=%p, papszArgs=%p, fFlags=%#x, ppapszArgv=%p\n",1078 1037 VGSvcVerbose(3, "VGSvcGstCtrlProcessPrepareArgv: pszArgv0=%p, papszArgs=%p, fFlags=%#x, ppapszArgv=%p\n", 1038 pszArgv0, papszArgs, fFlags, ppapszArgv); 1079 1039 1080 1040 int rc = VINF_SUCCESS; … … 1087 1047 1088 1048 /* Allocate new argv vector (adding + 2 for argv0 + termination). */ 1089 size_t cbSize = (cArgs + 2) * sizeof(char *);1090 char **papszNewArgv = (char **)RTMemAlloc(cbSize);1049 size_t cbSize = (cArgs + 2) * sizeof(char *); 1050 char **papszNewArgv = (char **)RTMemAlloc(cbSize); 1091 1051 if (!papszNewArgv) 1092 1052 return VERR_NO_MEMORY; 1093 1053 1094 1054 #ifdef DEBUG 1095 VBoxServiceVerbose(3, "GstCntlProcessAllocateArgv: cbSize=%RU32, cArgs=%RU32\n", 1096 cbSize, cArgs); 1097 #endif 1098 1055 VGSvcVerbose(3, "VGSvcGstCtrlProcessAllocateArgv: cbSize=%RU32, cArgs=%RU32\n", cbSize, cArgs); 1056 #endif 1099 1057 1100 1058 /* HACK ALERT! Since we still don't allow the user to really specify the first … … 1181 1139 * @param uPID PID to assign to the specified guest control execution thread. 1182 1140 */ 1183 int gstcntlProcessAssignPID(PVBOXSERVICECTRLPROCESS pProcess, uint32_t uPID)1141 static int vgsvcGstCtrlProcessAssignPID(PVBOXSERVICECTRLPROCESS pProcess, uint32_t uPID) 1184 1142 { 1185 1143 AssertPtrReturn(pProcess, VERR_INVALID_POINTER); … … 1204 1162 uint32_t uTriedPID = uPID; 1205 1163 uPID += 391939; 1206 V BoxServiceVerbose(2, "PID %RU32 was used before (process %p), trying again with %RU32 ...\n",1164 VGSvcVerbose(2, "PID %RU32 was used before (process %p), trying again with %RU32 ...\n", 1207 1165 uTriedPID, pProcessCur, uPID); 1208 1166 fTryAgain = true; … … 1223 1181 1224 1182 1225 void gstcntlProcessFreeArgv(char **papszArgv)1183 static void vgsvcGstCtrlProcessFreeArgv(char **papszArgv) 1226 1184 { 1227 1185 if (papszArgv) … … 1251 1209 * successful process start. 1252 1210 */ 1253 static int gstcntlProcessCreateProcess(const char *pszExec, const char * const *papszArgs, RTENV hEnv, uint32_t fFlags,1254 PCRTHANDLE phStdIn, PCRTHANDLE phStdOut, PCRTHANDLE phStdErr, const char *pszAsUser,1255 const char *pszPassword, PRTPROCESS phProcess)1211 static int vgsvcGstCtrlProcessCreateProcess(const char *pszExec, const char * const *papszArgs, RTENV hEnv, uint32_t fFlags, 1212 PCRTHANDLE phStdIn, PCRTHANDLE phStdOut, PCRTHANDLE phStdErr, const char *pszAsUser, 1213 const char *pszPassword, PRTPROCESS phProcess) 1256 1214 { 1257 1215 AssertPtrReturn(pszExec, VERR_INVALID_PARAMETER); … … 1297 1255 if ( RT_SUCCESS(rc) 1298 1256 && RTPathExists(szSysWow64)) 1299 V BoxServiceVerbose(0, "Warning: This service is 32-bit; could not execute sysprep on 64-bit OS!\n");1257 VGSvcVerbose(0, "Warning: This service is 32-bit; could not execute sysprep on 64-bit OS!\n"); 1300 1258 #endif 1301 1259 if (RT_SUCCESS(rc)) … … 1305 1263 1306 1264 if (RT_FAILURE(rc)) 1307 V BoxServiceError("Failed to detect sysrep location, rc=%Rrc\n", rc);1265 VGSvcError("Failed to detect sysrep location, rc=%Rrc\n", rc); 1308 1266 } 1309 1267 else if (!fRet) 1310 V BoxServiceError("Failed to retrieve OS information, last error=%ld\n", GetLastError());1311 1312 V BoxServiceVerbose(3, "Sysprep executable is: %s\n", szSysprepCmd);1268 VGSvcError("Failed to retrieve OS information, last error=%ld\n", GetLastError()); 1269 1270 VGSvcVerbose(3, "Sysprep executable is: %s\n", szSysprepCmd); 1313 1271 1314 1272 if (RT_SUCCESS(rc)) 1315 1273 { 1316 1274 char **papszArgsExp; 1317 rc = gstcntlProcessAllocateArgv(szSysprepCmd /* argv0 */, papszArgs, fFlags, &papszArgsExp);1275 rc = vgsvcGstCtrlProcessAllocateArgv(szSysprepCmd /* argv0 */, papszArgs, fFlags, &papszArgsExp); 1318 1276 if (RT_SUCCESS(rc)) 1319 1277 { … … 1324 1282 phStdIn, phStdOut, phStdErr, NULL /* pszAsUser */, 1325 1283 NULL /* pszPassword */, phProcess); 1326 gstcntlProcessFreeArgv(papszArgsExp);1284 vgsvcGstCtrlProcessFreeArgv(papszArgsExp); 1327 1285 } 1328 1286 } 1329 1287 1330 1288 if (RT_FAILURE(rc)) 1331 V BoxServiceVerbose(3, "Starting sysprep returned rc=%Rrc\n", rc);1289 VGSvcVerbose(3, "Starting sysprep returned rc=%Rrc\n", rc); 1332 1290 1333 1291 return rc; … … 1340 1298 /* We want to use the internal toolbox (all internal 1341 1299 * tools are starting with "vbox_" (e.g. "vbox_cat"). */ 1342 rc = gstcntlProcessResolveExecutable(VBOXSERVICE_NAME, szExecExp, sizeof(szExecExp));1300 rc = vgsvcGstCtrlProcessResolveExecutable(VBOXSERVICE_NAME, szExecExp, sizeof(szExecExp)); 1343 1301 } 1344 1302 else … … 1348 1306 * Do the environment variables expansion on executable and arguments. 1349 1307 */ 1350 rc = gstcntlProcessResolveExecutable(pszExec, szExecExp, sizeof(szExecExp));1308 rc = vgsvcGstCtrlProcessResolveExecutable(pszExec, szExecExp, sizeof(szExecExp)); 1351 1309 #ifdef VBOXSERVICE_TOOLBOX 1352 1310 } … … 1357 1315 /** @todo r-bird: pszExec != argv[0]! When are you going to get that?!? How many 1358 1316 * times does this need to be pointed out? HOST/GUEST INTERFACE IS MISDESIGNED! */ 1359 rc = gstcntlProcessAllocateArgv(pszExec /* Always use the unmodified executable name as argv0. */,1360 papszArgs /* Append the rest of the argument vector (if any). */,1361 fFlags, &papszArgsExp);1317 rc = vgsvcGstCtrlProcessAllocateArgv(pszExec /* Always use the unmodified executable name as argv0. */, 1318 papszArgs /* Append the rest of the argument vector (if any). */, 1319 fFlags, &papszArgsExp); 1362 1320 if (RT_FAILURE(rc)) 1363 1321 { 1364 1322 /* Don't print any arguments -- may contain passwords or other sensible data! */ 1365 V BoxServiceError("Could not prepare arguments, rc=%Rrc\n", rc);1323 VGSvcError("Could not prepare arguments, rc=%Rrc\n", rc); 1366 1324 } 1367 1325 else … … 1388 1346 uProcFlags |= RTPROC_FLAGS_SERVICE; 1389 1347 #ifdef DEBUG 1390 V BoxServiceVerbose(3, "Command: %s\n", szExecExp);1348 VGSvcVerbose(3, "Command: %s\n", szExecExp); 1391 1349 for (size_t i = 0; papszArgsExp[i]; i++) 1392 V BoxServiceVerbose(3, "\targv[%ld]: %s\n", i, papszArgsExp[i]);1393 #endif 1394 V BoxServiceVerbose(3, "Starting process \"%s\"...\n", szExecExp);1350 VGSvcVerbose(3, "\targv[%ld]: %s\n", i, papszArgsExp[i]); 1351 #endif 1352 VGSvcVerbose(3, "Starting process '%s' ...\n", szExecExp); 1395 1353 1396 1354 /* Do normal execution. */ … … 1401 1359 phProcess); 1402 1360 1403 VBoxServiceVerbose(3, "Starting process \"%s\" returned rc=%Rrc\n", 1404 szExecExp, rc); 1405 1406 gstcntlProcessFreeArgv(papszArgsExp); 1361 VGSvcVerbose(3, "Starting process '%s' returned rc=%Rrc\n", szExecExp, rc); 1362 1363 vgsvcGstCtrlProcessFreeArgv(papszArgsExp); 1407 1364 } 1408 1365 } … … 1412 1369 1413 1370 #ifdef DEBUG 1414 static int gstcntlProcessDumpToFile(const char *pszFileName, void *pvBuf, size_t cbBuf)1371 static int vgsvcGstCtrlProcessDumpToFile(const char *pszFileName, void *pvBuf, size_t cbBuf) 1415 1372 { 1416 1373 AssertPtrReturn(pszFileName, VERR_INVALID_POINTER); … … 1428 1385 if (RT_SUCCESS(rc)) 1429 1386 { 1430 V BoxServiceVerbose(4, "Dumping %ld bytes to \"%s\"\n", cbBuf, szFile);1387 VGSvcVerbose(4, "Dumping %ld bytes to '%s'\n", cbBuf, szFile); 1431 1388 1432 1389 RTFILE fh; … … 1441 1398 return rc; 1442 1399 } 1443 #endif 1400 #endif /* DEBUG */ 1444 1401 1445 1402 … … 1450 1407 * @param PVBOXSERVICECTRLPROCESS Guest process. 1451 1408 */ 1452 static int gstcntlProcessProcessWorker(PVBOXSERVICECTRLPROCESS pProcess)1409 static int vgsvcGstCtrlProcessProcessWorker(PVBOXSERVICECTRLPROCESS pProcess) 1453 1410 { 1454 1411 AssertPtrReturn(pProcess, VERR_INVALID_POINTER); 1455 VBoxServiceVerbose(3, "Thread of process pThread=0x%p = \"%s\" started\n", 1456 pProcess, pProcess->StartupInfo.szCmd); 1412 VGSvcVerbose(3, "Thread of process pThread=0x%p = '%s' started\n", pProcess, pProcess->StartupInfo.szCmd); 1457 1413 1458 1414 int rc = VbglR3GuestCtrlConnect(&pProcess->uClientID); 1459 1415 if (RT_FAILURE(rc)) 1460 1416 { 1461 V BoxServiceError("Process thread \"%s\"(%p) failed to connect to the guest control service, rc=%Rrc\n",1462 1417 VGSvcError("Process thread '%s' (%p) failed to connect to the guest control service, rc=%Rrc\n", 1418 pProcess->StartupInfo.szCmd, pProcess, rc); 1463 1419 RTThreadUserSignal(RTThreadSelf()); 1464 1420 return rc; 1465 1421 } 1466 1422 1467 V BoxServiceVerbose(3, "Guest process \"%s\"got client ID=%u, flags=0x%x\n",1468 1423 VGSvcVerbose(3, "Guest process '%s' got client ID=%u, flags=0x%x\n", 1424 pProcess->StartupInfo.szCmd, pProcess->uClientID, pProcess->StartupInfo.uFlags); 1469 1425 1470 1426 /* The process thread is not interested in receiving any commands; … … 1474 1430 if (RT_FAILURE(rc)) 1475 1431 { 1476 V BoxServiceError("Unable to set message filter, rc=%Rrc\n", rc);1432 VGSvcError("Unable to set message filter, rc=%Rrc\n", rc); 1477 1433 /* Non-critical. */ 1478 1434 } 1479 1435 1480 rc = GstCntlSessionProcessAdd(pProcess->pSession, pProcess);1436 rc = VGSvcGstCtrlSessionProcessAdd(pProcess->pSession, pProcess); 1481 1437 if (RT_FAILURE(rc)) 1482 1438 { 1483 V BoxServiceError("Errorwhile adding guest process \"%s\"(%p) to session process list, rc=%Rrc\n",1484 1439 VGSvcError("Errorwhile adding guest process '%s' (%p) to session process list, rc=%Rrc\n", 1440 pProcess->StartupInfo.szCmd, pProcess, rc); 1485 1441 RTThreadUserSignal(RTThreadSelf()); 1486 1442 return rc; … … 1563 1519 RTHANDLE hStdIn; 1564 1520 PRTHANDLE phStdIn; 1565 rc = gstcntlProcessSetupPipe("|", 0 /*STDIN_FILENO*/,1521 rc = vgsvcGstCtrlProcessSetupPipe("|", 0 /*STDIN_FILENO*/, 1566 1522 &hStdIn, &phStdIn, &pProcess->hPipeStdInW); 1567 1523 if (RT_SUCCESS(rc)) … … 1569 1525 RTHANDLE hStdOut; 1570 1526 PRTHANDLE phStdOut; 1571 rc = gstcntlProcessSetupPipe( (pProcess->StartupInfo.uFlags & EXECUTEPROCESSFLAG_WAIT_STDOUT)1527 rc = vgsvcGstCtrlProcessSetupPipe( (pProcess->StartupInfo.uFlags & EXECUTEPROCESSFLAG_WAIT_STDOUT) 1572 1528 ? "|" : "/dev/null", 1573 1529 1 /*STDOUT_FILENO*/, … … 1577 1533 RTHANDLE hStdErr; 1578 1534 PRTHANDLE phStdErr; 1579 rc = gstcntlProcessSetupPipe( (pProcess->StartupInfo.uFlags & EXECUTEPROCESSFLAG_WAIT_STDERR)1535 rc = vgsvcGstCtrlProcessSetupPipe( (pProcess->StartupInfo.uFlags & EXECUTEPROCESSFLAG_WAIT_STDERR) 1580 1536 ? "|" : "/dev/null", 1581 1537 2 /*STDERR_FILENO*/, … … 1618 1574 bool fNeedsImpersonation = !(pProcess->pSession->fFlags & VBOXSERVICECTRLSESSION_FLAG_SPAWN); 1619 1575 1620 rc = gstcntlProcessCreateProcess(pProcess->StartupInfo.szCmd, papszArgs, hEnv,1576 rc = vgsvcGstCtrlProcessCreateProcess(pProcess->StartupInfo.szCmd, papszArgs, hEnv, 1621 1577 pProcess->StartupInfo.uFlags, 1622 1578 phStdIn, phStdOut, phStdErr, … … 1625 1581 &pProcess->hProcess); 1626 1582 if (RT_FAILURE(rc)) 1627 V BoxServiceError("Error starting process, rc=%Rrc\n", rc);1583 VGSvcError("Error starting process, rc=%Rrc\n", rc); 1628 1584 /* 1629 1585 * Tell the session thread that it can continue … … 1650 1606 1651 1607 /* Enter the process main loop. */ 1652 rc = gstcntlProcessProcLoop(pProcess);1608 rc = vgsvcGstCtrlProcessProcLoop(pProcess); 1653 1609 1654 1610 /* … … 1712 1668 if ( RT_FAILURE(rc2) 1713 1669 && rc2 != VERR_NOT_FOUND) 1714 V BoxServiceError("[PID %RU32]: Could not report process failure error; rc=%Rrc (process error %Rrc)\n",1715 1670 VGSvcError("[PID %RU32]: Could not report process failure error; rc=%Rrc (process error %Rrc)\n", 1671 pProcess->uPID, rc2, rc); 1716 1672 } 1717 1673 1718 1674 /* Disconnect this client from the guest control service. This also cancels all 1719 1675 * outstanding host requests. */ 1720 VBoxServiceVerbose(3, "[PID %RU32]: Disconnecting (client ID=%u) ...\n", 1721 pProcess->uPID, pProcess->uClientID); 1676 VGSvcVerbose(3, "[PID %RU32]: Disconnecting (client ID=%u) ...\n", pProcess->uPID, pProcess->uClientID); 1722 1677 VbglR3GuestCtrlDisconnect(pProcess->uClientID); 1723 1678 pProcess->uClientID = 0; … … 1741 1696 RTThreadUserSignal(RTThreadSelf()); 1742 1697 1743 V BoxServiceVerbose(3, "[PID %RU32]: Thread of process \"%s\"ended with rc=%Rrc\n",1744 1698 VGSvcVerbose(3, "[PID %RU32]: Thread of process '%s' ended with rc=%Rrc\n", 1699 pProcess->uPID, pProcess->StartupInfo.szCmd, rc); 1745 1700 1746 1701 /* Finally, update stopped status. */ … … 1751 1706 1752 1707 1753 static int gstcntlProcessLock(PVBOXSERVICECTRLPROCESS pProcess)1708 static int vgsvcGstCtrlProcessLock(PVBOXSERVICECTRLPROCESS pProcess) 1754 1709 { 1755 1710 AssertPtrReturn(pProcess, VERR_INVALID_POINTER); … … 1768 1723 * 1769 1724 */ 1770 static DECLCALLBACK(int) gstcntlProcessThread(RTTHREAD ThreadSelf, void *pvUser)1725 static DECLCALLBACK(int) vgsvcGstCtrlProcessThread(RTTHREAD ThreadSelf, void *pvUser) 1771 1726 { 1772 1727 PVBOXSERVICECTRLPROCESS pProcess = (VBOXSERVICECTRLPROCESS*)pvUser; 1773 1728 AssertPtrReturn(pProcess, VERR_INVALID_POINTER); 1774 return gstcntlProcessProcessWorker(pProcess);1775 } 1776 1777 1778 static int gstcntlProcessUnlock(PVBOXSERVICECTRLPROCESS pProcess)1729 return vgsvcGstCtrlProcessProcessWorker(pProcess); 1730 } 1731 1732 1733 static int vgsvcGstCtrlProcessUnlock(PVBOXSERVICECTRLPROCESS pProcess) 1779 1734 { 1780 1735 AssertPtrReturn(pProcess, VERR_INVALID_POINTER); … … 1795 1750 1796 1751 */ 1797 int GstCntlProcessStart(const PVBOXSERVICECTRLSESSION pSession, 1798 const PVBOXSERVICECTRLPROCSTARTUPINFO pStartupInfo, 1799 uint32_t uContextID) 1752 int VGSvcGstCtrlProcessStart(const PVBOXSERVICECTRLSESSION pSession, 1753 const PVBOXSERVICECTRLPROCSTARTUPINFO pStartupInfo, uint32_t uContextID) 1800 1754 { 1801 1755 AssertPtrReturn(pSession, VERR_INVALID_POINTER); … … 1809 1763 return VERR_NO_MEMORY; 1810 1764 1811 int rc = gstcntlProcessInit(pProcess, pSession, pStartupInfo, uContextID);1765 int rc = vgsvcGstCtrlProcessInit(pProcess, pSession, pStartupInfo, uContextID); 1812 1766 if (RT_SUCCESS(rc)) 1813 1767 { … … 1815 1769 if (s_uCtrlExecThread++ == UINT32_MAX) 1816 1770 s_uCtrlExecThread = 0; /* Wrap around to not let IPRT freak out. */ 1817 rc = RTThreadCreateF(&pProcess->Thread, gstcntlProcessThread,1771 rc = RTThreadCreateF(&pProcess->Thread, vgsvcGstCtrlProcessThread, 1818 1772 pProcess /*pvUser*/, 0 /*cbStack*/, 1819 1773 RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "gctl%u", s_uCtrlExecThread); 1820 1774 if (RT_FAILURE(rc)) 1821 1775 { 1822 V BoxServiceError("Creating thread for guest process \"%s\"failed: rc=%Rrc, pProcess=%p\n",1823 1824 1825 GstCntlProcessFree(pProcess);1776 VGSvcError("Creating thread for guest process '%s' failed: rc=%Rrc, pProcess=%p\n", 1777 pStartupInfo->szCmd, rc, pProcess); 1778 1779 VGSvcGstCtrlProcessFree(pProcess); 1826 1780 } 1827 1781 else 1828 1782 { 1829 V BoxServiceVerbose(4, "Waiting for thread to initialize ...\n");1783 VGSvcVerbose(4, "Waiting for thread to initialize ...\n"); 1830 1784 1831 1785 /* Wait for the thread to initialize. */ … … 1835 1789 || RT_FAILURE(rc)) 1836 1790 { 1837 VBoxServiceError("Thread for process \"%s\" failed to start, rc=%Rrc\n", 1838 pStartupInfo->szCmd, rc); 1839 1840 GstCntlProcessFree(pProcess); 1791 VGSvcError("Thread for process '%s' failed to start, rc=%Rrc\n", pStartupInfo->szCmd, rc); 1792 VGSvcGstCtrlProcessFree(pProcess); 1841 1793 } 1842 1794 else … … 1851 1803 1852 1804 1853 static DECLCALLBACK(int) gstcntlProcessOnInput(PVBOXSERVICECTRLPROCESS pThis,1854 const PVBGLR3GUESTCTRLCMDCTX pHostCtx,1855 bool fPendingClose, void *pvBuf, uint32_t cbBuf)1805 static DECLCALLBACK(int) vgsvcGstCtrlProcessOnInput(PVBOXSERVICECTRLPROCESS pThis, 1806 const PVBGLR3GUESTCTRLCMDCTX pHostCtx, 1807 bool fPendingClose, void *pvBuf, uint32_t cbBuf) 1856 1808 { 1857 1809 AssertPtrReturn(pThis, VERR_INVALID_POINTER); … … 1864 1816 { 1865 1817 if (pThis->hPipeStdInW != NIL_RTPIPE) 1866 { 1867 rc = RTPipeWrite(pThis->hPipeStdInW, 1868 pvBuf, cbBuf, &cbWritten); 1869 } 1818 rc = RTPipeWrite(pThis->hPipeStdInW, pvBuf, cbBuf, &cbWritten); 1870 1819 else 1871 1820 rc = VINF_EOF; … … 1880 1829 */ 1881 1830 if ( fPendingClose 1882 && (cbBuf == cbWritten))1883 { 1884 int rc2 = gstcntlProcessPollsetCloseInput(pThis, &pThis->hPipeStdInW);1831 && cbBuf == cbWritten) 1832 { 1833 int rc2 = vgsvcGstCtrlProcessPollsetCloseInput(pThis, &pThis->hPipeStdInW); 1885 1834 if (RT_SUCCESS(rc)) 1886 1835 rc = rc2; … … 1888 1837 1889 1838 uint32_t uStatus = INPUT_STS_UNDEFINED; /* Status to send back to the host. */ 1890 uint32_t uFlags = 0; /* No flags at the moment. */1839 uint32_t fFlags = 0; /* No flags at the moment. */ 1891 1840 if (RT_SUCCESS(rc)) 1892 1841 { 1893 V BoxServiceVerbose(4, "[PID %RU32]: Written %RU32 bytes input, CID=%RU32, fPendingClose=%RTbool\n",1894 1842 VGSvcVerbose(4, "[PID %RU32]: Written %RU32 bytes input, CID=%RU32, fPendingClose=%RTbool\n", 1843 pThis->uPID, cbWritten, pHostCtx->uContextID, fPendingClose); 1895 1844 uStatus = INPUT_STS_WRITTEN; 1896 1845 } … … 1912 1861 { 1913 1862 uStatus = INPUT_STS_ERROR; 1914 uFlags = rc;1863 fFlags = rc; /* funny thing to call a "flag"... */ 1915 1864 } 1916 1865 Assert(uStatus > INPUT_STS_UNDEFINED); 1917 1866 1918 #ifdef DEBUG 1919 1920 #endif 1921 int rc2 = VbglR3GuestCtrlProcCbStatusInput(pHostCtx, pThis->uPID, 1922 uStatus, uFlags, (uint32_t)cbWritten); 1867 int rc2 = VbglR3GuestCtrlProcCbStatusInput(pHostCtx, pThis->uPID, uStatus, fFlags, (uint32_t)cbWritten); 1923 1868 if (RT_SUCCESS(rc)) 1924 1869 rc = rc2; 1925 1870 1926 1871 #ifdef DEBUG 1927 VBoxServiceVerbose(3, "[PID %RU32]: gstcntlProcessOnInput returned with rc=%Rrc\n", 1928 pThis->uPID, rc); 1872 VGSvcVerbose(3, "[PID %RU32]: vgsvcGstCtrlProcessOnInput returned with rc=%Rrc\n", pThis->uPID, rc); 1929 1873 #endif 1930 1874 return VINF_SUCCESS; /** @todo Return rc here as soon as RTReqQueue todos are fixed. */ … … 1932 1876 1933 1877 1934 static DECLCALLBACK(int) gstcntlProcessOnOutput(PVBOXSERVICECTRLPROCESS pThis,1935 const PVBGLR3GUESTCTRLCMDCTX pHostCtx,1936 uint32_t uHandle, uint32_t cbToRead, uint32_t uFlags)1878 static DECLCALLBACK(int) vgsvcGstCtrlProcessOnOutput(PVBOXSERVICECTRLPROCESS pThis, 1879 const PVBGLR3GUESTCTRLCMDCTX pHostCtx, 1880 uint32_t uHandle, uint32_t cbToRead, uint32_t fFlags) 1937 1881 { 1938 1882 AssertPtrReturn(pThis, VERR_INVALID_POINTER); … … 1948 1892 if (pvBuf) 1949 1893 { 1950 PRTPIPE phPipe = 1951 1952 1894 PRTPIPE phPipe = uHandle == OUTPUT_HANDLE_ID_STDOUT 1895 ? &pThis->hPipeStdOutR 1896 : &pThis->hPipeStdErrR; 1953 1897 AssertPtr(phPipe); 1954 1898 … … 1978 1922 ) 1979 1923 { 1924 /** @todo r=bird: vgsvcGstCtrlProcessDumpToFile(void *pvBuf, size_t cbBuf, const char *pszFileNmFmt, ...) */ 1980 1925 char szDumpFile[RTPATH_MAX]; 1981 1926 if (!RTStrPrintf(szDumpFile, sizeof(szDumpFile), "VBoxService_Session%RU32_PID%RU32_StdOut.txt", 1982 1927 pSession->StartupInfo.uSessionID, pThis->uPID)) rc = VERR_BUFFER_UNDERFLOW; 1983 1928 if (RT_SUCCESS(rc)) 1984 rc = gstcntlProcessDumpToFile(szDumpFile, pvBuf, cbRead);1929 rc = vgsvcGstCtrlProcessDumpToFile(szDumpFile, pvBuf, cbRead); 1985 1930 AssertRC(rc); 1986 1931 } … … 1993 1938 rc = VERR_BUFFER_UNDERFLOW; 1994 1939 if (RT_SUCCESS(rc)) 1995 rc = gstcntlProcessDumpToFile(szDumpFile, pvBuf, cbRead);1940 rc = vgsvcGstCtrlProcessDumpToFile(szDumpFile, pvBuf, cbRead); 1996 1941 AssertRC(rc); 1997 1942 } … … 2002 1947 { 2003 1948 #ifdef DEBUG 2004 V BoxServiceVerbose(3, "[PID %RU32]: Read %RU32 bytes output: uHandle=%RU32, CID=%RU32, uFlags=%x\n",2005 pThis->uPID, cbRead, uHandle, pHostCtx->uContextID, uFlags);1949 VGSvcVerbose(3, "[PID %RU32]: Read %RU32 bytes output: uHandle=%RU32, CID=%RU32, fFlags=%x\n", 1950 pThis->uPID, cbRead, uHandle, pHostCtx->uContextID, fFlags); 2006 1951 #endif 2007 1952 /** Note: Don't convert/touch/modify/whatever the output data here! This might be binary … … 2011 1956 * regardless whether we got data or not! Otherwise the waiting events 2012 1957 * on the host never will get completed! */ 2013 rc = VbglR3GuestCtrlProcCbOutput(pHostCtx, pThis->uPID, uHandle, uFlags,2014 pvBuf,cbRead);1958 Assert((uint32_t)cbRead == cbRead); 1959 rc = VbglR3GuestCtrlProcCbOutput(pHostCtx, pThis->uPID, uHandle, fFlags, pvBuf, (uint32_t)cbRead); 2015 1960 if ( RT_FAILURE(rc) 2016 1961 && rc == VERR_NOT_FOUND) /* Not critical if guest PID is not found on the host (anymore). */ … … 2024 1969 2025 1970 #ifdef DEBUG 2026 VBoxServiceVerbose(3, "[PID %RU32]: Reading output returned with rc=%Rrc\n", 2027 pThis->uPID, rc); 1971 VGSvcVerbose(3, "[PID %RU32]: Reading output returned with rc=%Rrc\n", pThis->uPID, rc); 2028 1972 #endif 2029 1973 return VINF_SUCCESS; /** @todo Return rc here as soon as RTReqQueue todos are fixed. */ … … 2031 1975 2032 1976 2033 static DECLCALLBACK(int) gstcntlProcessOnTerm(PVBOXSERVICECTRLPROCESS pThis)1977 static DECLCALLBACK(int) vgsvcGstCtrlProcessOnTerm(PVBOXSERVICECTRLPROCESS pThis) 2034 1978 { 2035 1979 AssertPtrReturn(pThis, VERR_INVALID_POINTER); 2036 1980 2037 1981 if (!ASMAtomicXchgBool(&pThis->fShutdown, true)) 2038 { 2039 VBoxServiceVerbose(3, "[PID %RU32]: Setting shutdown flag ...\n", 2040 pThis->uPID); 2041 } 1982 VGSvcVerbose(3, "[PID %RU32]: Setting shutdown flag ...\n", pThis->uPID); 2042 1983 2043 1984 return VINF_SUCCESS; /** @todo Return rc here as soon as RTReqQueue todos are fixed. */ … … 2045 1986 2046 1987 2047 int gstcntlProcessRequestExV(PVBOXSERVICECTRLPROCESS pProcess, const PVBGLR3GUESTCTRLCMDCTX pHostCtx, 2048 bool fAsync, RTMSINTERVAL uTimeoutMS, PRTREQ pReq, PFNRT pfnFunction, 2049 unsigned cArgs, va_list Args) 1988 static int vgsvcGstCtrlProcessRequestExV(PVBOXSERVICECTRLPROCESS pProcess, const PVBGLR3GUESTCTRLCMDCTX pHostCtx, bool fAsync, 1989 RTMSINTERVAL uTimeoutMS, PRTREQ pReq, PFNRT pfnFunction, unsigned cArgs, va_list Args) 2050 1990 { 2051 1991 AssertPtrReturn(pProcess, VERR_INVALID_POINTER); … … 2055 1995 AssertPtrReturn(pfnFunction, VERR_INVALID_POINTER); 2056 1996 2057 int rc = gstcntlProcessLock(pProcess);1997 int rc = vgsvcGstCtrlProcessLock(pProcess); 2058 1998 if (RT_SUCCESS(rc)) 2059 1999 { 2060 2000 #ifdef DEBUG 2061 VBoxServiceVerbose(3, "[PID %RU32]: gstcntlProcessRequestExV fAsync=%RTbool, uTimeoutMS=%RU32, cArgs=%u\n",2062 2063 #endif 2064 uint32_t uFlags = RTREQFLAGS_IPRT_STATUS;2001 VGSvcVerbose(3, "[PID %RU32]: vgsvcGstCtrlProcessRequestExV fAsync=%RTbool, uTimeoutMS=%RU32, cArgs=%u\n", 2002 pProcess->uPID, fAsync, uTimeoutMS, cArgs); 2003 #endif 2004 uint32_t fFlags = RTREQFLAGS_IPRT_STATUS; 2065 2005 if (fAsync) 2066 2006 { 2067 2007 Assert(uTimeoutMS == 0); 2068 uFlags |= RTREQFLAGS_NO_WAIT; 2069 } 2070 2071 rc = RTReqQueueCallV(pProcess->hReqQueue, &pReq, uTimeoutMS, uFlags, 2072 pfnFunction, cArgs, Args); 2008 fFlags |= RTREQFLAGS_NO_WAIT; 2009 } 2010 2011 rc = RTReqQueueCallV(pProcess->hReqQueue, &pReq, uTimeoutMS, fFlags, pfnFunction, cArgs, Args); 2073 2012 if (RT_SUCCESS(rc)) 2074 2013 { … … 2081 2020 && cbWritten != 1) 2082 2021 { 2083 V BoxServiceError("[PID %RU32]: Notification pipe got %zu bytes instead of 1\n",2022 VGSvcError("[PID %RU32]: Notification pipe got %zu bytes instead of 1\n", 2084 2023 pProcess->uPID, cbWritten); 2085 2024 } 2086 2025 else if (RT_UNLIKELY(RT_FAILURE(rc))) 2087 V BoxServiceError("[PID %RU32]: Writing to notification pipe failed, rc=%Rrc\n",2026 VGSvcError("[PID %RU32]: Writing to notification pipe failed, rc=%Rrc\n", 2088 2027 pProcess->uPID, rc); 2089 2028 } 2090 2029 else 2091 V BoxServiceError("[PID %RU32]: RTReqQueueCallV failed, rc=%Rrc\n",2030 VGSvcError("[PID %RU32]: RTReqQueueCallV failed, rc=%Rrc\n", 2092 2031 pProcess->uPID, rc); 2093 2032 2094 int rc2 = gstcntlProcessUnlock(pProcess);2033 int rc2 = vgsvcGstCtrlProcessUnlock(pProcess); 2095 2034 if (RT_SUCCESS(rc)) 2096 2035 rc = rc2; … … 2098 2037 2099 2038 #ifdef DEBUG 2100 VBoxServiceVerbose(3, "[PID %RU32]: gstcntlProcessRequestExV returned rc=%Rrc\n", 2101 pProcess->uPID, rc); 2039 VGSvcVerbose(3, "[PID %RU32]: vgsvcGstCtrlProcessRequestExV returned rc=%Rrc\n", pProcess->uPID, rc); 2102 2040 #endif 2103 2041 return rc; … … 2105 2043 2106 2044 2107 int gstcntlProcessRequestAsync(PVBOXSERVICECTRLPROCESS pProcess, const PVBGLR3GUESTCTRLCMDCTX pHostCtx,2108 PFNRT pfnFunction, unsigned cArgs, ...)2045 static int vgsvcGstCtrlProcessRequestAsync(PVBOXSERVICECTRLPROCESS pProcess, const PVBGLR3GUESTCTRLCMDCTX pHostCtx, 2046 PFNRT pfnFunction, unsigned cArgs, ...) 2109 2047 { 2110 2048 AssertPtrReturn(pProcess, VERR_INVALID_POINTER); … … 2114 2052 va_list va; 2115 2053 va_start(va, cArgs); 2116 int rc = gstcntlProcessRequestExV(pProcess, pHostCtx, true /* fAsync */, 0 /* uTimeoutMS */,2117 NULL /* pReq */, pfnFunction, cArgs, va);2054 int rc = vgsvcGstCtrlProcessRequestExV(pProcess, pHostCtx, true /* fAsync */, 0 /* uTimeoutMS */, 2055 NULL /* pReq */, pfnFunction, cArgs, va); 2118 2056 va_end(va); 2119 2057 … … 2122 2060 2123 2061 2124 int gstcntlProcessRequestWait(PVBOXSERVICECTRLPROCESS pProcess, const PVBGLR3GUESTCTRLCMDCTX pHostCtx, 2125 RTMSINTERVAL uTimeoutMS, PRTREQ pReq, PFNRT pfnFunction, unsigned cArgs, ...) 2062 #if 0 /* unused */ 2063 static int vgsvcGstCtrlProcessRequestWait(PVBOXSERVICECTRLPROCESS pProcess, const PVBGLR3GUESTCTRLCMDCTX pHostCtx, 2064 RTMSINTERVAL uTimeoutMS, PRTREQ pReq, PFNRT pfnFunction, unsigned cArgs, ...) 2126 2065 { 2127 2066 AssertPtrReturn(pProcess, VERR_INVALID_POINTER); … … 2131 2070 va_list va; 2132 2071 va_start(va, cArgs); 2133 int rc = gstcntlProcessRequestExV(pProcess, pHostCtx, false /* fAsync */, uTimeoutMS,2134 pReq, pfnFunction, cArgs, va);2072 int rc = vgsvcGstCtrlProcessRequestExV(pProcess, pHostCtx, false /* fAsync */, uTimeoutMS, 2073 pReq, pfnFunction, cArgs, va); 2135 2074 va_end(va); 2136 2075 2137 2076 return rc; 2138 2077 } 2139 2140 2141 int GstCntlProcessHandleInput(PVBOXSERVICECTRLPROCESS pProcess, PVBGLR3GUESTCTRLCMDCTX pHostCtx, 2142 bool fPendingClose, void *pvBuf, uint32_t cbBuf) 2078 #endif 2079 2080 2081 int VGSvcGstCtrlProcessHandleInput(PVBOXSERVICECTRLPROCESS pProcess, PVBGLR3GUESTCTRLCMDCTX pHostCtx, 2082 bool fPendingClose, void *pvBuf, uint32_t cbBuf) 2143 2083 { 2144 2084 if (!ASMAtomicReadBool(&pProcess->fShutdown)) 2145 return gstcntlProcessRequestAsync(pProcess, pHostCtx, (PFNRT)gstcntlProcessOnInput,2146 5 /* cArgs */, pProcess, pHostCtx, fPendingClose, pvBuf, cbBuf);2147 2148 return gstcntlProcessOnInput(pProcess, pHostCtx, fPendingClose, pvBuf, cbBuf);2149 } 2150 2151 2152 int GstCntlProcessHandleOutput(PVBOXSERVICECTRLPROCESS pProcess, PVBGLR3GUESTCTRLCMDCTX pHostCtx,2153 uint32_t uHandle, uint32_t cbToRead, uint32_t uFlags)2085 return vgsvcGstCtrlProcessRequestAsync(pProcess, pHostCtx, (PFNRT)vgsvcGstCtrlProcessOnInput, 2086 5 /* cArgs */, pProcess, pHostCtx, fPendingClose, pvBuf, cbBuf); 2087 2088 return vgsvcGstCtrlProcessOnInput(pProcess, pHostCtx, fPendingClose, pvBuf, cbBuf); 2089 } 2090 2091 2092 int VGSvcGstCtrlProcessHandleOutput(PVBOXSERVICECTRLPROCESS pProcess, PVBGLR3GUESTCTRLCMDCTX pHostCtx, 2093 uint32_t uHandle, uint32_t cbToRead, uint32_t fFlags) 2154 2094 { 2155 2095 if (!ASMAtomicReadBool(&pProcess->fShutdown)) 2156 return gstcntlProcessRequestAsync(pProcess, pHostCtx, (PFNRT)gstcntlProcessOnOutput,2157 5 /* cArgs */, pProcess, pHostCtx, uHandle, cbToRead, uFlags);2158 2159 return gstcntlProcessOnOutput(pProcess, pHostCtx, uHandle, cbToRead, uFlags);2160 } 2161 2162 2163 int GstCntlProcessHandleTerm(PVBOXSERVICECTRLPROCESS pProcess)2096 return vgsvcGstCtrlProcessRequestAsync(pProcess, pHostCtx, (PFNRT)vgsvcGstCtrlProcessOnOutput, 2097 5 /* cArgs */, pProcess, pHostCtx, uHandle, cbToRead, fFlags); 2098 2099 return vgsvcGstCtrlProcessOnOutput(pProcess, pHostCtx, uHandle, cbToRead, fFlags); 2100 } 2101 2102 2103 int VGSvcGstCtrlProcessHandleTerm(PVBOXSERVICECTRLPROCESS pProcess) 2164 2104 { 2165 2105 if (!ASMAtomicReadBool(&pProcess->fShutdown)) 2166 return gstcntlProcessRequestAsync(pProcess, NULL /* pHostCtx */, (PFNRT)gstcntlProcessOnTerm,2167 1 /* cArgs */, pProcess);2168 2169 return gstcntlProcessOnTerm(pProcess);2170 } 2171 2106 return vgsvcGstCtrlProcessRequestAsync(pProcess, NULL /* pHostCtx */, (PFNRT)vgsvcGstCtrlProcessOnTerm, 2107 1 /* cArgs */, pProcess); 2108 2109 return vgsvcGstCtrlProcessOnTerm(pProcess); 2110 } 2111 -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlSession.cpp
r58023 r58029 42 42 43 43 /********************************************************************************************************************************* 44 * Externals*44 * Structures and Typedefs * 45 45 *********************************************************************************************************************************/ 46 extern RTLISTANCHOR g_lstControlSessionThreads;47 extern VBOXSERVICECTRLSESSION g_Session;48 49 extern int VBoxServiceLogCreate(const char *pszLogFile);50 extern void VBoxServiceLogDestroy(void);51 52 53 /*********************************************************************************************************************************54 * Internal Functions *55 *********************************************************************************************************************************/56 static int gstcntlSessionFileDestroy(PVBOXSERVICECTRLFILE pFile);57 static int gstcntlSessionFileAdd(PVBOXSERVICECTRLSESSION pSession, PVBOXSERVICECTRLFILE pFile);58 static PVBOXSERVICECTRLFILE gstcntlSessionFileGetLocked(const PVBOXSERVICECTRLSESSION pSession, uint32_t uHandle);59 static DECLCALLBACK(int) gstcntlSessionThread(RTTHREAD ThreadSelf, void *pvUser);60 /* Host -> Guest handlers. */61 static int gstcntlSessionHandleDirRemove(PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx);62 static int gstcntlSessionHandleFileOpen(PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx);63 static int gstcntlSessionHandleFileClose(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx);64 static int gstcntlSessionHandleFileRead(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx);65 static int gstcntlSessionHandleFileWrite(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx, void *pvScratchBuf, size_t cbScratchBuf);66 static int gstcntlSessionHandleFileSeek(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx);67 static int gstcntlSessionHandleFileTell(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx);68 static int gstcntlSessionHandlePathRename(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx);69 static int gstcntlSessionHandleProcExec(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx);70 static int gstcntlSessionHandleProcInput(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx, void *pvScratchBuf, size_t cbScratchBuf);71 static int gstcntlSessionHandleProcOutput(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx);72 static int gstcntlSessionHandleProcTerminate(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx);73 static int gstcntlSessionHandleProcWaitFor(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx);74 75 76 46 /** Generic option indices for session spawn arguments. */ 77 47 enum … … 90 60 91 61 92 static int gstcntlSessionFileDestroy(PVBOXSERVICECTRLFILE pFile) 62 63 static int vgsvcGstCtrlSessionFileDestroy(PVBOXSERVICECTRLFILE pFile) 93 64 { 94 65 AssertPtrReturn(pFile, VERR_INVALID_POINTER); … … 108 79 109 80 /** @todo No locking done yet! */ 110 static PVBOXSERVICECTRLFILE gstcntlSessionFileGetLocked(const PVBOXSERVICECTRLSESSION pSession, 111 uint32_t uHandle) 81 static PVBOXSERVICECTRLFILE vgsvcGstCtrlSessionFileGetLocked(const PVBOXSERVICECTRLSESSION pSession, uint32_t uHandle) 112 82 { 113 83 AssertPtrReturn(pSession, NULL); 114 84 115 PVBOXSERVICECTRLFILE pFileCur = NULL;116 85 /** @todo Use a map later! */ 86 PVBOXSERVICECTRLFILE pFileCur; 117 87 RTListForEach(&pSession->lstFiles, pFileCur, VBOXSERVICECTRLFILE, Node) 118 88 { … … 125 95 126 96 127 static int gstcntlSessionHandleDirRemove(PVBOXSERVICECTRLSESSION pSession, 128 PVBGLR3GUESTCTRLCMDCTX pHostCtx) 97 static int vgsvcGstCtrlSessionHandleDirRemove(PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx) 129 98 { 130 99 AssertPtrReturn(pSession, VERR_INVALID_POINTER); … … 158 127 rc = VERR_NOT_SUPPORTED; 159 128 160 V BoxServiceVerbose(4, "[Dir %s]: Removing with fFlags=0x%x, rc=%Rrc\n", szDir, fFlags, rc);129 VGSvcVerbose(4, "[Dir %s]: Removing with fFlags=0x%x, rc=%Rrc\n", szDir, fFlags, rc); 161 130 162 131 /* Report back in any case. */ 163 132 int rc2 = VbglR3GuestCtrlMsgReply(pHostCtx, rc); 164 133 if (RT_FAILURE(rc2)) 165 V BoxServiceError("[Dir %s]: Failed to report removing status, rc=%Rrc\n", szDir, rc2);134 VGSvcError("[Dir %s]: Failed to report removing status, rc=%Rrc\n", szDir, rc2); 166 135 if (RT_SUCCESS(rc)) 167 136 rc = rc2; … … 169 138 170 139 #ifdef DEBUG 171 VBoxServiceVerbose(4, "Removing directory \"%s\" returned rc=%Rrc\n", szDir, rc); 172 #endif 173 return rc; 174 } 175 176 177 static int gstcntlSessionHandleFileOpen(PVBOXSERVICECTRLSESSION pSession, 178 PVBGLR3GUESTCTRLCMDCTX pHostCtx) 140 VGSvcVerbose(4, "Removing directory '%s' returned rc=%Rrc\n", szDir, rc); 141 #endif 142 return rc; 143 } 144 145 146 static int vgsvcGstCtrlSessionHandleFileOpen(PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx) 179 147 { 180 148 AssertPtrReturn(pSession, VERR_INVALID_POINTER); … … 186 154 char szSharing[64]; 187 155 uint32_t uCreationMode = 0; 188 uint64_t uOffset= 0;156 uint64_t offOpen = 0; 189 157 uint32_t uHandle = 0; 190 158 … … 201 169 &uCreationMode, 202 170 /* Offset. */ 203 &uOffset); 204 VBoxServiceVerbose(4, "[File %s]: szAccess=%s, szDisposition=%s, szSharing=%s, uOffset=%RU64, rc=%Rrc\n", 205 szFile, szAccess, szDisposition, szSharing, uOffset, rc); 206 171 &offOpen); 172 VGSvcVerbose(4, "[File %s]: szAccess=%s, szDisposition=%s, szSharing=%s, offOpen=%RU64, rc=%Rrc\n", 173 szFile, szAccess, szDisposition, szSharing, offOpen, rc); 207 174 if (RT_SUCCESS(rc)) 208 175 { … … 215 182 if (RT_SUCCESS(rc)) 216 183 { 184 /** @todo r=bird: Plase, use RTStrCopy for stuff like this! */ 217 185 RTStrPrintf(pFile->szName, sizeof(pFile->szName), "%s", szFile); 218 186 219 187 uint64_t fFlags; 220 rc = RTFileModeToFlagsEx(szAccess, szDisposition, 221 NULL /* pszSharing, not used yet */, &fFlags); 222 VBoxServiceVerbose(4, "[File %s]: Opening with fFlags=0x%x, rc=%Rrc\n", pFile->szName, fFlags, rc); 188 rc = RTFileModeToFlagsEx(szAccess, szDisposition, NULL /* pszSharing, not used yet */, &fFlags); 189 VGSvcVerbose(4, "[File %s]: Opening with fFlags=0x%x, rc=%Rrc\n", pFile->szName, fFlags, rc); 223 190 224 191 if (RT_SUCCESS(rc)) 225 192 rc = RTFileOpen(&pFile->hFile, pFile->szName, fFlags); 226 193 if ( RT_SUCCESS(rc) 227 && uOffset)194 && offOpen) 228 195 { 229 196 /* Seeking is optional. However, the whole operation 230 197 * will fail if we don't succeed seeking to the wanted position. */ 231 rc = RTFileSeek(pFile->hFile, (int64_t) uOffset, RTFILE_SEEK_BEGIN, NULL /* Current offset */);198 rc = RTFileSeek(pFile->hFile, (int64_t)offOpen, RTFILE_SEEK_BEGIN, NULL /* Current offset */); 232 199 if (RT_FAILURE(rc)) 233 VBoxServiceError("[File %s]: Seeking to offset %RU64 failed; rc=%Rrc\n", 234 pFile->szName, uOffset, rc); 200 VGSvcError("[File %s]: Seeking to offset %RU64 failed; rc=%Rrc\n", pFile->szName, offOpen, rc); 235 201 } 236 202 else if (RT_FAILURE(rc)) 237 V BoxServiceError("[File %s]: Opening failed with rc=%Rrc\n", pFile->szName, rc);203 VGSvcError("[File %s]: Opening failed with rc=%Rrc\n", pFile->szName, rc); 238 204 } 239 205 … … 243 209 pFile->uHandle = uHandle; 244 210 245 /* rc = */ RTListAppend(&pSession->lstFiles, &pFile->Node); 246 247 VBoxServiceVerbose(3, "[File %s]: Opened (ID=%RU32)\n", 248 pFile->szName, pFile->uHandle); 211 RTListAppend(&pSession->lstFiles, &pFile->Node); 212 213 VGSvcVerbose(3, "[File %s]: Opened (ID=%RU32)\n", pFile->szName, pFile->uHandle); 249 214 } 250 215 … … 262 227 int rc2 = VbglR3GuestCtrlFileCbOpen(pHostCtx, rc, uHandle); 263 228 if (RT_FAILURE(rc2)) 264 VBoxServiceError("[File %s]: Failed to report file open status, rc=%Rrc\n", 265 szFile, rc2); 229 VGSvcError("[File %s]: Failed to report file open status, rc=%Rrc\n", szFile, rc2); 266 230 if (RT_SUCCESS(rc)) 267 231 rc = rc2; … … 269 233 270 234 #ifdef DEBUG 271 VBoxServiceVerbose(4, "Opening file \"%s\" (open mode=\"%s\", disposition=\"%s\", creation mode=0x%x returned rc=%Rrc\n", 272 szFile, szAccess, szDisposition, uCreationMode, rc); 273 #endif 274 return rc; 275 } 276 277 278 static int gstcntlSessionHandleFileClose(const PVBOXSERVICECTRLSESSION pSession, 279 PVBGLR3GUESTCTRLCMDCTX pHostCtx) 235 VGSvcVerbose(4, "Opening file '%s' (open mode='%s', disposition='%s', creation mode=0x%x returned rc=%Rrc\n", 236 szFile, szAccess, szDisposition, uCreationMode, rc); 237 #endif 238 return rc; 239 } 240 241 242 static int vgsvcGstCtrlSessionHandleFileClose(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx) 280 243 { 281 244 AssertPtrReturn(pSession, VERR_INVALID_POINTER); … … 288 251 if (RT_SUCCESS(rc)) 289 252 { 290 pFile = gstcntlSessionFileGetLocked(pSession, uHandle);253 pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle); 291 254 if (pFile) 292 { 293 rc = gstcntlSessionFileDestroy(pFile); 294 } 255 rc = vgsvcGstCtrlSessionFileDestroy(pFile); 295 256 else 296 257 rc = VERR_NOT_FOUND; … … 299 260 int rc2 = VbglR3GuestCtrlFileCbClose(pHostCtx, rc); 300 261 if (RT_FAILURE(rc2)) 301 V BoxServiceError("Failed to report file close status, rc=%Rrc\n", rc2);262 VGSvcError("Failed to report file close status, rc=%Rrc\n", rc2); 302 263 if (RT_SUCCESS(rc)) 303 264 rc = rc2; … … 305 266 306 267 #ifdef DEBUG 307 VBoxServiceVerbose(4, "Closing file \"%s\" (handle=%RU32) returned rc=%Rrc\n", 308 pFile ? pFile->szName : "<Not found>", uHandle, rc); 309 #endif 310 return rc; 311 } 312 313 314 static int gstcntlSessionHandleFileRead(const PVBOXSERVICECTRLSESSION pSession, 315 PVBGLR3GUESTCTRLCMDCTX pHostCtx, 316 void *pvScratchBuf, size_t cbScratchBuf) 268 VGSvcVerbose(4, "Closing file '%s' (handle=%RU32) returned rc=%Rrc\n", pFile ? pFile->szName : "<Not found>", uHandle, rc); 269 #endif 270 return rc; 271 } 272 273 274 static int vgsvcGstCtrlSessionHandleFileRead(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx, 275 void *pvScratchBuf, size_t cbScratchBuf) 317 276 { 318 277 AssertPtrReturn(pSession, VERR_INVALID_POINTER); … … 329 288 size_t cbRead = 0; 330 289 331 pFile = gstcntlSessionFileGetLocked(pSession, uHandle);290 pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle); 332 291 if (pFile) 333 292 { … … 357 316 358 317 if (RT_FAILURE(rc2)) 359 V BoxServiceError("Failed to report file read status, rc=%Rrc\n", rc2);318 VGSvcError("Failed to report file read status, rc=%Rrc\n", rc2); 360 319 if (RT_SUCCESS(rc)) 361 320 rc = rc2; … … 363 322 364 323 #ifdef DEBUG 365 VBoxServiceVerbose(4, "Reading file \"%s\" (handle=%RU32) returned rc=%Rrc\n", 366 pFile ? pFile->szName : "<Not found>", uHandle, rc); 367 #endif 368 return rc; 369 } 370 371 372 static int gstcntlSessionHandleFileReadAt(const PVBOXSERVICECTRLSESSION pSession, 373 PVBGLR3GUESTCTRLCMDCTX pHostCtx, 374 void *pvScratchBuf, size_t cbScratchBuf) 324 VGSvcVerbose(4, "Reading file '%s' (handle=%RU32) returned rc=%Rrc\n", pFile ? pFile->szName : "<Not found>", uHandle, rc); 325 #endif 326 return rc; 327 } 328 329 330 static int vgsvcGstCtrlSessionHandleFileReadAt(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx, 331 void *pvScratchBuf, size_t cbScratchBuf) 375 332 { 376 333 AssertPtrReturn(pSession, VERR_INVALID_POINTER); … … 380 337 381 338 uint32_t uHandle = 0; 382 uint32_t cbToRead; int64_t iOffset; 383 384 int rc = VbglR3GuestCtrlFileGetReadAt(pHostCtx, 385 &uHandle, &cbToRead, (uint64_t *)&iOffset); 339 uint32_t cbToRead; 340 uint64_t offReadAt; 341 int rc = VbglR3GuestCtrlFileGetReadAt(pHostCtx, &uHandle, &cbToRead, &offReadAt); 386 342 if (RT_SUCCESS(rc)) 387 343 { … … 389 345 size_t cbRead = 0; 390 346 391 pFile = gstcntlSessionFileGetLocked(pSession, uHandle);347 pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle); 392 348 if (pFile) 393 349 { … … 401 357 } 402 358 403 if (RT_ LIKELY(RT_SUCCESS(rc)))404 rc = RTFileReadAt(pFile->hFile, iOffset, pvDataRead, cbToRead, &cbRead);359 if (RT_SUCCESS(rc)) 360 rc = RTFileReadAt(pFile->hFile, (RTFOFF)offReadAt, pvDataRead, cbToRead, &cbRead); 405 361 } 406 362 else … … 417 373 418 374 if (RT_FAILURE(rc2)) 419 V BoxServiceError("Failed to report file read status, rc=%Rrc\n", rc2);375 VGSvcError("Failed to report file read status, rc=%Rrc\n", rc2); 420 376 if (RT_SUCCESS(rc)) 421 377 rc = rc2; … … 423 379 424 380 #ifdef DEBUG 425 VBoxServiceVerbose(4, "Reading file \"%s\" at offset (handle=%RU32) returned rc=%Rrc\n", 426 pFile ? pFile->szName : "<Not found>", uHandle, rc); 427 #endif 428 return rc; 429 } 430 431 432 static int gstcntlSessionHandleFileWrite(const PVBOXSERVICECTRLSESSION pSession, 433 PVBGLR3GUESTCTRLCMDCTX pHostCtx, 434 void *pvScratchBuf, size_t cbScratchBuf) 381 VGSvcVerbose(4, "Reading file '%s' at offset (handle=%RU32) returned rc=%Rrc\n", 382 pFile ? pFile->szName : "<Not found>", uHandle, rc); 383 #endif 384 return rc; 385 } 386 387 388 static int vgsvcGstCtrlSessionHandleFileWrite(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx, 389 void *pvScratchBuf, size_t cbScratchBuf) 435 390 { 436 391 AssertPtrReturn(pSession, VERR_INVALID_POINTER); … … 443 398 uint32_t uHandle = 0; 444 399 uint32_t cbToWrite; 445 446 int rc = VbglR3GuestCtrlFileGetWrite(pHostCtx, &uHandle, 447 pvScratchBuf, (uint32_t)cbScratchBuf, &cbToWrite); 400 int rc = VbglR3GuestCtrlFileGetWrite(pHostCtx, &uHandle, pvScratchBuf, (uint32_t)cbScratchBuf, &cbToWrite); 448 401 if (RT_SUCCESS(rc)) 449 402 { 450 403 size_t cbWritten = 0; 451 pFile = gstcntlSessionFileGetLocked(pSession, uHandle);404 pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle); 452 405 if (pFile) 453 406 { 454 407 rc = RTFileWrite(pFile->hFile, pvScratchBuf, cbToWrite, &cbWritten); 455 408 #ifdef DEBUG 456 V BoxServiceVerbose(4, "[File %s]: Writing pvScratchBuf=%p, cbToWrite=%RU32, cbWritten=%zu, rc=%Rrc\n",457 409 VGSvcVerbose(4, "[File %s]: Writing pvScratchBuf=%p, cbToWrite=%RU32, cbWritten=%zu, rc=%Rrc\n", 410 pFile->szName, pvScratchBuf, cbToWrite, cbWritten, rc); 458 411 #endif 459 412 } … … 464 417 int rc2 = VbglR3GuestCtrlFileCbWrite(pHostCtx, rc, (uint32_t)cbWritten); 465 418 if (RT_FAILURE(rc2)) 466 V BoxServiceError("Failed to report file write status, rc=%Rrc\n", rc2);419 VGSvcError("Failed to report file write status, rc=%Rrc\n", rc2); 467 420 if (RT_SUCCESS(rc)) 468 421 rc = rc2; … … 470 423 471 424 #ifdef DEBUG 472 VBoxServiceVerbose(4, "Writing file \"%s\" (handle=%RU32) returned rc=%Rrc\n", 473 pFile ? pFile->szName : "<Not found>", uHandle, rc); 474 #endif 475 return rc; 476 } 477 478 479 static int gstcntlSessionHandleFileWriteAt(const PVBOXSERVICECTRLSESSION pSession, 480 PVBGLR3GUESTCTRLCMDCTX pHostCtx, 481 void *pvScratchBuf, size_t cbScratchBuf) 425 VGSvcVerbose(4, "Writing file '%s' (handle=%RU32) returned rc=%Rrc\n", pFile ? pFile->szName : "<Not found>", uHandle, rc); 426 #endif 427 return rc; 428 } 429 430 431 static int vgsvcGstCtrlSessionHandleFileWriteAt(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx, 432 void *pvScratchBuf, size_t cbScratchBuf) 482 433 { 483 434 AssertPtrReturn(pSession, VERR_INVALID_POINTER); … … 489 440 490 441 uint32_t uHandle = 0; 491 uint32_t cbToWrite; int64_t iOffset; 492 493 int rc = VbglR3GuestCtrlFileGetWriteAt(pHostCtx, &uHandle, 494 pvScratchBuf, (uint32_t)cbScratchBuf, 495 &cbToWrite, (uint64_t *)&iOffset); 442 uint32_t cbToWrite; 443 uint64_t offWriteAt; 444 445 int rc = VbglR3GuestCtrlFileGetWriteAt(pHostCtx, &uHandle, pvScratchBuf, (uint32_t)cbScratchBuf, &cbToWrite, &offWriteAt); 496 446 if (RT_SUCCESS(rc)) 497 447 { 498 448 size_t cbWritten = 0; 499 pFile = gstcntlSessionFileGetLocked(pSession, uHandle);449 pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle); 500 450 if (pFile) 501 451 { 502 rc = RTFileWriteAt(pFile->hFile, iOffset, 503 pvScratchBuf, cbToWrite, &cbWritten); 504 #ifdef DEBUG 505 VBoxServiceVerbose(4, "[File %s]: Writing iOffset=%RI64, pvScratchBuf=%p, cbToWrite=%RU32, cbWritten=%zu, rc=%Rrc\n", 506 pFile->szName, iOffset, pvScratchBuf, cbToWrite, cbWritten, rc); 452 rc = RTFileWriteAt(pFile->hFile, (RTFOFF)offWriteAt, pvScratchBuf, cbToWrite, &cbWritten); 453 #ifdef DEBUG 454 VGSvcVerbose(4, "[File %s]: Writing offWriteAt=%RI64, pvScratchBuf=%p, cbToWrite=%RU32, cbWritten=%zu, rc=%Rrc\n", 455 pFile->szName, offWriteAt, pvScratchBuf, cbToWrite, cbWritten, rc); 507 456 #endif 508 457 } … … 513 462 int rc2 = VbglR3GuestCtrlFileCbWrite(pHostCtx, rc, (uint32_t)cbWritten); 514 463 if (RT_FAILURE(rc2)) 515 V BoxServiceError("Failed to report file write status, rc=%Rrc\n", rc2);464 VGSvcError("Failed to report file write status, rc=%Rrc\n", rc2); 516 465 if (RT_SUCCESS(rc)) 517 466 rc = rc2; … … 519 468 520 469 #ifdef DEBUG 521 VBoxServiceVerbose(4, "Writing file \"%s\" at offset (handle=%RU32) returned rc=%Rrc\n", 522 pFile ? pFile->szName : "<Not found>", uHandle, rc); 523 #endif 524 return rc; 525 } 526 527 528 static int gstcntlSessionHandleFileSeek(const PVBOXSERVICECTRLSESSION pSession, 529 PVBGLR3GUESTCTRLCMDCTX pHostCtx) 470 VGSvcVerbose(4, "Writing file '%s' at offset (handle=%RU32) returned rc=%Rrc\n", 471 pFile ? pFile->szName : "<Not found>", uHandle, rc); 472 #endif 473 return rc; 474 } 475 476 477 static int vgsvcGstCtrlSessionHandleFileSeek(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx) 530 478 { 531 479 AssertPtrReturn(pSession, VERR_INVALID_POINTER); … … 536 484 uint32_t uHandle = 0; 537 485 uint32_t uSeekMethod; 538 uint64_t uOffset; /* Will be converted to int64_t. */ 539 540 uint64_t uOffsetActual = 0; 541 542 int rc = VbglR3GuestCtrlFileGetSeek(pHostCtx, &uHandle, 543 &uSeekMethod, &uOffset); 544 if (RT_SUCCESS(rc)) 545 { 546 pFile = gstcntlSessionFileGetLocked(pSession, uHandle); 486 uint64_t offSeek; /* Will be converted to int64_t. */ 487 int rc = VbglR3GuestCtrlFileGetSeek(pHostCtx, &uHandle, &uSeekMethod, &offSeek); 488 if (RT_SUCCESS(rc)) 489 { 490 uint64_t offActual = 0; 491 pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle); 547 492 if (pFile) 548 493 { 549 unsigned uSeekMethodI PRT;494 unsigned uSeekMethodIprt; 550 495 switch (uSeekMethod) 551 496 { 552 497 case GUEST_FILE_SEEKTYPE_BEGIN: 553 uSeekMethodI PRT= RTFILE_SEEK_BEGIN;498 uSeekMethodIprt = RTFILE_SEEK_BEGIN; 554 499 break; 555 500 556 501 case GUEST_FILE_SEEKTYPE_CURRENT: 557 uSeekMethodI PRT= RTFILE_SEEK_CURRENT;502 uSeekMethodIprt = RTFILE_SEEK_CURRENT; 558 503 break; 559 504 560 505 case GUEST_FILE_SEEKTYPE_END: 561 uSeekMethodI PRT= RTFILE_SEEK_END;506 uSeekMethodIprt = RTFILE_SEEK_END; 562 507 break; 563 508 … … 569 514 if (RT_SUCCESS(rc)) 570 515 { 571 rc = RTFileSeek(pFile->hFile, (int64_t)uOffset, 572 uSeekMethodIPRT, &uOffsetActual); 573 #ifdef DEBUG 574 VBoxServiceVerbose(4, "[File %s]: Seeking to iOffset=%RI64, uSeekMethodIPRT=%RU16, rc=%Rrc\n", 575 pFile->szName, (int64_t)uOffset, uSeekMethodIPRT, rc); 516 rc = RTFileSeek(pFile->hFile, (int64_t)offSeek, uSeekMethodIprt, &offActual); 517 #ifdef DEBUG 518 VGSvcVerbose(4, "[File %s]: Seeking to offSeek=%RI64, uSeekMethodIPRT=%RU16, rc=%Rrc\n", 519 pFile->szName, offSeek, uSeekMethodIprt, rc); 576 520 #endif 577 521 } … … 581 525 582 526 /* Report back in any case. */ 583 int rc2 = VbglR3GuestCtrlFileCbSeek(pHostCtx, rc, uOffsetActual);527 int rc2 = VbglR3GuestCtrlFileCbSeek(pHostCtx, rc, offActual); 584 528 if (RT_FAILURE(rc2)) 585 V BoxServiceError("Failed to report file seek status, rc=%Rrc\n", rc2);529 VGSvcError("Failed to report file seek status, rc=%Rrc\n", rc2); 586 530 if (RT_SUCCESS(rc)) 587 531 rc = rc2; … … 589 533 590 534 #ifdef DEBUG 591 VBoxServiceVerbose(4, "Seeking file \"%s\" (handle=%RU32) returned rc=%Rrc\n", 592 pFile ? pFile->szName : "<Not found>", uHandle, rc); 593 #endif 594 return rc; 595 } 596 597 598 static int gstcntlSessionHandleFileTell(const PVBOXSERVICECTRLSESSION pSession, 599 PVBGLR3GUESTCTRLCMDCTX pHostCtx) 535 VGSvcVerbose(4, "Seeking file '%s' (handle=%RU32) returned rc=%Rrc\n", pFile ? pFile->szName : "<Not found>", uHandle, rc); 536 #endif 537 return rc; 538 } 539 540 541 static int vgsvcGstCtrlSessionHandleFileTell(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx) 600 542 { 601 543 AssertPtrReturn(pSession, VERR_INVALID_POINTER); … … 605 547 606 548 uint32_t uHandle = 0; 607 uint64_t uOffsetActual = 0;608 609 549 int rc = VbglR3GuestCtrlFileGetTell(pHostCtx, &uHandle); 610 550 if (RT_SUCCESS(rc)) 611 551 { 612 pFile = gstcntlSessionFileGetLocked(pSession, uHandle); 552 uint64_t off = 0; 553 pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle); 613 554 if (pFile) 614 555 { 615 uOffsetActual = RTFileTell(pFile->hFile); 616 #ifdef DEBUG 617 VBoxServiceVerbose(4, "[File %s]: Telling uOffsetActual=%RU64\n", 618 pFile->szName, uOffsetActual); 556 off = RTFileTell(pFile->hFile); 557 #ifdef DEBUG 558 VGSvcVerbose(4, "[File %s]: Telling off=%RU64\n", pFile->szName, off); 619 559 #endif 620 560 } … … 623 563 624 564 /* Report back in any case. */ 625 int rc2 = VbglR3GuestCtrlFileCbTell(pHostCtx, rc, uOffsetActual);565 int rc2 = VbglR3GuestCtrlFileCbTell(pHostCtx, rc, off); 626 566 if (RT_FAILURE(rc2)) 627 V BoxServiceError("Failed to report file tell status, rc=%Rrc\n", rc2);567 VGSvcError("Failed to report file tell status, rc=%Rrc\n", rc2); 628 568 if (RT_SUCCESS(rc)) 629 569 rc = rc2; … … 631 571 632 572 #ifdef DEBUG 633 VBoxServiceVerbose(4, "Telling file \"%s\" (handle=%RU32) returned rc=%Rrc\n", 634 pFile ? pFile->szName : "<Not found>", uHandle, rc); 635 #endif 636 return rc; 637 } 638 639 640 static int gstcntlSessionHandlePathRename(PVBOXSERVICECTRLSESSION pSession, 641 PVBGLR3GUESTCTRLCMDCTX pHostCtx) 573 VGSvcVerbose(4, "Telling file '%s' (handle=%RU32) returned rc=%Rrc\n", pFile ? pFile->szName : "<Not found>", uHandle, rc); 574 #endif 575 return rc; 576 } 577 578 579 static int vgsvcGstCtrlSessionHandlePathRename(PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx) 642 580 { 643 581 AssertPtrReturn(pSession, VERR_INVALID_POINTER); … … 646 584 char szSource[RTPATH_MAX]; 647 585 char szDest[RTPATH_MAX]; 648 uint32_t uFlags = 0;586 uint32_t fFlags = 0; 649 587 650 588 int rc = VbglR3GuestCtrlPathGetRename(pHostCtx, … … 652 590 szDest, sizeof(szDest), 653 591 /* Flags of type PATHRENAME_FLAG_. */ 654 & uFlags);655 if (RT_SUCCESS(rc)) 656 { 657 if ( uFlags & ~PATHRENAME_FLAG_VALID_MASK)592 &fFlags); 593 if (RT_SUCCESS(rc)) 594 { 595 if (fFlags & ~PATHRENAME_FLAG_VALID_MASK) 658 596 rc = VERR_NOT_SUPPORTED; 659 597 660 V BoxServiceVerbose(4, "Renaming \"%s\" to \"%s\", uFlags=0x%x, rc=%Rrc\n",661 szSource, szDest, uFlags, rc); 662 663 if (RT_SUCCESS(rc))664 { 665 if ( uFlags & PATHRENAME_FLAG_NO_REPLACE)666 uFlags |= RTPATHRENAME_FLAGS_NO_REPLACE;667 668 if ( uFlags & PATHRENAME_FLAG_REPLACE)669 uFlags |= RTPATHRENAME_FLAGS_REPLACE;670 671 if ( uFlags & PATHRENAME_FLAG_NO_SYMLINKS)672 uFlags |= RTPATHRENAME_FLAGS_NO_SYMLINKS;673 674 rc = RTPathRename(szSource, szDest, uFlags);598 VGSvcVerbose(4, "Renaming '%s' to '%s', fFlags=0x%x, rc=%Rrc\n", szSource, szDest, fFlags, rc); 599 600 if (RT_SUCCESS(rc)) 601 { 602 /** @todo r=bird: shouldn't you use a different variable here for the IPRT flags??? */ 603 if (fFlags & PATHRENAME_FLAG_NO_REPLACE) 604 fFlags |= RTPATHRENAME_FLAGS_NO_REPLACE; 605 606 if (fFlags & PATHRENAME_FLAG_REPLACE) 607 fFlags |= RTPATHRENAME_FLAGS_REPLACE; 608 609 if (fFlags & PATHRENAME_FLAG_NO_SYMLINKS) 610 fFlags |= RTPATHRENAME_FLAGS_NO_SYMLINKS; 611 612 rc = RTPathRename(szSource, szDest, fFlags); 675 613 } 676 614 … … 678 616 int rc2 = VbglR3GuestCtrlMsgReply(pHostCtx, rc); 679 617 if (RT_FAILURE(rc2)) 680 V BoxServiceError("Failed to report renaming status, rc=%Rrc\n", rc2);618 VGSvcError("Failed to report renaming status, rc=%Rrc\n", rc2); 681 619 if (RT_SUCCESS(rc)) 682 620 rc = rc2; … … 684 622 685 623 #ifdef DEBUG 686 VBoxServiceVerbose(4, "Renaming \"%s\" to \"%s\" returned rc=%Rrc\n", 687 szSource, szDest, rc); 624 VGSvcVerbose(4, "Renaming '%s' to '%s' returned rc=%Rrc\n", szSource, szDest, rc); 688 625 #endif 689 626 return rc; … … 694 631 * Handles starting a guest processes. 695 632 * 696 * @returns IPRTstatus code.633 * @returns VBox status code. 697 634 * @param pSession Guest session. 698 635 * @param pHostCtx Host context. 699 636 */ 700 int gstcntlSessionHandleProcExec(PVBOXSERVICECTRLSESSION pSession, 701 PVBGLR3GUESTCTRLCMDCTX pHostCtx) 637 static int vgsvcGstCtrlSessionHandleProcExec(PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx) 702 638 { 703 639 AssertPtrReturn(pSession, VERR_INVALID_POINTER); … … 756 692 if (RT_SUCCESS(rc)) 757 693 { 758 V BoxServiceVerbose(3, "Request to start process szCmd=%s, uFlags=0x%x, szArgs=%s, szEnv=%s, uTimeout=%RU32\n",759 760 761 762 763 764 rc = GstCntlSessionProcessStartAllowed(pSession, &fStartAllowed);694 VGSvcVerbose(3, "Request to start process szCmd=%s, fFlags=0x%x, szArgs=%s, szEnv=%s, uTimeout=%RU32\n", 695 startupInfo.szCmd, startupInfo.uFlags, 696 startupInfo.uNumArgs ? startupInfo.szArgs : "<None>", 697 startupInfo.uNumEnvVars ? startupInfo.szEnv : "<None>", 698 startupInfo.uTimeLimitMS); 699 700 rc = VGSvcGstCtrlSessionProcessStartAllowed(pSession, &fStartAllowed); 765 701 if (RT_SUCCESS(rc)) 766 702 { 767 703 if (fStartAllowed) 768 { 769 rc = GstCntlProcessStart(pSession, &startupInfo, pHostCtx->uContextID); 770 } 704 rc = VGSvcGstCtrlProcessStart(pSession, &startupInfo, pHostCtx->uContextID); 771 705 else 772 706 rc = VERR_MAX_PROCS_REACHED; /* Maximum number of processes reached. */ … … 778 712 if (RT_FAILURE(rc)) 779 713 { 780 V BoxServiceError("Starting process failed with rc=%Rrc, protocol=%RU32, parameters=%RU32\n",781 714 VGSvcError("Starting process failed with rc=%Rrc, protocol=%RU32, parameters=%RU32\n", 715 rc, pHostCtx->uProtocol, pHostCtx->uNumParms); 782 716 783 717 /* Don't report back if we didn't supply sufficient buffer for getting … … 793 727 NULL /* pvData */, 0 /* cbData */); 794 728 if (RT_FAILURE(rc2)) 795 V BoxServiceError("Error sending start process status to host, rc=%Rrc\n", rc2);729 VGSvcError("Error sending start process status to host, rc=%Rrc\n", rc2); 796 730 } 797 731 } … … 804 738 * Sends stdin input to a specific guest process. 805 739 * 806 * @returns IPRT status code. 807 * @param pSession The session which is in charge. 808 * @param pHostCtx The host context to use. 809 * @param pvScratchBuf The scratch buffer. 810 * @param cbScratchBuf The scratch buffer size for retrieving the input data. 740 * @returns VBox status code. 741 * @param pSession The session which is in charge. 742 * @param pHostCtx The host context to use. 743 * @param pvScratchBuf The scratch buffer. 744 * @param cbScratchBuf The scratch buffer size for retrieving the input 745 * data. 811 746 */ 812 int gstcntlSessionHandleProcInput(PVBOXSERVICECTRLSESSION pSession, 813 PVBGLR3GUESTCTRLCMDCTX pHostCtx, 814 void *pvScratchBuf, size_t cbScratchBuf) 747 static int vgsvcGstCtrlSessionHandleProcInput(PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx, 748 void *pvScratchBuf, size_t cbScratchBuf) 815 749 { 816 750 AssertPtrReturn(pSession, VERR_INVALID_POINTER); … … 820 754 821 755 uint32_t uPID; 822 uint32_t uFlags;756 uint32_t fFlags; 823 757 uint32_t cbSize; 824 758 … … 829 763 * Ask the host for the input data. 830 764 */ 831 int rc = VbglR3GuestCtrlProcGetInput(pHostCtx, &uPID, & uFlags,765 int rc = VbglR3GuestCtrlProcGetInput(pHostCtx, &uPID, &fFlags, 832 766 pvScratchBuf, (uint32_t)cbScratchBuf, &cbSize); 833 767 if (RT_FAILURE(rc)) 834 { 835 VBoxServiceError("Failed to retrieve process input command for PID=%RU32, rc=%Rrc\n", 836 uPID, rc); 837 } 768 VGSvcError("Failed to retrieve process input command for PID=%RU32, rc=%Rrc\n", uPID, rc); 838 769 else if (cbSize > cbScratchBuf) 839 770 { 840 V BoxServiceError("Too much process input received, rejecting: uPID=%RU32, cbSize=%RU32, cbScratchBuf=%RU32\n",841 771 VGSvcError("Too much process input received, rejecting: uPID=%RU32, cbSize=%RU32, cbScratchBuf=%RU32\n", 772 uPID, cbSize, cbScratchBuf); 842 773 rc = VERR_TOO_MUCH_DATA; 843 774 } … … 848 779 */ 849 780 bool fPendingClose = false; 850 if ( uFlags & INPUT_FLAG_EOF)781 if (fFlags & INPUT_FLAG_EOF) 851 782 { 852 783 fPendingClose = true; 853 784 #ifdef DEBUG 854 VBoxServiceVerbose(4, "Got last process input block for PID=%RU32 (%RU32 bytes) ...\n", 855 uPID, cbSize); 856 #endif 857 } 858 859 PVBOXSERVICECTRLPROCESS pProcess = GstCntlSessionRetainProcess(pSession, uPID); 785 VGSvcVerbose(4, "Got last process input block for PID=%RU32 (%RU32 bytes) ...\n", uPID, cbSize); 786 #endif 787 } 788 789 PVBOXSERVICECTRLPROCESS pProcess = VGSvcGstCtrlSessionRetainProcess(pSession, uPID); 860 790 if (pProcess) 861 791 { 862 rc = GstCntlProcessHandleInput(pProcess, pHostCtx, fPendingClose, 863 pvScratchBuf, cbSize); 792 rc = VGSvcGstCtrlProcessHandleInput(pProcess, pHostCtx, fPendingClose, pvScratchBuf, cbSize); 864 793 if (RT_FAILURE(rc)) 865 VBoxServiceError("Error handling input command for PID=%RU32, rc=%Rrc\n", 866 uPID, rc); 867 GstCntlProcessRelease(pProcess); 794 VGSvcError("Error handling input command for PID=%RU32, rc=%Rrc\n", uPID, rc); 795 VGSvcGstCtrlProcessRelease(pProcess); 868 796 } 869 797 else … … 872 800 873 801 #ifdef DEBUG 874 VBoxServiceVerbose(4, "Setting input for PID=%RU32 resulted in rc=%Rrc\n", 875 uPID, rc); 802 VGSvcVerbose(4, "Setting input for PID=%RU32 resulted in rc=%Rrc\n", uPID, rc); 876 803 #endif 877 804 return rc; … … 882 809 * Gets stdout/stderr output of a specific guest process. 883 810 * 884 * @return IPRTstatus code.885 * @param pSession The session which is in charge.886 * @param pHostCtx The host context to use.811 * @returns VBox status code. 812 * @param pSession The session which is in charge. 813 * @param pHostCtx The host context to use. 887 814 */ 888 int gstcntlSessionHandleProcOutput(PVBOXSERVICECTRLSESSION pSession, 889 PVBGLR3GUESTCTRLCMDCTX pHostCtx) 815 static int vgsvcGstCtrlSessionHandleProcOutput(PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx) 890 816 { 891 817 AssertPtrReturn(pSession, VERR_INVALID_POINTER); … … 894 820 uint32_t uPID; 895 821 uint32_t uHandleID; 896 uint32_t uFlags;897 898 int rc = VbglR3GuestCtrlProcGetOutput(pHostCtx, &uPID, &uHandleID, & uFlags);822 uint32_t fFlags; 823 824 int rc = VbglR3GuestCtrlProcGetOutput(pHostCtx, &uPID, &uHandleID, &fFlags); 899 825 #ifdef DEBUG_andy 900 V BoxServiceVerbose(4, "Getting output for PID=%RU32, CID=%RU32, uHandleID=%RU32, uFlags=%RU32\n",901 uPID, pHostCtx->uContextID, uHandleID, uFlags);902 #endif 903 if (RT_SUCCESS(rc)) 904 { 905 PVBOXSERVICECTRLPROCESS pProcess = GstCntlSessionRetainProcess(pSession, uPID);826 VGSvcVerbose(4, "Getting output for PID=%RU32, CID=%RU32, uHandleID=%RU32, fFlags=%RU32\n", 827 uPID, pHostCtx->uContextID, uHandleID, fFlags); 828 #endif 829 if (RT_SUCCESS(rc)) 830 { 831 PVBOXSERVICECTRLPROCESS pProcess = VGSvcGstCtrlSessionRetainProcess(pSession, uPID); 906 832 if (pProcess) 907 833 { 908 rc = GstCntlProcessHandleOutput(pProcess, pHostCtx, 909 uHandleID, _64K /* cbToRead */, uFlags); 834 rc = VGSvcGstCtrlProcessHandleOutput(pProcess, pHostCtx, uHandleID, _64K /* cbToRead */, fFlags); 910 835 if (RT_FAILURE(rc)) 911 VBoxServiceError("Error getting output for PID=%RU32, rc=%Rrc\n", 912 uPID, rc); 913 GstCntlProcessRelease(pProcess); 836 VGSvcError("Error getting output for PID=%RU32, rc=%Rrc\n", uPID, rc); 837 VGSvcGstCtrlProcessRelease(pProcess); 914 838 } 915 839 else … … 918 842 919 843 #ifdef DEBUG_andy 920 VBoxServiceVerbose(4, "Getting output for PID=%RU32 resulted in rc=%Rrc\n", 921 uPID, rc); 844 VGSvcVerbose(4, "Getting output for PID=%RU32 resulted in rc=%Rrc\n", uPID, rc); 922 845 #endif 923 846 return rc; … … 928 851 * Tells a guest process to terminate. 929 852 * 930 * @return IPRTstatus code.931 * @param pSession The session which is in charge.932 * @param pHostCtx The host context to use.853 * @returns VBox status code. 854 * @param pSession The session which is in charge. 855 * @param pHostCtx The host context to use. 933 856 */ 934 int gstcntlSessionHandleProcTerminate(const PVBOXSERVICECTRLSESSION pSession, 935 PVBGLR3GUESTCTRLCMDCTX pHostCtx) 857 static int vgsvcGstCtrlSessionHandleProcTerminate(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx) 936 858 { 937 859 AssertPtrReturn(pSession, VERR_INVALID_POINTER); … … 942 864 if (RT_SUCCESS(rc)) 943 865 { 944 PVBOXSERVICECTRLPROCESS pProcess = GstCntlSessionRetainProcess(pSession, uPID);866 PVBOXSERVICECTRLPROCESS pProcess = VGSvcGstCtrlSessionRetainProcess(pSession, uPID); 945 867 if (pProcess) 946 868 { 947 rc = GstCntlProcessHandleTerm(pProcess);948 949 GstCntlProcessRelease(pProcess);869 rc = VGSvcGstCtrlProcessHandleTerm(pProcess); 870 871 VGSvcGstCtrlProcessRelease(pProcess); 950 872 } 951 873 else … … 954 876 955 877 #ifdef DEBUG_andy 956 VBoxServiceVerbose(4, "Terminating PID=%RU32 resulted in rc=%Rrc\n", 957 uPID, rc); 958 #endif 959 return rc; 960 } 961 962 963 int gstcntlSessionHandleProcWaitFor(const PVBOXSERVICECTRLSESSION pSession, 964 PVBGLR3GUESTCTRLCMDCTX pHostCtx) 878 VGSvcVerbose(4, "Terminating PID=%RU32 resulted in rc=%Rrc\n", uPID, rc); 879 #endif 880 return rc; 881 } 882 883 884 static int vgsvcGstCtrlSessionHandleProcWaitFor(const PVBOXSERVICECTRLSESSION pSession, PVBGLR3GUESTCTRLCMDCTX pHostCtx) 965 885 { 966 886 AssertPtrReturn(pSession, VERR_INVALID_POINTER); … … 973 893 if (RT_SUCCESS(rc)) 974 894 { 975 PVBOXSERVICECTRLPROCESS pProcess = GstCntlSessionRetainProcess(pSession, uPID);895 PVBOXSERVICECTRLPROCESS pProcess = VGSvcGstCtrlSessionRetainProcess(pSession, uPID); 976 896 if (pProcess) 977 897 { 978 898 rc = VERR_NOT_IMPLEMENTED; /** @todo */ 979 GstCntlProcessRelease(pProcess);899 VGSvcGstCtrlProcessRelease(pProcess); 980 900 } 981 901 else … … 987 907 988 908 989 int GstCntlSessionHandler(PVBOXSERVICECTRLSESSION pSession, 990 uint32_t uMsg, PVBGLR3GUESTCTRLCMDCTX pHostCtx, 991 void *pvScratchBuf, size_t cbScratchBuf, 992 volatile bool *pfShutdown) 909 int VGSvcGstCtrlSessionHandler(PVBOXSERVICECTRLSESSION pSession, uint32_t uMsg, PVBGLR3GUESTCTRLCMDCTX pHostCtx, 910 void *pvScratchBuf, size_t cbScratchBuf, volatile bool *pfShutdown) 993 911 { 994 912 AssertPtrReturn(pSession, VERR_INVALID_POINTER); … … 997 915 AssertPtrReturn(pfShutdown, VERR_INVALID_POINTER); 998 916 999 int rc = VINF_SUCCESS; 1000 /* *917 918 /* 1001 919 * Only anonymous sessions (that is, sessions which run with local 1002 920 * service privileges) or spawned session processes can do certain 1003 921 * operations. 1004 922 */ 1005 bool fImpersonated = ( pSession->fFlags &VBOXSERVICECTRLSESSION_FLAG_SPAWN1006 || pSession->fFlags & VBOXSERVICECTRLSESSION_FLAG_ANONYMOUS);1007 923 bool const fImpersonated = RT_BOOL(pSession->fFlags & ( VBOXSERVICECTRLSESSION_FLAG_SPAWN 924 | VBOXSERVICECTRLSESSION_FLAG_ANONYMOUS)); 925 int rc; 1008 926 switch (uMsg) 1009 927 { 1010 928 case HOST_SESSION_CLOSE: 1011 929 /* Shutdown (this spawn). */ 1012 rc = GstCntlSessionClose(pSession);930 rc = VGSvcGstCtrlSessionClose(pSession); 1013 931 *pfShutdown = true; /* Shutdown in any case. */ 1014 932 break; 1015 933 1016 934 case HOST_DIR_REMOVE: 1017 rc = fImpersonated 1018 ? gstcntlSessionHandleDirRemove(pSession, pHostCtx) 1019 : VERR_NOT_SUPPORTED; 935 if (fImpersonated) 936 rc = vgsvcGstCtrlSessionHandleDirRemove(pSession, pHostCtx); 937 else 938 rc = VERR_NOT_SUPPORTED; 1020 939 break; 1021 940 1022 941 case HOST_EXEC_CMD: 1023 rc = gstcntlSessionHandleProcExec(pSession, pHostCtx);942 rc = vgsvcGstCtrlSessionHandleProcExec(pSession, pHostCtx); 1024 943 break; 1025 944 1026 945 case HOST_EXEC_SET_INPUT: 1027 rc = gstcntlSessionHandleProcInput(pSession, pHostCtx, 1028 pvScratchBuf, cbScratchBuf); 946 rc = vgsvcGstCtrlSessionHandleProcInput(pSession, pHostCtx, pvScratchBuf, cbScratchBuf); 1029 947 break; 1030 948 1031 949 case HOST_EXEC_GET_OUTPUT: 1032 rc = gstcntlSessionHandleProcOutput(pSession, pHostCtx);950 rc = vgsvcGstCtrlSessionHandleProcOutput(pSession, pHostCtx); 1033 951 break; 1034 952 1035 953 case HOST_EXEC_TERMINATE: 1036 rc = gstcntlSessionHandleProcTerminate(pSession, pHostCtx);954 rc = vgsvcGstCtrlSessionHandleProcTerminate(pSession, pHostCtx); 1037 955 break; 1038 956 1039 957 case HOST_EXEC_WAIT_FOR: 1040 rc = gstcntlSessionHandleProcWaitFor(pSession, pHostCtx);958 rc = vgsvcGstCtrlSessionHandleProcWaitFor(pSession, pHostCtx); 1041 959 break; 1042 960 1043 961 case HOST_FILE_OPEN: 1044 rc = fImpersonated 1045 ? gstcntlSessionHandleFileOpen(pSession, pHostCtx) 1046 : VERR_NOT_SUPPORTED; 962 if (fImpersonated) 963 rc = vgsvcGstCtrlSessionHandleFileOpen(pSession, pHostCtx); 964 else 965 rc = VERR_NOT_SUPPORTED; 1047 966 break; 1048 967 1049 968 case HOST_FILE_CLOSE: 1050 rc = fImpersonated 1051 ? gstcntlSessionHandleFileClose(pSession, pHostCtx) 1052 : VERR_NOT_SUPPORTED; 969 if (fImpersonated) 970 rc = vgsvcGstCtrlSessionHandleFileClose(pSession, pHostCtx); 971 else 972 rc = VERR_NOT_SUPPORTED; 1053 973 break; 1054 974 1055 975 case HOST_FILE_READ: 1056 rc = fImpersonated1057 ? gstcntlSessionHandleFileRead(pSession, pHostCtx,1058 pvScratchBuf, cbScratchBuf)1059 :VERR_NOT_SUPPORTED;976 if (fImpersonated) 977 rc = vgsvcGstCtrlSessionHandleFileRead(pSession, pHostCtx, pvScratchBuf, cbScratchBuf); 978 else 979 rc = VERR_NOT_SUPPORTED; 1060 980 break; 1061 981 1062 982 case HOST_FILE_READ_AT: 1063 rc = fImpersonated1064 ? gstcntlSessionHandleFileReadAt(pSession, pHostCtx,1065 pvScratchBuf, cbScratchBuf)1066 :VERR_NOT_SUPPORTED;983 if (fImpersonated) 984 rc = vgsvcGstCtrlSessionHandleFileReadAt(pSession, pHostCtx, pvScratchBuf, cbScratchBuf); 985 else 986 rc = VERR_NOT_SUPPORTED; 1067 987 break; 1068 988 1069 989 case HOST_FILE_WRITE: 1070 rc = fImpersonated1071 ? gstcntlSessionHandleFileWrite(pSession, pHostCtx,1072 pvScratchBuf, cbScratchBuf)1073 :VERR_NOT_SUPPORTED;990 if (fImpersonated) 991 rc = vgsvcGstCtrlSessionHandleFileWrite(pSession, pHostCtx, pvScratchBuf, cbScratchBuf); 992 else 993 rc = VERR_NOT_SUPPORTED; 1074 994 break; 1075 995 1076 996 case HOST_FILE_WRITE_AT: 1077 rc = fImpersonated1078 ? gstcntlSessionHandleFileWriteAt(pSession, pHostCtx,1079 pvScratchBuf, cbScratchBuf)1080 :VERR_NOT_SUPPORTED;997 if (fImpersonated) 998 rc = vgsvcGstCtrlSessionHandleFileWriteAt(pSession, pHostCtx, pvScratchBuf, cbScratchBuf); 999 else 1000 rc = VERR_NOT_SUPPORTED; 1081 1001 break; 1082 1002 1083 1003 case HOST_FILE_SEEK: 1084 rc = fImpersonated 1085 ? gstcntlSessionHandleFileSeek(pSession, pHostCtx) 1086 : VERR_NOT_SUPPORTED; 1004 if (fImpersonated) 1005 rc = vgsvcGstCtrlSessionHandleFileSeek(pSession, pHostCtx); 1006 else 1007 rc = VERR_NOT_SUPPORTED; 1087 1008 break; 1088 1009 1089 1010 case HOST_FILE_TELL: 1090 rc = fImpersonated 1091 ? gstcntlSessionHandleFileTell(pSession, pHostCtx) 1092 : VERR_NOT_SUPPORTED; 1011 if (fImpersonated) 1012 rc = vgsvcGstCtrlSessionHandleFileTell(pSession, pHostCtx); 1013 else 1014 rc = VERR_NOT_SUPPORTED; 1093 1015 break; 1094 1016 1095 1017 case HOST_PATH_RENAME: 1096 rc = fImpersonated 1097 ? gstcntlSessionHandlePathRename(pSession, pHostCtx) 1098 : VERR_NOT_SUPPORTED; 1018 if (fImpersonated) 1019 rc = vgsvcGstCtrlSessionHandlePathRename(pSession, pHostCtx); 1020 else 1021 rc = VERR_NOT_SUPPORTED; 1099 1022 break; 1100 1023 1101 1024 default: 1102 1025 rc = VbglR3GuestCtrlMsgSkip(pHostCtx->uClientID); 1103 VBoxServiceVerbose(3, "Unsupported message (uMsg=%RU32, cParms=%RU32) from host, skipping\n", 1104 uMsg, pHostCtx->uNumParms); 1026 VGSvcVerbose(3, "Unsupported message (uMsg=%RU32, cParms=%RU32) from host, skipping\n", uMsg, pHostCtx->uNumParms); 1105 1027 break; 1106 1028 } 1107 1029 1108 1030 if (RT_FAILURE(rc)) 1109 VBoxServiceError("Error while handling message (uMsg=%RU32, cParms=%RU32), rc=%Rrc\n", 1110 uMsg, pHostCtx->uNumParms, rc); 1031 VGSvcError("Error while handling message (uMsg=%RU32, cParms=%RU32), rc=%Rrc\n", uMsg, pHostCtx->uNumParms, rc); 1111 1032 1112 1033 return rc; … … 1118 1039 * This thread runs in the main executable to control the spawned session process. 1119 1040 * 1120 * @return IPRTstatus code.1121 * @param RTTHREAD Pointer to the thread's data.1122 * @param void* User-supplied argument pointer.1041 * @returns VBox status code. 1042 * @param hThreadSelf Thread handle. 1043 * @param pvUser Pointer to a VBOXSERVICECTRLSESSIONTHREAD structure. 1123 1044 * 1124 1045 */ 1125 static DECLCALLBACK(int) gstcntlSessionThread(RTTHREADThreadSelf, void *pvUser)1046 static DECLCALLBACK(int) vgsvcGstCtrlSessionThread(RTTHREAD hThreadSelf, void *pvUser) 1126 1047 { 1127 1048 PVBOXSERVICECTRLSESSIONTHREAD pThread = (PVBOXSERVICECTRLSESSIONTHREAD)pvUser; … … 1134 1055 if (RT_SUCCESS(rc)) 1135 1056 { 1136 VBoxServiceVerbose(3, "Session ID=%RU32 thread running, client ID=%RU32\n", 1137 uSessionID, uClientID); 1057 VGSvcVerbose(3, "Session ID=%RU32 thread running, client ID=%RU32\n", uSessionID, uClientID); 1138 1058 1139 1059 /* The session thread is not interested in receiving any commands; 1140 1060 * tell the host service. */ 1141 rc = VbglR3GuestCtrlMsgFilterSet(uClientID, 0 /* Skip all */, 1142 0 /* Filter mask to add */, 0 /* Filter mask to remove */); 1061 rc = VbglR3GuestCtrlMsgFilterSet(uClientID, 0 /* Skip all */, 0 /* Filter mask to add */, 0 /* Filter mask to remove */); 1143 1062 if (RT_FAILURE(rc)) 1144 1063 { 1145 V BoxServiceError("Unable to set message filter, rc=%Rrc\n", rc);1064 VGSvcError("Unable to set message filter, rc=%Rrc\n", rc); 1146 1065 /* Non-critical. */ 1147 1066 rc = VINF_SUCCESS; … … 1149 1068 } 1150 1069 else 1151 V BoxServiceError("Error connecting to guest control service, rc=%Rrc\n", rc);1070 VGSvcError("Error connecting to guest control service, rc=%Rrc\n", rc); 1152 1071 1153 1072 if (RT_FAILURE(rc)) … … 1155 1074 1156 1075 /* Let caller know that we're done initializing, regardless of the result. */ 1157 int rc2 = RTThreadUserSignal( RTThreadSelf());1076 int rc2 = RTThreadUserSignal(hThreadSelf); 1158 1077 AssertRC(rc2); 1159 1078 … … 1173 1092 for (;;) 1174 1093 { 1175 rcWait = RTProcWaitNoResume(pThread->hProcess, RTPROCWAIT_FLAGS_NOBLOCK, 1176 &ProcessStatus); 1094 rcWait = RTProcWaitNoResume(pThread->hProcess, RTPROCWAIT_FLAGS_NOBLOCK, &ProcessStatus); 1177 1095 if (RT_UNLIKELY(rcWait == VERR_INTERRUPTED)) 1178 1096 continue; 1179 else if ( rcWait == VINF_SUCCESS 1180 || rcWait == VERR_PROCESS_NOT_FOUND) 1097 1098 if ( rcWait == VINF_SUCCESS 1099 || rcWait == VERR_PROCESS_NOT_FOUND) 1181 1100 { 1182 1101 fProcessAlive = false; 1183 1102 break; 1184 1103 } 1185 else 1186 AssertMsgBreak(rcWait == VERR_PROCESS_RUNNING, 1187 ("Got unexpected rc=%Rrc while waiting for session process termination\n", rcWait)); 1104 AssertMsgBreak(rcWait == VERR_PROCESS_RUNNING, 1105 ("Got unexpected rc=%Rrc while waiting for session process termination\n", rcWait)); 1188 1106 1189 1107 if (ASMAtomicReadBool(&pThread->fShutdown)) … … 1191 1109 if (!u64TimeoutStart) 1192 1110 { 1193 VBoxServiceVerbose(3, "Notifying guest session process (PID=%RU32, session ID=%RU32) ...\n", 1194 pThread->hProcess, uSessionID); 1195 1196 VBGLR3GUESTCTRLCMDCTX hostCtx = { uClientID, 1197 VBOX_GUESTCTRL_CONTEXTID_MAKE_SESSION(uSessionID), 1198 pThread->StartupInfo.uProtocol, 2 /* uNumParms */ }; 1199 rc = VbglR3GuestCtrlSessionClose(&hostCtx, 0 /* uFlags */); 1111 VGSvcVerbose(3, "Notifying guest session process (PID=%RU32, session ID=%RU32) ...\n", 1112 pThread->hProcess, uSessionID); 1113 1114 VBGLR3GUESTCTRLCMDCTX hostCtx = 1115 { 1116 /* .idClient = */ uClientID, 1117 /* .idContext = */ VBOX_GUESTCTRL_CONTEXTID_MAKE_SESSION(uSessionID), 1118 /* .uProtocol = */ pThread->StartupInfo.uProtocol, 1119 /* .cParams = */ 2 1120 }; 1121 rc = VbglR3GuestCtrlSessionClose(&hostCtx, 0 /* fFlags */); 1200 1122 if (RT_FAILURE(rc)) 1201 1123 { 1202 V BoxServiceError("Unable to notify guest session process (PID=%RU32, session ID=%RU32), rc=%Rrc\n",1203 1124 VGSvcError("Unable to notify guest session process (PID=%RU32, session ID=%RU32), rc=%Rrc\n", 1125 pThread->hProcess, uSessionID, rc); 1204 1126 1205 1127 if (rc == VERR_NOT_SUPPORTED) … … 1207 1129 /* Terminate guest session process in case it's not supported by a too old host. */ 1208 1130 rc = RTProcTerminate(pThread->hProcess); 1209 V BoxServiceVerbose(3, "Terminating guest session process (PID=%RU32) ended with rc=%Rrc\n",1210 1131 VGSvcVerbose(3, "Terminating guest session process (PID=%RU32) ended with rc=%Rrc\n", 1132 pThread->hProcess, rc); 1211 1133 } 1212 1134 break; 1213 1135 } 1214 1136 1215 V BoxServiceVerbose(3, "Guest session ID=%RU32 thread was asked to terminate, waiting for session process to exit (%RU32ms timeout) ...\n",1216 1137 VGSvcVerbose(3, "Guest session ID=%RU32 thread was asked to terminate, waiting for session process to exit (%RU32ms timeout) ...\n", 1138 uSessionID, uTimeoutsMS); 1217 1139 u64TimeoutStart = RTTimeMilliTS(); 1218 1219 1140 continue; /* Don't waste time on waiting. */ 1220 1141 } 1221 1142 if (RTTimeMilliTS() - u64TimeoutStart > uTimeoutsMS) 1222 1143 { 1223 VBoxServiceVerbose(3, "Guest session ID=%RU32 process did not shut down within time\n", 1224 uSessionID); 1144 VGSvcVerbose(3, "Guest session ID=%RU32 process did not shut down within time\n", uSessionID); 1225 1145 break; 1226 1146 } … … 1232 1152 if (!fProcessAlive) 1233 1153 { 1234 VBoxServiceVerbose(2, "Guest session process (ID=%RU32) terminated with rc=%Rrc, reason=%ld, status=%d\n", 1235 uSessionID, rcWait, 1236 ProcessStatus.enmReason, ProcessStatus.iStatus); 1154 VGSvcVerbose(2, "Guest session process (ID=%RU32) terminated with rc=%Rrc, reason=%d, status=%d\n", 1155 uSessionID, rcWait, ProcessStatus.enmReason, ProcessStatus.iStatus); 1237 1156 if (ProcessStatus.iStatus == RTEXITCODE_INIT) 1238 1157 { 1239 VBoxServiceError("Guest session process (ID=%RU32) failed to initialize. Here some hints:\n", 1240 uSessionID); 1241 VBoxServiceError("- Is logging enabled and the output directory is read-only by the guest session user?\n"); 1158 VGSvcError("Guest session process (ID=%RU32) failed to initialize. Here some hints:\n", uSessionID); 1159 VGSvcError("- Is logging enabled and the output directory is read-only by the guest session user?\n"); 1242 1160 /** @todo Add more here. */ 1243 1161 } … … 1252 1170 for (int i = 0; i < 3; i++) 1253 1171 { 1254 VBoxServiceVerbose(2, "Guest session ID=%RU32 process still alive, killing attempt %d/3\n", 1255 uSessionID, i + 1); 1172 VGSvcVerbose(2, "Guest session ID=%RU32 process still alive, killing attempt %d/3\n", uSessionID, i + 1); 1256 1173 1257 1174 rc = RTProcTerminate(pThread->hProcess); 1258 1175 if (RT_SUCCESS(rc)) 1259 1176 break; 1177 /** @todo r=bird: What's the point of sleeping 3 second after the last attempt? */ 1260 1178 RTThreadSleep(3000); 1261 1179 } 1262 1180 1263 VBoxServiceVerbose(2, "Guest session ID=%RU32 process termination resulted in rc=%Rrc\n", 1264 uSessionID, rc); 1265 1266 uSessionStatus = RT_SUCCESS(rc) 1267 ? GUEST_SESSION_NOTIFYTYPE_TOK : GUEST_SESSION_NOTIFYTYPE_TOA; 1181 VGSvcVerbose(2, "Guest session ID=%RU32 process termination resulted in rc=%Rrc\n", uSessionID, rc); 1182 1183 uSessionStatus = RT_SUCCESS(rc) ? GUEST_SESSION_NOTIFYTYPE_TOK : GUEST_SESSION_NOTIFYTYPE_TOA; 1184 } 1185 else if (RT_SUCCESS(rcWait)) 1186 { 1187 switch (ProcessStatus.enmReason) 1188 { 1189 case RTPROCEXITREASON_NORMAL: 1190 uSessionStatus = GUEST_SESSION_NOTIFYTYPE_TEN; 1191 break; 1192 1193 case RTPROCEXITREASON_ABEND: 1194 uSessionStatus = GUEST_SESSION_NOTIFYTYPE_TEA; 1195 break; 1196 1197 case RTPROCEXITREASON_SIGNAL: 1198 uSessionStatus = GUEST_SESSION_NOTIFYTYPE_TES; 1199 break; 1200 1201 default: 1202 AssertMsgFailed(("Unhandled process termination reason (%d)\n", ProcessStatus.enmReason)); 1203 uSessionStatus = GUEST_SESSION_NOTIFYTYPE_TEA; 1204 break; 1205 } 1268 1206 } 1269 1207 else 1270 1208 { 1271 if (RT_SUCCESS(rcWait)) 1272 { 1273 switch (ProcessStatus.enmReason) 1274 { 1275 case RTPROCEXITREASON_NORMAL: 1276 uSessionStatus = GUEST_SESSION_NOTIFYTYPE_TEN; 1277 break; 1278 1279 case RTPROCEXITREASON_ABEND: 1280 uSessionStatus = GUEST_SESSION_NOTIFYTYPE_TEA; 1281 break; 1282 1283 case RTPROCEXITREASON_SIGNAL: 1284 uSessionStatus = GUEST_SESSION_NOTIFYTYPE_TES; 1285 break; 1286 1287 default: 1288 AssertMsgFailed(("Unhandled process termination reason (%ld)\n", 1289 ProcessStatus.enmReason)); 1290 uSessionStatus = GUEST_SESSION_NOTIFYTYPE_TEA; 1291 break; 1292 } 1293 } 1294 else 1295 { 1296 /* If we didn't find the guest process anymore, just assume it 1297 * terminated normally. */ 1298 uSessionStatus = GUEST_SESSION_NOTIFYTYPE_TEN; 1299 } 1300 } 1301 1302 VBoxServiceVerbose(3, "Guest session ID=%RU32 thread ended with sessionStatus=%RU32, sessionRc=%Rrc\n", 1303 uSessionID, uSessionStatus, uSessionRc); 1209 /* If we didn't find the guest process anymore, just assume it 1210 * terminated normally. */ 1211 uSessionStatus = GUEST_SESSION_NOTIFYTYPE_TEN; 1212 } 1213 1214 VGSvcVerbose(3, "Guest session ID=%RU32 thread ended with sessionStatus=%RU32, sessionRc=%Rrc\n", 1215 uSessionID, uSessionStatus, uSessionRc); 1304 1216 1305 1217 /* Report final status. */ 1306 1218 Assert(uSessionStatus != GUEST_SESSION_NOTIFYTYPE_UNDEFINED); 1307 1219 VBGLR3GUESTCTRLCMDCTX ctx = { uClientID, VBOX_GUESTCTRL_CONTEXTID_MAKE_SESSION(uSessionID) }; 1308 rc2 = VbglR3GuestCtrlSessionNotify(&ctx, 1309 uSessionStatus, uSessionRc); 1220 rc2 = VbglR3GuestCtrlSessionNotify(&ctx, uSessionStatus, uSessionRc); 1310 1221 if (RT_FAILURE(rc2)) 1311 VBoxServiceError("Reporting session ID=%RU32 final status failed with rc=%Rrc\n", 1312 uSessionID, rc2); 1222 VGSvcError("Reporting session ID=%RU32 final status failed with rc=%Rrc\n", uSessionID, rc2); 1313 1223 1314 1224 VbglR3GuestCtrlDisconnect(uClientID); 1315 1225 1316 VBoxServiceVerbose(3, "Session ID=%RU32 thread ended with rc=%Rrc\n", 1317 uSessionID, rc); 1318 return rc; 1319 } 1320 1321 1322 RTEXITCODE gstcntlSessionSpawnWorker(PVBOXSERVICECTRLSESSION pSession) 1226 VGSvcVerbose(3, "Session ID=%RU32 thread ended with rc=%Rrc\n", uSessionID, rc); 1227 return rc; 1228 } 1229 1230 1231 static RTEXITCODE vgsvcGstCtrlSessionSpawnWorker(PVBOXSERVICECTRLSESSION pSession) 1323 1232 { 1324 1233 AssertPtrReturn(pSession, RTEXITCODE_FAILURE); … … 1326 1235 bool fSessionFilter = true; 1327 1236 1328 VBoxServiceVerbose(0, "Hi, this is guest session ID=%RU32\n", 1329 pSession->StartupInfo.uSessionID); 1237 VGSvcVerbose(0, "Hi, this is guest session ID=%RU32\n", pSession->StartupInfo.uSessionID); 1330 1238 1331 1239 uint32_t uClientID; … … 1336 1244 * host service to send messages which belong to another 1337 1245 * session we don't want to handle. */ 1338 uint32_t uFilterAdd = 1339 VBOX_GUESTCTRL_FILTER_BY_SESSION(pSession->StartupInfo.uSessionID); 1246 uint32_t uFilterAdd = VBOX_GUESTCTRL_FILTER_BY_SESSION(pSession->StartupInfo.uSessionID); 1340 1247 rc = VbglR3GuestCtrlMsgFilterSet(uClientID, 1341 1248 VBOX_GUESTCTRL_CONTEXTID_MAKE_SESSION(pSession->StartupInfo.uSessionID), 1342 1249 uFilterAdd, 0 /* Filter remove */); 1343 VBoxServiceVerbose(3, "Setting message filterAdd=0x%x returned %Rrc\n", 1344 uFilterAdd, rc); 1250 VGSvcVerbose(3, "Setting message filterAdd=0x%x returned %Rrc\n", uFilterAdd, rc); 1345 1251 1346 1252 if ( RT_FAILURE(rc) … … 1353 1259 } 1354 1260 1355 V BoxServiceVerbose(1, "Using client ID=%RU32\n", uClientID);1261 VGSvcVerbose(1, "Using client ID=%RU32\n", uClientID); 1356 1262 } 1357 1263 else 1358 V BoxServiceError("Error connecting to guest control service, rc=%Rrc\n", rc);1264 VGSvcError("Error connecting to guest control service, rc=%Rrc\n", rc); 1359 1265 1360 1266 /* Report started status. */ 1361 1267 VBGLR3GUESTCTRLCMDCTX ctx = { uClientID, VBOX_GUESTCTRL_CONTEXTID_MAKE_SESSION(pSession->StartupInfo.uSessionID) }; 1362 int rc2 = VbglR3GuestCtrlSessionNotify(&ctx, 1363 GUEST_SESSION_NOTIFYTYPE_STARTED, VINF_SUCCESS); 1268 int rc2 = VbglR3GuestCtrlSessionNotify(&ctx, GUEST_SESSION_NOTIFYTYPE_STARTED, VINF_SUCCESS); 1364 1269 if (RT_FAILURE(rc2)) 1365 1270 { 1366 VBoxServiceError("Reporting session ID=%RU32 started status failed with rc=%Rrc\n", 1367 pSession->StartupInfo.uSessionID, rc2); 1271 VGSvcError("Reporting session ID=%RU32 started status failed with rc=%Rrc\n", pSession->StartupInfo.uSessionID, rc2); 1368 1272 1369 1273 /* … … 1392 1296 bool fShutdown = false; 1393 1297 1394 VBGLR3GUESTCTRLCMDCTX ctxHost = { uClientID, 0 /* Context ID, zeroed */, 1395 pSession->StartupInfo.uProtocol }; 1298 VBGLR3GUESTCTRLCMDCTX ctxHost = { uClientID, 0 /* Context ID */, pSession->StartupInfo.uProtocol }; 1396 1299 for (;;) 1397 1300 { 1398 V BoxServiceVerbose(3, "Waiting for host msg ...\n");1301 VGSvcVerbose(3, "Waiting for host msg ...\n"); 1399 1302 uint32_t uMsg = 0; 1400 1303 uint32_t cParms = 0; … … 1403 1306 { 1404 1307 #ifdef DEBUG 1405 VBoxServiceVerbose(4, "Message requires %RU32 parameters, but only 2 supplied -- retrying request (no error!)...\n", cParms); 1308 VGSvcVerbose(4, "Message requires %RU32 parameters, but only 2 supplied -- retrying request (no error!)...\n", 1309 cParms); 1406 1310 #endif 1407 1311 rc = VINF_SUCCESS; /* Try to get "real" message in next block below. */ 1408 1312 } 1409 1313 else if (RT_FAILURE(rc)) 1410 V BoxServiceVerbose(3, "Getting host message failed with %Rrc\n", rc); /* VERR_GEN_IO_FAILURE seems to be normal if ran into timeout. */1314 VGSvcVerbose(3, "Getting host message failed with %Rrc\n", rc); /* VERR_GEN_IO_FAILURE seems to be normal if ran into timeout. */ 1411 1315 if (RT_SUCCESS(rc)) 1412 1316 { 1413 V BoxServiceVerbose(4, "Msg=%RU32 (%RU32 parms) retrieved\n", uMsg, cParms);1317 VGSvcVerbose(4, "Msg=%RU32 (%RU32 parms) retrieved\n", uMsg, cParms); 1414 1318 1415 1319 /* Set number of parameters for current host context. */ … … 1417 1321 1418 1322 /* ... and pass it on to the session handler. */ 1419 rc = GstCntlSessionHandler(pSession, uMsg, &ctxHost, 1420 pvScratchBuf, cbScratchBuf, &fShutdown); 1323 rc = VGSvcGstCtrlSessionHandler(pSession, uMsg, &ctxHost, pvScratchBuf, cbScratchBuf, &fShutdown); 1421 1324 } 1422 1325 … … 1424 1327 break; 1425 1328 1426 /* Let 's sleep for a bit and letothers run ... */1329 /* Let others run ... */ 1427 1330 RTThreadYield(); 1428 1331 } 1429 1332 } 1430 1333 1431 V BoxServiceVerbose(0, "Session %RU32 ended\n", pSession->StartupInfo.uSessionID);1334 VGSvcVerbose(0, "Session %RU32 ended\n", pSession->StartupInfo.uSessionID); 1432 1335 1433 1336 if (pvScratchBuf) … … 1436 1339 if (uClientID) 1437 1340 { 1438 V BoxServiceVerbose(3, "Disconnecting client ID=%RU32 ...\n", uClientID);1341 VGSvcVerbose(3, "Disconnecting client ID=%RU32 ...\n", uClientID); 1439 1342 VbglR3GuestCtrlDisconnect(uClientID); 1440 1343 } 1441 1344 1442 V BoxServiceVerbose(3, "Session worker returned with rc=%Rrc\n", rc);1345 VGSvcVerbose(3, "Session worker returned with rc=%Rrc\n", rc); 1443 1346 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 1444 1347 } … … 1446 1349 1447 1350 /** 1448 * Finds a (formerly) started guest process given by its PID and increases 1449 * its reference count. Must be decreased by the caller with GstCntlProcessRelease(). 1450 * Note: This does *not lock the process! 1351 * Finds a (formerly) started guest process given by its PID and increases its 1352 * reference count. 1451 1353 * 1452 * @return PVBOXSERVICECTRLTHREAD Guest process if found, otherwise NULL. 1453 * @param PVBOXSERVICECTRLSESSION Pointer to guest session where to search process in. 1454 * @param uPID PID to search for. 1354 * Must be decreased by the caller with VGSvcGstCtrlProcessRelease(). 1355 * 1356 * @returns Guest process if found, otherwise NULL. 1357 * @param pSession Pointer to guest session where to search process in. 1358 * @param uPID PID to search for. 1359 * 1360 * @note This does *not lock the process! 1455 1361 */ 1456 PVBOXSERVICECTRLPROCESS GstCntlSessionRetainProcess(PVBOXSERVICECTRLSESSION pSession, uint32_t uPID)1362 PVBOXSERVICECTRLPROCESS VGSvcGstCtrlSessionRetainProcess(PVBOXSERVICECTRLSESSION pSession, uint32_t uPID) 1457 1363 { 1458 1364 AssertPtrReturn(pSession, NULL); … … 1489 1395 1490 1396 1491 int GstCntlSessionClose(PVBOXSERVICECTRLSESSION pSession)1397 int VGSvcGstCtrlSessionClose(PVBOXSERVICECTRLSESSION pSession) 1492 1398 { 1493 1399 AssertPtrReturn(pSession, VERR_INVALID_POINTER); 1494 1400 1495 VBoxServiceVerbose(0, "Session %RU32 is about to close ...\n", 1496 pSession->StartupInfo.uSessionID); 1401 VGSvcVerbose(0, "Session %RU32 is about to close ...\n", pSession->StartupInfo.uSessionID); 1497 1402 1498 1403 int rc = RTCritSectEnter(&pSession->CritSect); … … 1502 1407 * Close all guest processes. 1503 1408 */ 1504 V BoxServiceVerbose(0, "Stopping all guest processes ...\n");1409 VGSvcVerbose(0, "Stopping all guest processes ...\n"); 1505 1410 1506 1411 /* Signal all guest processes in the active list that we want to shutdown. */ … … 1509 1414 RTListForEach(&pSession->lstProcesses, pProcess, VBOXSERVICECTRLPROCESS, Node) 1510 1415 { 1511 GstCntlProcessStop(pProcess);1416 VGSvcGstCtrlProcessStop(pProcess); 1512 1417 cProcesses++; 1513 1418 } 1514 1419 1515 V BoxServiceVerbose(1, "%zu guest processes were signalled to stop\n", cProcesses);1420 VGSvcVerbose(1, "%zu guest processes were signalled to stop\n", cProcesses); 1516 1421 1517 1422 /* Wait for all active threads to shutdown and destroy the active thread list. */ … … 1525 1430 AssertRC(rc2); 1526 1431 1527 rc2 = GstCntlProcessWait(pProcess, 1528 30 * 1000 /* Wait 30 seconds max. */, 1529 NULL /* rc */); 1432 rc2 = VGSvcGstCtrlProcessWait(pProcess, 30 * 1000 /* Wait 30 seconds max. */, NULL /* rc */); 1530 1433 1531 1434 int rc3 = RTCritSectEnter(&pSession->CritSect); … … 1533 1436 1534 1437 if (RT_SUCCESS(rc2)) 1535 GstCntlProcessFree(pProcess);1438 VGSvcGstCtrlProcessFree(pProcess); 1536 1439 1537 1440 if (fLast) … … 1548 1451 bool fLast = RTListNodeIsLast(&pSession->lstProcesses, &pProcess->Node); 1549 1452 1550 VBoxServiceVerbose(1, "Process %p (PID %RU32) still in list\n", 1551 pProcess, pProcess->uPID); 1453 VGSvcVerbose(1, "Process %p (PID %RU32) still in list\n", pProcess, pProcess->uPID); 1552 1454 if (fLast) 1553 1455 break; … … 1562 1464 * Close all left guest files. 1563 1465 */ 1564 V BoxServiceVerbose(0, "Closing all guest files ...\n");1466 VGSvcVerbose(0, "Closing all guest files ...\n"); 1565 1467 1566 1468 PVBOXSERVICECTRLFILE pFile; … … 1571 1473 bool fLast = RTListNodeIsLast(&pSession->lstFiles, &pFile->Node); 1572 1474 1573 int rc2 = gstcntlSessionFileDestroy(pFile);1475 int rc2 = vgsvcGstCtrlSessionFileDestroy(pFile); 1574 1476 if (RT_FAILURE(rc2)) 1575 1477 { 1576 VBoxServiceError("Unable to close file \"%s\"; rc=%Rrc\n", 1577 pFile->szName, rc2); 1478 VGSvcError("Unable to close file '%s'; rc=%Rrc\n", pFile->szName, rc2); 1578 1479 if (RT_SUCCESS(rc)) 1579 1480 rc = rc2; … … 1587 1488 } 1588 1489 1589 AssertMsg(RTListIsEmpty(&pSession->lstFiles), 1590 ("Guest file list still contains entries when it should not\n")); 1490 AssertMsg(RTListIsEmpty(&pSession->lstFiles), ("Guest file list still contains entries when it should not\n")); 1591 1491 1592 1492 int rc2 = RTCritSectLeave(&pSession->CritSect); … … 1599 1499 1600 1500 1601 int GstCntlSessionDestroy(PVBOXSERVICECTRLSESSION pSession)1501 int VGSvcGstCtrlSessionDestroy(PVBOXSERVICECTRLSESSION pSession) 1602 1502 { 1603 1503 AssertPtrReturn(pSession, VERR_INVALID_POINTER); 1604 1504 1605 int rc = GstCntlSessionClose(pSession);1505 int rc = VGSvcGstCtrlSessionClose(pSession); 1606 1506 1607 1507 /* Destroy critical section. */ … … 1612 1512 1613 1513 1614 int GstCntlSessionInit(PVBOXSERVICECTRLSESSION pSession, uint32_t fFlags)1514 int VGSvcGstCtrlSessionInit(PVBOXSERVICECTRLSESSION pSession, uint32_t fFlags) 1615 1515 { 1616 1516 AssertPtrReturn(pSession, VERR_INVALID_POINTER); … … 1632 1532 * Adds a guest process to a session's process list. 1633 1533 * 1634 * @return IPRTstatus code.1534 * @return VBox status code. 1635 1535 * @param pSession Guest session to add process to. 1636 1536 * @param pProcess Guest process to add. 1637 1537 */ 1638 int GstCntlSessionProcessAdd(PVBOXSERVICECTRLSESSION pSession, 1639 PVBOXSERVICECTRLPROCESS pProcess) 1538 int VGSvcGstCtrlSessionProcessAdd(PVBOXSERVICECTRLSESSION pSession, PVBOXSERVICECTRLPROCESS pProcess) 1640 1539 { 1641 1540 AssertPtrReturn(pSession, VERR_INVALID_POINTER); … … 1645 1544 if (RT_SUCCESS(rc)) 1646 1545 { 1647 VBoxServiceVerbose(3, "Adding process (PID %RU32) to session ID=%RU32\n", 1648 pProcess->uPID, pSession->StartupInfo.uSessionID); 1546 VGSvcVerbose( 3, "Adding process (PID %RU32) to session ID=%RU32\n", pProcess->uPID, pSession->StartupInfo.uSessionID); 1649 1547 1650 1548 /* Add process to session list. */ 1651 /* rc = */RTListAppend(&pSession->lstProcesses, &pProcess->Node);1549 RTListAppend(&pSession->lstProcesses, &pProcess->Node); 1652 1550 1653 1551 int rc2 = RTCritSectLeave(&pSession->CritSect); … … 1663 1561 * Removes a guest process from a session's process list. 1664 1562 * 1665 * @return IPRTstatus code.1563 * @return VBox status code. 1666 1564 * @param pSession Guest session to remove process from. 1667 1565 * @param pProcess Guest process to remove. 1668 1566 */ 1669 int GstCntlSessionProcessRemove(PVBOXSERVICECTRLSESSION pSession, 1670 PVBOXSERVICECTRLPROCESS pProcess) 1567 int VGSvcGstCtrlSessionProcessRemove(PVBOXSERVICECTRLSESSION pSession, PVBOXSERVICECTRLPROCESS pProcess) 1671 1568 { 1672 1569 AssertPtrReturn(pSession, VERR_INVALID_POINTER); … … 1676 1573 if (RT_SUCCESS(rc)) 1677 1574 { 1678 VBoxServiceVerbose(3, "Removing process (PID %RU32) from session ID=%RU32\n", 1679 pProcess->uPID, pSession->StartupInfo.uSessionID); 1575 VGSvcVerbose(3, "Removing process (PID %RU32) from session ID=%RU32\n", pProcess->uPID, pSession->StartupInfo.uSessionID); 1680 1576 Assert(pProcess->cRefs == 0); 1681 1577 … … 1695 1591 * maximum number of concurrent guest processes defined is allowed or not. 1696 1592 * 1697 * @return IPRTstatus code.1593 * @return VBox status code. 1698 1594 * @param pbAllowed True if starting (another) guest process 1699 1595 * is allowed, false if not. 1700 1596 */ 1701 int GstCntlSessionProcessStartAllowed(const PVBOXSERVICECTRLSESSION pSession, 1702 bool *pbAllowed) 1597 int VGSvcGstCtrlSessionProcessStartAllowed(const PVBOXSERVICECTRLSESSION pSession, bool *pbAllowed) 1703 1598 { 1704 1599 AssertPtrReturn(pSession, VERR_INVALID_POINTER); … … 1720 1615 uProcsRunning++; 1721 1616 1722 VBoxServiceVerbose(3, "Maximum served guest processes set to %u, running=%u\n", 1723 pSession->uProcsMaxKept, uProcsRunning); 1617 VGSvcVerbose(3, "Maximum served guest processes set to %u, running=%u\n", pSession->uProcsMaxKept, uProcsRunning); 1724 1618 1725 1619 int32_t iProcsLeft = (pSession->uProcsMaxKept - uProcsRunning - 1); 1726 1620 if (iProcsLeft < 0) 1727 1621 { 1728 VBoxServiceVerbose(3, "Maximum running guest processes reached (%u)\n", 1729 pSession->uProcsMaxKept); 1622 VGSvcVerbose(3, "Maximum running guest processes reached (%u)\n", pSession->uProcsMaxKept); 1730 1623 fLimitReached = true; 1731 1624 } … … 1747 1640 * 1748 1641 * 1749 * @return IPRTstatus code.1642 * @return VBox status code. 1750 1643 * @param pSessionStartupInfo Session startup info. 1751 1644 * @param pSessionThread The session thread under construction. 1752 1645 * @param uCtrlSessionThread The session thread debug ordinal. 1753 1646 */ 1754 static int vgsvc GstCntlSessionThreadCreateProcess(const PVBOXSERVICECTRLSESSIONSTARTUPINFO pSessionStartupInfo,1755 PVBOXSERVICECTRLSESSIONTHREAD pSessionThread, uint32_t uCtrlSessionThread)1647 static int vgsvcVGSvcGstCtrlSessionThreadCreateProcess(const PVBOXSERVICECTRLSESSIONSTARTUPINFO pSessionStartupInfo, 1648 PVBOXSERVICECTRLSESSIONTHREAD pSessionThread, uint32_t uCtrlSessionThread) 1756 1649 { 1757 1650 /* … … 1765 1658 Assert(!strlen(pSessionThread->StartupInfo.szDomain)); 1766 1659 1767 V BoxServiceVerbose(3, "New anonymous guest session ID=%RU32 created, fFlags=%x, using protocol %RU32\n",1768 1769 1770 1660 VGSvcVerbose(3, "New anonymous guest session ID=%RU32 created, fFlags=%x, using protocol %RU32\n", 1661 pSessionStartupInfo->uSessionID, 1662 pSessionStartupInfo->fFlags, 1663 pSessionStartupInfo->uProtocol); 1771 1664 } 1772 1665 else 1773 1666 { 1774 V BoxServiceVerbose(3, "Spawning new guest session ID=%RU32, szUser=%s, szPassword=%s, szDomain=%s, fFlags=%x, using protocol %RU32\n",1775 1776 1777 #ifdef DEBUG 1778 1667 VGSvcVerbose(3, "Spawning new guest session ID=%RU32, szUser=%s, szPassword=%s, szDomain=%s, fFlags=%x, using protocol %RU32\n", 1668 pSessionStartupInfo->uSessionID, 1669 pSessionStartupInfo->szUser, 1670 #ifdef DEBUG 1671 pSessionStartupInfo->szPassword, 1779 1672 #else 1780 1781 #endif 1782 1783 1784 1673 "XXX", /* Never show passwords in release mode. */ 1674 #endif 1675 pSessionStartupInfo->szDomain, 1676 pSessionStartupInfo->fFlags, 1677 pSessionStartupInfo->uProtocol); 1785 1678 } 1786 1679 … … 1853 1746 1854 1747 #ifdef DEBUG 1855 V BoxServiceVerbose(4, "Argv building rc=%Rrc, session flags=%x\n", rc, g_Session.fFlags);1748 VGSvcVerbose(4, "Argv building rc=%Rrc, session flags=%x\n", rc, g_Session.fFlags); 1856 1749 if (RT_SUCCESS(rc)) 1857 1750 { … … 1867 1760 if (g_cVerbosity > 3) 1868 1761 { 1869 V BoxServiceVerbose(4, "Spawning parameters:\n");1762 VGSvcVerbose(4, "Spawning parameters:\n"); 1870 1763 for (idxArg = 0; apszArgs[idxArg]; idxArg++) 1871 V BoxServiceVerbose(4, "\t%s\n", apszArgs[idxArg]);1764 VGSvcVerbose(4, "\t%s\n", apszArgs[idxArg]); 1872 1765 } 1873 1766 … … 1968 1861 * be added to the given session thread list. 1969 1862 * 1970 * @return IPRTstatus code.1863 * @return VBox status code. 1971 1864 * @param pList Which list to use to store the session thread in. 1972 1865 * @param pSessionStartupInfo Session startup info. … … 1974 1867 * Optional. 1975 1868 */ 1976 int GstCntlSessionThreadCreate(PRTLISTANCHOR pList, 1977 const PVBOXSERVICECTRLSESSIONSTARTUPINFO pSessionStartupInfo, 1978 PVBOXSERVICECTRLSESSIONTHREAD *ppSessionThread) 1869 int VGSvcGstCtrlSessionThreadCreate(PRTLISTANCHOR pList, const PVBOXSERVICECTRLSESSIONSTARTUPINFO pSessionStartupInfo, 1870 PVBOXSERVICECTRLSESSIONTHREAD *ppSessionThread) 1979 1871 { 1980 1872 AssertPtrReturn(pList, VERR_INVALID_POINTER); … … 2020 1912 * Start the session thread. 2021 1913 */ 2022 rc = vgsvc GstCntlSessionThreadCreateProcess(pSessionStartupInfo, pSessionThread, s_uCtrlSessionThread);1914 rc = vgsvcVGSvcGstCtrlSessionThreadCreateProcess(pSessionStartupInfo, pSessionThread, s_uCtrlSessionThread); 2023 1915 if (RT_SUCCESS(rc)) 2024 1916 { … … 2026 1918 * Start the session thread. 2027 1919 */ 2028 rc = RTThreadCreateF(&pSessionThread->Thread, gstcntlSessionThread,1920 rc = RTThreadCreateF(&pSessionThread->Thread, vgsvcGstCtrlSessionThread, 2029 1921 pSessionThread /*pvUser*/, 0 /*cbStack*/, 2030 1922 RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "sess%u", s_uCtrlSessionThread); … … 2036 1928 && !ASMAtomicReadBool(&pSessionThread->fShutdown)) 2037 1929 { 2038 V BoxServiceVerbose(2, "Thread for session ID=%RU32 started\n", pSessionThread->StartupInfo.uSessionID);1930 VGSvcVerbose(2, "Thread for session ID=%RU32 started\n", pSessionThread->StartupInfo.uSessionID); 2039 1931 2040 1932 ASMAtomicXchgBool(&pSessionThread->fStarted, true); 2041 1933 2042 1934 /* Add session to list. */ 2043 /* rc = */RTListAppend(pList, &pSessionThread->Node);1935 RTListAppend(pList, &pSessionThread->Node); 2044 1936 if (ppSessionThread) /* Return session if wanted. */ 2045 1937 *ppSessionThread = pSessionThread; … … 2050 1942 * Bail out. 2051 1943 */ 2052 V BoxServiceError("Thread for session ID=%RU32 failed to start, rc=%Rrc\n",2053 1944 VGSvcError("Thread for session ID=%RU32 failed to start, rc=%Rrc\n", 1945 pSessionThread->StartupInfo.uSessionID, rc); 2054 1946 if (RT_SUCCESS_NP(rc)) 2055 1947 rc = VERR_CANT_CREATE; /** @todo Find a better rc. */ 2056 1948 } 2057 1949 else 2058 V BoxServiceError("Creating session thread failed, rc=%Rrc\n", rc);1950 VGSvcError("Creating session thread failed, rc=%Rrc\n", rc); 2059 1951 2060 1952 RTProcTerminate(pSessionThread->hProcess); … … 2074 1966 rc = VERR_NO_MEMORY; 2075 1967 2076 V BoxServiceVerbose(3, "Spawning session thread returned returned rc=%Rrc\n", rc);1968 VGSvcVerbose(3, "Spawning session thread returned returned rc=%Rrc\n", rc); 2077 1969 return rc; 2078 1970 } … … 2082 1974 * Waits for a formerly opened guest session process to close. 2083 1975 * 2084 * @return IPRTstatus code.1976 * @return VBox status code. 2085 1977 * @param pThread Guest session thread to wait for. 2086 1978 * @param uTimeoutMS Waiting timeout (in ms). 2087 * @param uFlags Closing flags.1979 * @param fFlags Closing flags. 2088 1980 */ 2089 int GstCntlSessionThreadWait(PVBOXSERVICECTRLSESSIONTHREAD pThread, 2090 uint32_t uTimeoutMS, uint32_t uFlags) 1981 int VGSvcGstCtrlSessionThreadWait(PVBOXSERVICECTRLSESSIONTHREAD pThread, uint32_t uTimeoutMS, uint32_t fFlags) 2091 1982 { 2092 1983 AssertPtrReturn(pThread, VERR_INVALID_POINTER); 2093 1984 /** @todo Validate closing flags. */ 2094 1985 2095 if (pThread->Thread == NIL_RTTHREAD) 2096 { 2097 AssertMsgFailed(("Guest session thread of session %p does not exist when it should\n", 2098 pThread)); 2099 return VERR_NOT_FOUND; 2100 } 1986 AssertMsgReturn(pThread->Thread != NIL_RTTHREAD, 1987 ("Guest session thread of session %p does not exist when it should\n", pThread), 1988 VERR_NOT_FOUND); 2101 1989 2102 1990 int rc = VINF_SUCCESS; … … 2111 1999 ASMAtomicXchgBool(&pThread->fShutdown, true); 2112 2000 2113 V BoxServiceVerbose(3, "Waiting for session thread ID=%RU32 to close (%RU32ms) ...\n",2114 2001 VGSvcVerbose(3, "Waiting for session thread ID=%RU32 to close (%RU32ms) ...\n", 2002 pThread->StartupInfo.uSessionID, uTimeoutMS); 2115 2003 2116 2004 int rcThread; 2117 2005 rc = RTThreadWait(pThread->Thread, uTimeoutMS, &rcThread); 2118 if (RT_FAILURE(rc)) 2119 { 2120 VBoxServiceError("Waiting for session thread ID=%RU32 to close failed with rc=%Rrc\n", 2121 pThread->StartupInfo.uSessionID, rc); 2122 } 2006 if (RT_SUCCESS(rc)) 2007 VGSvcVerbose(3, "Session thread ID=%RU32 ended with rc=%Rrc\n", pThread->StartupInfo.uSessionID, rcThread); 2123 2008 else 2124 VBoxServiceVerbose(3, "Session thread ID=%RU32 ended with rc=%Rrc\n", 2125 pThread->StartupInfo.uSessionID, rcThread); 2009 VGSvcError("Waiting for session thread ID=%RU32 to close failed with rc=%Rrc\n", pThread->StartupInfo.uSessionID, rc); 2126 2010 } 2127 2011 … … 2133 2017 * it from the session thread list. 2134 2018 * 2135 * @return IPRTstatus code.2019 * @return VBox status code. 2136 2020 * @param pThread Session thread to destroy. 2137 * @param uFlags Closing flags.2021 * @param fFlags Closing flags. 2138 2022 */ 2139 int GstCntlSessionThreadDestroy(PVBOXSERVICECTRLSESSIONTHREAD pThread, uint32_t uFlags)2023 int VGSvcGstCtrlSessionThreadDestroy(PVBOXSERVICECTRLSESSIONTHREAD pThread, uint32_t fFlags) 2140 2024 { 2141 2025 AssertPtrReturn(pThread, VERR_INVALID_POINTER); 2142 2026 2143 int rc = GstCntlSessionThreadWait(pThread, 2144 5 * 60 * 1000 /* 5 minutes timeout */, uFlags); 2027 int rc = VGSvcGstCtrlSessionThreadWait(pThread, 5 * 60 * 1000 /* 5 minutes timeout */, fFlags); 2145 2028 2146 2029 /* Remove session from list and destroy object. */ … … 2158 2041 * @note Caller is responsible for locking! 2159 2042 * 2160 * @return IPRTstatus code.2043 * @return VBox status code. 2161 2044 * @param pList Which list to close the session threads for. 2162 * @param uFlags Closing flags.2045 * @param fFlags Closing flags. 2163 2046 */ 2164 int GstCntlSessionThreadDestroyAll(PRTLISTANCHOR pList, uint32_t uFlags)2047 int VGSvcGstCtrlSessionThreadDestroyAll(PRTLISTANCHOR pList, uint32_t fFlags) 2165 2048 { 2166 2049 AssertPtrReturn(pList, VERR_INVALID_POINTER); … … 2170 2053 /*int rc = VbglR3GuestCtrlClose 2171 2054 if (RT_FAILURE(rc)) 2172 V BoxServiceError("Cancelling pending waits failed; rc=%Rrc\n", rc);*/2055 VGSvcError("Cancelling pending waits failed; rc=%Rrc\n", rc);*/ 2173 2056 2174 2057 PVBOXSERVICECTRLSESSIONTHREAD pSessIt; … … 2176 2059 RTListForEachSafe(pList, pSessIt, pSessItNext, VBOXSERVICECTRLSESSIONTHREAD, Node) 2177 2060 { 2178 int rc2 = GstCntlSessionThreadDestroy(pSessIt, uFlags);2061 int rc2 = VGSvcGstCtrlSessionThreadDestroy(pSessIt, fFlags); 2179 2062 if (RT_FAILURE(rc2)) 2180 2063 { 2181 V BoxServiceError("Closing session thread '%s' failed with rc=%Rrc\n", RTThreadGetName(pSessIt->Thread), rc2);2064 VGSvcError("Closing session thread '%s' failed with rc=%Rrc\n", RTThreadGetName(pSessIt->Thread), rc2); 2182 2065 if (RT_SUCCESS(rc)) 2183 2066 rc = rc2; … … 2186 2069 } 2187 2070 2188 VBoxServiceVerbose(4, "Destroying guest session threads ended with %Rrc\n", rc); 2189 return rc; 2190 } 2191 2192 RTEXITCODE VBoxServiceControlSessionSpawnInit(int argc, char **argv) 2071 VGSvcVerbose(4, "Destroying guest session threads ended with %Rrc\n", rc); 2072 return rc; 2073 } 2074 2075 2076 /** 2077 * Main function for the session process. 2078 * 2079 * @returns exit code. 2080 * @param argc Argument count. 2081 * @param argv Argument vector (UTF-8). 2082 */ 2083 RTEXITCODE VGSvcGstCtrlSessionSpawnInit(int argc, char **argv) 2193 2084 { 2194 2085 static const RTGETOPTDEF s_aOptions[] = … … 2215 2106 1 /*iFirst*/, RTGETOPTINIT_FLAGS_OPTS_FIRST); 2216 2107 2217 uint32_t uSessionFlags= VBOXSERVICECTRLSESSION_FLAG_SPAWN;2108 uint32_t fSession = VBOXSERVICECTRLSESSION_FLAG_SPAWN; 2218 2109 2219 2110 /* Protocol and session ID must be specified explicitly. */ … … 2235 2126 #ifdef DEBUG 2236 2127 case VBOXSERVICESESSIONOPT_DUMP_STDOUT: 2237 uSessionFlags|= VBOXSERVICECTRLSESSION_FLAG_DUMPSTDOUT;2128 fSession |= VBOXSERVICECTRLSESSION_FLAG_DUMPSTDOUT; 2238 2129 break; 2239 2130 2240 2131 case VBOXSERVICESESSIONOPT_DUMP_STDERR: 2241 uSessionFlags|= VBOXSERVICECTRLSESSION_FLAG_DUMPSTDERR;2132 fSession |= VBOXSERVICECTRLSESSION_FLAG_DUMPSTDERR; 2242 2133 break; 2243 2134 #endif … … 2283 2174 2284 2175 /* Init the session object. */ 2285 int rc = GstCntlSessionInit(&g_Session, uSessionFlags);2176 int rc = VGSvcGstCtrlSessionInit(&g_Session, fSession); 2286 2177 if (RT_FAILURE(rc)) 2287 2178 return RTMsgErrorExit(RTEXITCODE_INIT, "Failed to initialize session object, rc=%Rrc\n", rc); 2288 2179 2289 rc = V BoxServiceLogCreate(g_szLogFile[0] ? g_szLogFile : NULL);2180 rc = VGSvcLogCreate(g_szLogFile[0] ? g_szLogFile : NULL); 2290 2181 if (RT_FAILURE(rc)) 2291 return RTMsgErrorExit(RTEXITCODE_INIT, "Failed to create log file \"%s\", rc=%Rrc\n",2182 return RTMsgErrorExit(RTEXITCODE_INIT, "Failed to create log file '%s', rc=%Rrc\n", 2292 2183 g_szLogFile[0] ? g_szLogFile : "<None>", rc); 2293 2184 2294 RTEXITCODE rcExit = gstcntlSessionSpawnWorker(&g_Session);2295 2296 V BoxServiceLogDestroy();2185 RTEXITCODE rcExit = vgsvcGstCtrlSessionSpawnWorker(&g_Session); 2186 2187 VGSvcLogDestroy(); 2297 2188 return rcExit; 2298 2189 } -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceCpuHotPlug.cpp
r57358 r58029 40 40 *********************************************************************************************************************************/ 41 41 #ifdef RT_OS_LINUX 42 42 43 /** @name Paths to access the CPU device 43 44 * @{ … … 76 77 77 78 /** Content of uId if the path wasn't probed yet. */ 78 #define ACPI_CPU_PATH_NOT_PROBED UINT32_MAX 79 79 # define ACPI_CPU_PATH_NOT_PROBED UINT32_MAX 80 #endif /* RT_OS_LINUX*/ 81 82 83 /********************************************************************************************************************************* 84 * Global Variables * 85 *********************************************************************************************************************************/ 86 #ifdef RT_OS_LINUX 80 87 /** Possible combinations of all path components for level 1. */ 81 const SYSFSCPUPATHCOMP g_aAcpiCpuPathLvl1[] =88 static const SYSFSCPUPATHCOMP g_aAcpiCpuPathLvl1[] = 82 89 { 83 90 /** LNXSYSTEM:<id> */ 84 { true, "LNXSYSTM:*"}91 { true, "LNXSYSTM:*" } 85 92 }; 86 93 87 94 /** Possible combinations of all path components for level 2. */ 88 const SYSFSCPUPATHCOMP g_aAcpiCpuPathLvl2[] =95 static const SYSFSCPUPATHCOMP g_aAcpiCpuPathLvl2[] = 89 96 { 90 97 /** device:<id> */ … … 95 102 96 103 /** Possible combinations of all path components for level 3 */ 97 const SYSFSCPUPATHCOMP g_aAcpiCpuPathLvl3[] =104 static const SYSFSCPUPATHCOMP g_aAcpiCpuPathLvl3[] = 98 105 { 99 106 /** ACPI0004:<id> */ … … 102 109 103 110 /** Possible combinations of all path components for level 4 */ 104 const SYSFSCPUPATHCOMP g_aAcpiCpuPathLvl4[] =111 static const SYSFSCPUPATHCOMP g_aAcpiCpuPathLvl4[] = 105 112 { 106 113 /** LNXCPU:<id> */ … … 111 118 112 119 /** All possible combinations. */ 113 SYSFSCPUPATH g_aAcpiCpuPath[] =120 static SYSFSCPUPATH g_aAcpiCpuPath[] = 114 121 { 115 122 /** Level 1 */ … … 129 136 * below and would make the hot unplug code fail. 130 137 */ 131 const char *g_apszTopologyPath[] =138 static const char *g_apszTopologyPath[] = 132 139 { 133 140 "sysdev", 134 141 "physical_node" 135 142 }; 136 #endif 143 144 #endif /* RT_OS_LINUX*/ 145 137 146 138 147 #ifdef RT_OS_LINUX 148 139 149 /** 140 150 * Probes for the correct path to the ACPI CPU object in sysfs for the … … 143 153 * @returns VBox status code. 144 154 */ 145 static int VBoxServiceCpuHotPlugProbePath(void)155 static int vgsvcCpuHotPlugProbePath(void) 146 156 { 147 157 int rc = VINF_SUCCESS; … … 221 231 } /* For every level */ 222 232 223 V BoxServiceVerbose(1, "Final path after probing %s rc=%Rrc\n", pszPath, rc);233 VGSvcVerbose(1, "Final path after probing %s rc=%Rrc\n", pszPath, rc); 224 234 RTStrFree(pszPath); 225 235 } … … 227 237 return rc; 228 238 } 239 229 240 230 241 /** … … 236 247 * @param idCpuPackage The package ID of the CPU. 237 248 */ 238 static int VBoxServiceCpuHotPlugGetACPIDevicePath(char **ppszPath, uint32_t idCpuCore, uint32_t idCpuPackage)249 static int vgsvcCpuHotPlugGetACPIDevicePath(char **ppszPath, uint32_t idCpuCore, uint32_t idCpuPackage) 239 250 { 240 251 int rc = VINF_SUCCESS; … … 242 253 AssertPtrReturn(ppszPath, VERR_INVALID_PARAMETER); 243 254 244 rc = VBoxServiceCpuHotPlugProbePath();255 rc = vgsvcCpuHotPlugProbePath(); 245 256 if (RT_SUCCESS(rc)) 246 257 { … … 316 327 pszPath = pszPathCurr; 317 328 fFound = true; 318 V BoxServiceVerbose(3, "CPU found\n");329 VGSvcVerbose(3, "CPU found\n"); 319 330 break; 320 331 } … … 323 334 /* Get the next directory. */ 324 335 RTStrFree(pszPathCurr); 325 V BoxServiceVerbose(3, "CPU doesn't match, next directory\n");336 VGSvcVerbose(3, "CPU doesn't match, next directory\n"); 326 337 } 327 338 } … … 331 342 iLvlCurr++; 332 343 333 V BoxServiceVerbose(3, "Going deeper (iLvlCurr=%u)\n", iLvlCurr);344 VGSvcVerbose(3, "Going deeper (iLvlCurr=%u)\n", iLvlCurr); 334 345 335 346 pAcpiCpuPathLvl = &g_aAcpiCpuPath[iLvlCurr]; … … 349 360 } 350 361 351 V BoxServiceVerbose(3, "New path %s\n", pszPathDir);362 VGSvcVerbose(3, "New path %s\n", pszPathDir); 352 363 353 364 /* Open the directory */ … … 369 380 iLvlCurr--; 370 381 pAcpiCpuPathLvl = &g_aAcpiCpuPath[iLvlCurr]; 371 V BoxServiceVerbose(3, "Directory not found, going back (iLvlCurr=%u)\n", iLvlCurr);382 VGSvcVerbose(3, "Directory not found, going back (iLvlCurr=%u)\n", iLvlCurr); 372 383 } 373 384 } /* while not found */ … … 395 406 return rc; 396 407 } 408 397 409 #endif /* RT_OS_LINUX */ 398 399 410 400 411 /** … … 404 415 * @param idCpuPackage The CPU package ID. 405 416 */ 406 static void VBoxServiceCpuHotPlugHandlePlugEvent(uint32_t idCpuCore, uint32_t idCpuPackage)417 static void vgsvcCpuHotPlugHandlePlugEvent(uint32_t idCpuCore, uint32_t idCpuPackage) 407 418 { 408 419 #ifdef RT_OS_LINUX … … 413 424 * Because the directory might not be available immediately we try a few times. 414 425 * 415 * @todo: Maybe use udev to monitor hot-add events from the kernel416 426 */ 427 /** @todo Maybe use udev to monitor hot-add events from the kernel */ 417 428 bool fCpuOnline = false; 418 429 unsigned cTries = 5; … … 457 468 if (RT_SUCCESS(rc)) 458 469 { 459 V BoxServiceVerbose(1, "CpuHotPlug: CPU %u/%u was brought online\n", idCpuPackage, idCpuCore);470 VGSvcVerbose(1, "CpuHotPlug: CPU %u/%u was brought online\n", idCpuPackage, idCpuCore); 460 471 fCpuOnline = true; 461 472 break; … … 464 475 } 465 476 else 466 V BoxServiceError("CpuHotPlug: Failed to open \"%s/%s/online\"rc=%Rrc\n",467 477 VGSvcError("CpuHotPlug: Failed to open '%s/%s/online' rc=%Rrc\n", 478 SYSFS_CPU_PATH, DirFolderContent.szName, rc); 468 479 } 469 480 } 470 481 } 471 482 else 472 V BoxServiceError("CpuHotPlug: Failed to open path %s rc=%Rrc\n", SYSFS_CPU_PATH, rc);483 VGSvcError("CpuHotPlug: Failed to open path %s rc=%Rrc\n", SYSFS_CPU_PATH, rc); 473 484 474 485 /* Sleep a bit */ … … 490 501 * @param idCpuPackage The CPU package ID. 491 502 */ 492 static void VBoxServiceCpuHotPlugHandleUnplugEvent(uint32_t idCpuCore, uint32_t idCpuPackage)503 static void vgsvcCpuHotPlugHandleUnplugEvent(uint32_t idCpuCore, uint32_t idCpuPackage) 493 504 { 494 505 #ifdef RT_OS_LINUX 495 506 char *pszCpuDevicePath = NULL; 496 int rc = VBoxServiceCpuHotPlugGetACPIDevicePath(&pszCpuDevicePath, idCpuCore, idCpuPackage);507 int rc = vgsvcCpuHotPlugGetACPIDevicePath(&pszCpuDevicePath, idCpuCore, idCpuPackage); 497 508 if (RT_SUCCESS(rc)) 498 509 { 499 510 RTFILE hFileCpuEject; 500 rc = RTFileOpenF(&hFileCpuEject, RTFILE_O_WRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE, 501 "%s/eject", pszCpuDevicePath); 511 rc = RTFileOpenF(&hFileCpuEject, RTFILE_O_WRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE, "%s/eject", pszCpuDevicePath); 502 512 if (RT_SUCCESS(rc)) 503 513 { … … 505 515 rc = RTFileWrite(hFileCpuEject, "1", 1, NULL); 506 516 if (RT_SUCCESS(rc)) 507 V BoxServiceVerbose(1, "CpuHotPlug: CPU %u/%u was ejected\n", idCpuPackage, idCpuCore);517 VGSvcVerbose(1, "CpuHotPlug: CPU %u/%u was ejected\n", idCpuPackage, idCpuCore); 508 518 else 509 V BoxServiceError("CpuHotPlug: Failed to eject CPU %u/%u rc=%Rrc\n", idCpuPackage, idCpuCore, rc);519 VGSvcError("CpuHotPlug: Failed to eject CPU %u/%u rc=%Rrc\n", idCpuPackage, idCpuCore, rc); 510 520 511 521 RTFileClose(hFileCpuEject); 512 522 } 513 523 else 514 V BoxServiceError("CpuHotPlug: Failed to open \"%s/eject\"rc=%Rrc\n", pszCpuDevicePath, rc);524 VGSvcError("CpuHotPlug: Failed to open '%s/eject' rc=%Rrc\n", pszCpuDevicePath, rc); 515 525 RTStrFree(pszCpuDevicePath); 516 526 } 517 527 else 518 V BoxServiceError("CpuHotPlug: Failed to get CPU device path rc=%Rrc\n", rc);528 VGSvcError("CpuHotPlug: Failed to get CPU device path rc=%Rrc\n", rc); 519 529 #else 520 530 # error "Port me" … … 523 533 524 534 525 /** @ copydoc VBOXSERVICE::pfnWorker*/526 DECLCALLBACK(int) VBoxServiceCpuHotPlugWorker(bool volatile *pfShutdown)535 /** @interface_method_impl{VBOXSERVICE,pfnWorker} */ 536 static DECLCALLBACK(int) vgsvcCpuHotPlugWorker(bool volatile *pfShutdown) 527 537 { 528 538 /* … … 550 560 if (RT_SUCCESS(rc)) 551 561 { 552 V BoxServiceVerbose(3, "CpuHotPlug: Event happened idCpuCore=%u idCpuPackage=%u enmEventType=%d\n",553 562 VGSvcVerbose(3, "CpuHotPlug: Event happened idCpuCore=%u idCpuPackage=%u enmEventType=%d\n", 563 idCpuCore, idCpuPackage, enmEventType); 554 564 switch (enmEventType) 555 565 { 556 566 case VMMDevCpuEventType_Plug: 557 VBoxServiceCpuHotPlugHandlePlugEvent(idCpuCore, idCpuPackage);567 vgsvcCpuHotPlugHandlePlugEvent(idCpuCore, idCpuPackage); 558 568 break; 559 569 560 570 case VMMDevCpuEventType_Unplug: 561 VBoxServiceCpuHotPlugHandleUnplugEvent(idCpuCore, idCpuPackage);571 vgsvcCpuHotPlugHandleUnplugEvent(idCpuCore, idCpuPackage); 562 572 break; 563 573 … … 566 576 static uint32_t s_iErrors = 0; 567 577 if (s_iErrors++ < 10) 568 V BoxServiceError("CpuHotPlug: Unknown event: idCpuCore=%u idCpuPackage=%u enmEventType=%d\n",569 578 VGSvcError("CpuHotPlug: Unknown event: idCpuCore=%u idCpuPackage=%u enmEventType=%d\n", 579 idCpuCore, idCpuPackage, enmEventType); 570 580 break; 571 581 } … … 574 584 else if (rc != VERR_INTERRUPTED && rc != VERR_TRY_AGAIN) 575 585 { 576 V BoxServiceError("CpuHotPlug: VbglR3CpuHotPlugWaitForEvent returned %Rrc\n", rc);586 VGSvcError("CpuHotPlug: VbglR3CpuHotPlugWaitForEvent returned %Rrc\n", rc); 577 587 break; 578 588 } … … 587 597 588 598 589 /** @ copydoc VBOXSERVICE::pfnStop*/590 static DECLCALLBACK(void) VBoxServiceCpuHotPlugStop(void)599 /** @interface_method_impl{VBOXSERVICE,pfnStop} */ 600 static DECLCALLBACK(void) vgsvcCpuHotPlugStop(void) 591 601 { 592 602 VbglR3InterruptEventWaits(); … … 609 619 NULL, 610 620 /* methods */ 611 V BoxServiceDefaultPreInit,612 V BoxServiceDefaultOption,613 V BoxServiceDefaultInit,614 VBoxServiceCpuHotPlugWorker,615 VBoxServiceCpuHotPlugStop,616 V BoxServiceDefaultTerm621 VGSvcDefaultPreInit, 622 VGSvcDefaultOption, 623 VGSvcDefaultInit, 624 vgsvcCpuHotPlugWorker, 625 vgsvcCpuHotPlugStop, 626 VGSvcDefaultTerm 617 627 }; 618 628 -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h
r57966 r58029 96 96 97 97 /* Default call-backs for services which do not need special behaviour. */ 98 DECLCALLBACK(int) VBoxServiceDefaultPreInit(void); 99 DECLCALLBACK(int) VBoxServiceDefaultOption(const char **ppszShort, int argc, 100 char **argv, int *pi); 101 DECLCALLBACK(int) VBoxServiceDefaultInit(void); 102 DECLCALLBACK(void) VBoxServiceDefaultTerm(void); 98 DECLCALLBACK(int) VGSvcDefaultPreInit(void); 99 DECLCALLBACK(int) VGSvcDefaultOption(const char **ppszShort, int argc, char **argv, int *pi); 100 DECLCALLBACK(int) VGSvcDefaultInit(void); 101 DECLCALLBACK(void) VGSvcDefaultTerm(void); 103 102 104 103 /** The service name. … … 181 180 #endif 182 181 183 extern RTEXITCODE VBoxServiceSyntax(const char *pszFormat, ...); 184 extern RTEXITCODE VBoxServiceError(const char *pszFormat, ...); 185 extern void VBoxServiceVerbose(unsigned iLevel, const char *pszFormat, ...); 186 extern int VBoxServiceArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32, 187 uint32_t u32Min, uint32_t u32Max); 188 extern int VBoxServiceStartServices(void); 189 extern int VBoxServiceStopServices(void); 190 extern void VBoxServiceMainWait(void); 191 extern int VBoxServiceReportStatus(VBoxGuestFacilityStatus enmStatus); 192 #ifdef RT_OS_WINDOWS 193 extern RTEXITCODE VBoxServiceWinInstall(void); 194 extern RTEXITCODE VBoxServiceWinUninstall(void); 195 extern RTEXITCODE VBoxServiceWinEnterCtrlDispatcher(void); 196 extern void VBoxServiceWinSetStopPendingStatus(uint32_t uCheckPoint); 182 extern RTEXITCODE VGSvcSyntax(const char *pszFormat, ...); 183 extern RTEXITCODE VGSvcError(const char *pszFormat, ...); 184 extern void VGSvcVerbose(unsigned iLevel, const char *pszFormat, ...); 185 extern int VGSvcLogCreate(const char *pszLogFile); 186 extern void VGSvcLogDestroy(void); 187 extern int VGSvcArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32, 188 uint32_t u32Min, uint32_t u32Max); 189 190 /* Exposing the following bits because of windows: */ 191 extern int VGSvcStartServices(void); 192 extern int VGSvcStopServices(void); 193 extern void VGSvcMainWait(void); 194 extern int VGSvcReportStatus(VBoxGuestFacilityStatus enmStatus); 195 #ifdef RT_OS_WINDOWS 196 extern RTEXITCODE VGSvcWinInstall(void); 197 extern RTEXITCODE VGSvcWinUninstall(void); 198 extern RTEXITCODE VGSvcWinEnterCtrlDispatcher(void); 199 extern void VGSvcWinSetStopPendingStatus(uint32_t uCheckPoint); 197 200 #endif 198 201 199 202 #ifdef VBOXSERVICE_TOOLBOX 200 extern bool V BoxServiceToolboxMain(int argc, char **argv, RTEXITCODE *prcExit);203 extern bool VGSvcToolboxMain(int argc, char **argv, RTEXITCODE *prcExit); 201 204 #endif 202 205 203 206 #ifdef RT_OS_WINDOWS 204 207 # ifdef VBOX_WITH_GUEST_PROPS 205 extern int V BoxServiceVMInfoWinWriteUsers(PVBOXSERVICEVEPROPCACHE pCache, char **ppszUserList, uint32_t *pcUsersInList);206 extern int V BoxServiceWinGetComponentVersions(uint32_t uiClientID);208 extern int VGSvcVMInfoWinWriteUsers(PVBOXSERVICEVEPROPCACHE pCache, char **ppszUserList, uint32_t *pcUsersInList); 209 extern int VGSvcVMInfoWinGetComponentVersions(uint32_t uClientID); 207 210 # endif /* VBOX_WITH_GUEST_PROPS */ 208 211 #endif /* RT_OS_WINDOWS */ 209 212 210 213 #ifdef VBOXSERVICE_MANAGEMENT 211 extern uint32_t V BoxServiceBalloonQueryPages(uint32_t cbPage);214 extern uint32_t VGSvcBalloonQueryPages(uint32_t cbPage); 212 215 #endif 213 216 #if defined(VBOXSERVICE_PAGE_SHARING) 214 extern RTEXITCODE V BoxServicePageSharingWorkerChild(void);215 #endif 216 extern int V BoxServiceVMInfoSignal(void);217 extern RTEXITCODE VGSvcPageSharingWorkerChild(void); 218 #endif 219 extern int VGSvcVMInfoSignal(void); 217 220 218 221 RT_C_DECLS_END -
trunk/src/VBox/Additions/common/VBoxService/VBoxServicePageSharing.cpp
r57358 r58029 38 38 #include "VBoxServiceUtils.h" 39 39 40 #if defined(RT_OS_WINDOWS) && !defined(TARGET_NT4) 41 # include <tlhelp32.h> 42 # include <psapi.h> 43 # include <winternl.h> 44 #endif 45 40 46 41 47 /********************************************************************************************************************************* 42 * Global Variables*48 * Header Files * 43 49 *********************************************************************************************************************************/ 44 45 /** The semaphore we're blocking on. */46 static RTSEMEVENTMULTI g_PageSharingEvent = NIL_RTSEMEVENTMULTI;47 48 #if defined(RT_OS_WINDOWS) && !defined(TARGET_NT4)49 #include <tlhelp32.h>50 #include <psapi.h>51 #include <winternl.h>52 53 50 typedef struct 54 51 { 55 52 AVLPVNODECORE Core; 53 #ifdef RT_OS_WINDOWS 56 54 HMODULE hModule; 57 55 char szFileVersion[16]; 58 56 MODULEENTRY32 Info; 59 } KNOWN_MODULE, *PKNOWN_MODULE; 60 61 #define SystemModuleInformation 11 57 #endif /* RT_OS_WINDOWS */ 58 } VGSVCPGSHKNOWNMOD, *PVGSVCPGSHKNOWNMOD; 59 60 61 #ifdef RT_OS_WINDOWS 62 /* NTDLL API we want to use: */ 63 # define SystemModuleInformation 11 62 64 63 65 typedef struct _RTL_PROCESS_MODULE_INFORMATION … … 82 84 83 85 typedef NTSTATUS (WINAPI *PFNZWQUERYSYSTEMINFORMATION)(ULONG, PVOID, ULONG, PULONG); 86 87 #endif /* RT_OS_WINDOWS */ 88 89 90 /********************************************************************************************************************************* 91 * Global Variables * 92 *********************************************************************************************************************************/ 93 #ifdef RT_OS_WINDOWS 84 94 static PFNZWQUERYSYSTEMINFORMATION g_pfnZwQuerySystemInformation = NULL; 85 86 87 static DECLCALLBACK(int) VBoxServicePageSharingEmptyTreeCallback(PAVLPVNODECORE pNode, void *pvUser); 95 #endif 96 97 /** The semaphore we're blocking on. */ 98 static RTSEMEVENTMULTI g_PageSharingEvent = NIL_RTSEMEVENTMULTI; 88 99 89 100 static PAVLPVNODECORE g_pKnownModuleTree = NULL; 90 101 static uint64_t g_idSession = 0; 102 103 104 /********************************************************************************************************************************* 105 * Internal Functions * 106 *********************************************************************************************************************************/ 107 static DECLCALLBACK(int) vgsvcPageSharingEmptyTreeCallback(PAVLPVNODECORE pNode, void *pvUser); 108 109 110 #if defined(RT_OS_WINDOWS) && !defined(TARGET_NT4) 91 111 92 112 /** … … 95 115 * @param fValidateMemory Validate/touch memory pages or not 96 116 */ 97 void VBoxServicePageSharingRegisterModule(PKNOWN_MODULEpModule, bool fValidateMemory)117 static void vgsvcPageSharingRegisterModule(PVGSVCPGSHKNOWNMOD pModule, bool fValidateMemory) 98 118 { 99 119 VMMDEVSHAREDREGIONDESC aRegions[VMMDEVSHAREDREGIONDESC_MAX]; … … 103 123 BYTE *pVersionInfo; 104 124 105 V BoxServiceVerbose(3, "VBoxServicePageSharingRegisterModule\n");125 VGSvcVerbose(3, "vgsvcPageSharingRegisterModule\n"); 106 126 107 127 cbVersionSize = GetFileVersionInfoSize(pModule->Info.szExePath, &dummy); 108 128 if (!cbVersionSize) 109 129 { 110 V BoxServiceVerbose(3, "VBoxServicePageSharingRegisterModule: GetFileVersionInfoSize failed with %d\n", GetLastError());130 VGSvcVerbose(3, "vgsvcPageSharingRegisterModule: GetFileVersionInfoSize failed with %d\n", GetLastError()); 111 131 return; 112 132 } … … 117 137 if (!GetFileVersionInfo(pModule->Info.szExePath, 0, cbVersionSize, pVersionInfo)) 118 138 { 119 V BoxServiceVerbose(3, "VBoxServicePageSharingRegisterModule: GetFileVersionInfo failed with %d\n", GetLastError());139 VGSvcVerbose(3, "vgsvcPageSharingRegisterModule: GetFileVersionInfo failed with %d\n", GetLastError()); 120 140 goto end; 121 141 } 122 142 123 143 /* Fetch default code page. */ 124 struct LANGANDCODEPAGE { 144 struct LANGANDCODEPAGE 145 { 125 146 WORD wLanguage; 126 147 WORD wCodePage; … … 128 149 129 150 UINT cbTranslate; 130 BOOL ret = VerQueryValue(pVersionInfo, TEXT("\\VarFileInfo\\Translation"), (LPVOID *)&lpTranslate, &cbTranslate);131 if ( !ret132 || 133 { 134 V BoxServiceVerbose(3, "VBoxServicePageSharingRegisterModule: VerQueryValue failed with %d (cb=%d)\n", GetLastError(), cbTranslate);151 BOOL fRet = VerQueryValue(pVersionInfo, TEXT("\\VarFileInfo\\Translation"), (LPVOID *)&lpTranslate, &cbTranslate); 152 if ( !fRet 153 || cbTranslate < 4) 154 { 155 VGSvcVerbose(3, "vgsvcPageSharingRegisterModule: VerQueryValue failed with %d (cb=%d)\n", GetLastError(), cbTranslate); 135 156 goto end; 136 157 } … … 147 168 148 169 sprintf(szFileVersionLocation, TEXT("\\StringFileInfo\\%04x%04x\\FileVersion"), lpTranslate[i].wLanguage, lpTranslate[i].wCodePage); 149 ret = VerQueryValue(pVersionInfo, szFileVersionLocation, (LPVOID *)&lpszFileVersion, &cbFileVersion);150 if ( ret)170 fRet = VerQueryValue(pVersionInfo, szFileVersionLocation, (LPVOID *)&lpszFileVersion, &cbFileVersion); 171 if (fRet) 151 172 break; 152 173 } 153 174 if (i == cTranslationBlocks) 154 175 { 155 V BoxServiceVerbose(3, "VBoxServicePageSharingRegisterModule: no file version found!\n");176 VGSvcVerbose(3, "vgsvcPageSharingRegisterModule: no file version found!\n"); 156 177 goto end; 157 178 } … … 167 188 { 168 189 MEMORY_BASIC_INFORMATION MemInfo; 169 170 SIZE_T ret = VirtualQuery(pBaseAddress, &MemInfo, sizeof(MemInfo)); 171 Assert(ret); 172 if (!ret) 190 SIZE_T cbRet = VirtualQuery(pBaseAddress, &MemInfo, sizeof(MemInfo)); 191 Assert(cbRet); 192 if (!cbRet) 173 193 { 174 V BoxServiceVerbose(3, "VBoxServicePageSharingRegisterModule: VirtualQueryEx failed with %d\n", GetLastError());194 VGSvcVerbose(3, "vgsvcPageSharingRegisterModule: VirtualQueryEx failed with %d\n", GetLastError()); 175 195 break; 176 196 } 177 197 178 if ( 179 && MemInfo.Type== MEM_IMAGE)198 if ( MemInfo.State == MEM_COMMIT 199 && MemInfo.Type == MEM_IMAGE) 180 200 { 181 201 switch (MemInfo.Protect) 182 202 { 183 case PAGE_EXECUTE: 184 case PAGE_EXECUTE_READ: 185 case PAGE_READONLY: 186 { 187 char *pRegion = (char *)MemInfo.BaseAddress; 188 189 /* Skip the first region as it only contains the image file header. */ 190 if (pRegion != (char *)pModule->Info.modBaseAddr) 203 case PAGE_EXECUTE: 204 case PAGE_EXECUTE_READ: 205 case PAGE_READONLY: 191 206 { 192 /* Touch all pages. */ 193 while (pRegion < (char *)MemInfo.BaseAddress + MemInfo.RegionSize) 207 char *pRegion = (char *)MemInfo.BaseAddress; 208 209 /* Skip the first region as it only contains the image file header. */ 210 if (pRegion != (char *)pModule->Info.modBaseAddr) 194 211 { 195 /* Try to trick the optimizer to leave the page touching code in place. */ 196 ASMProbeReadByte(pRegion); 197 pRegion += PAGE_SIZE; 212 /* Touch all pages. */ 213 while ((uintptr_t)pRegion < (uintptr_t)MemInfo.BaseAddress + MemInfo.RegionSize) 214 { 215 /* Try to trick the optimizer to leave the page touching code in place. */ 216 ASMProbeReadByte(pRegion); 217 pRegion += PAGE_SIZE; 218 } 198 219 } 220 #ifdef RT_ARCH_X86 221 aRegions[idxRegion].GCRegionAddr = (RTGCPTR32)MemInfo.BaseAddress; 222 #else 223 aRegions[idxRegion].GCRegionAddr = (RTGCPTR64)MemInfo.BaseAddress; 224 #endif 225 aRegions[idxRegion].cbRegion = MemInfo.RegionSize; 226 idxRegion++; 227 228 break; 199 229 } 200 #ifdef RT_ARCH_X86 201 aRegions[idxRegion].GCRegionAddr = (RTGCPTR32)MemInfo.BaseAddress; 202 #else 203 aRegions[idxRegion].GCRegionAddr = (RTGCPTR64)MemInfo.BaseAddress; 204 #endif 205 aRegions[idxRegion].cbRegion = MemInfo.RegionSize; 206 idxRegion++; 207 208 break; 209 } 210 211 default: 212 break; /* ignore */ 230 231 default: 232 break; /* ignore */ 213 233 } 214 234 } … … 216 236 pBaseAddress = (BYTE *)MemInfo.BaseAddress + MemInfo.RegionSize; 217 237 if (dwModuleSize > MemInfo.RegionSize) 218 {219 238 dwModuleSize -= MemInfo.RegionSize; 220 }221 239 else 222 240 { … … 241 259 idxRegion++; 242 260 } 243 V BoxServiceVerbose(3, "VBoxServicePageSharingRegisterModule: VbglR3RegisterSharedModule %s %s base=%p size=%x cregions=%d\n", pModule->Info.szModule, pModule->szFileVersion, pModule->Info.modBaseAddr, pModule->Info.modBaseSize, idxRegion);261 VGSvcVerbose(3, "vgsvcPageSharingRegisterModule: VbglR3RegisterSharedModule %s %s base=%p size=%x cregions=%d\n", pModule->Info.szModule, pModule->szFileVersion, pModule->Info.modBaseAddr, pModule->Info.modBaseSize, idxRegion); 244 262 int rc = VbglR3RegisterSharedModule(pModule->Info.szModule, pModule->szFileVersion, (uintptr_t)pModule->Info.modBaseAddr, 245 263 pModule->Info.modBaseSize, idxRegion, aRegions); 246 264 if (RT_FAILURE(rc)) 247 V BoxServiceVerbose(3, "VBoxServicePageSharingRegisterModule: VbglR3RegisterSharedModule failed with %Rrc\n", rc);265 VGSvcVerbose(3, "vgsvcPageSharingRegisterModule: VbglR3RegisterSharedModule failed with %Rrc\n", rc); 248 266 249 267 end: … … 252 270 } 253 271 272 254 273 /** 255 274 * Inspect all loaded modules for the specified process 256 275 * @param dwProcessId Process id 257 276 */ 258 void VBoxServicePageSharingInspectModules(DWORD dwProcessId, PAVLPVNODECORE *ppNewTree) 259 { 260 HANDLE hProcess, hSnapshot; 261 277 static void vgsvcPageSharingInspectModules(DWORD dwProcessId, PAVLPVNODECORE *ppNewTree) 278 { 262 279 /* Get a list of all the modules in this process. */ 263 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 264 FALSE /* no child process handle inheritance */, dwProcessId); 280 HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE /* no child process handle inheritance */, dwProcessId); 265 281 if (hProcess == NULL) 266 282 { 267 V BoxServiceVerbose(3, "VBoxServicePageSharingInspectModules: OpenProcess %x failed with %d\n", dwProcessId, GetLastError());283 VGSvcVerbose(3, "vgsvcPageSharingInspectModules: OpenProcess %x failed with %d\n", dwProcessId, GetLastError()); 268 284 return; 269 285 } 270 286 271 hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcessId);287 HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcessId); 272 288 if (hSnapshot == INVALID_HANDLE_VALUE) 273 289 { 274 V BoxServiceVerbose(3, "VBoxServicePageSharingInspectModules: CreateToolhelp32Snapshot failed with %d\n", GetLastError());290 VGSvcVerbose(3, "vgsvcPageSharingInspectModules: CreateToolhelp32Snapshot failed with %d\n", GetLastError()); 275 291 CloseHandle(hProcess); 276 292 return; 277 293 } 278 294 279 V BoxServiceVerbose(3, "VBoxServicePageSharingInspectModules\n");295 VGSvcVerbose(3, "vgsvcPageSharingInspectModules\n"); 280 296 281 297 MODULEENTRY32 ModuleInfo; … … 300 316 { 301 317 /* New module; register it. */ 302 P KNOWN_MODULE pModule = (PKNOWN_MODULE)RTMemAllocZ(sizeof(*pModule));318 PVGSVCPGSHKNOWNMOD pModule = (PVGSVCPGSHKNOWNMOD)RTMemAllocZ(sizeof(*pModule)); 303 319 Assert(pModule); 304 320 if (!pModule) … … 309 325 pModule->hModule = LoadLibraryEx(ModuleInfo.szExePath, 0, DONT_RESOLVE_DLL_REFERENCES); 310 326 if (pModule->hModule) 311 VBoxServicePageSharingRegisterModule(pModule, true /* validate pages */);312 313 V BoxServiceVerbose(3, "\n\n MODULE NAME: %s", ModuleInfo.szModule );314 V BoxServiceVerbose(3, "\n executable = %s", ModuleInfo.szExePath );315 V BoxServiceVerbose(3, "\n process ID = 0x%08X", ModuleInfo.th32ProcessID );316 V BoxServiceVerbose(3, "\n base address = 0x%08X", (DWORD) ModuleInfo.modBaseAddr );317 V BoxServiceVerbose(3, "\n base size = %d", ModuleInfo.modBaseSize );327 vgsvcPageSharingRegisterModule(pModule, true /* validate pages */); 328 329 VGSvcVerbose(3, "\n\n MODULE NAME: %s", ModuleInfo.szModule ); 330 VGSvcVerbose(3, "\n executable = %s", ModuleInfo.szExePath ); 331 VGSvcVerbose(3, "\n process ID = 0x%08X", ModuleInfo.th32ProcessID ); 332 VGSvcVerbose(3, "\n base address = 0x%08X", (DWORD) ModuleInfo.modBaseAddr ); 333 VGSvcVerbose(3, "\n base size = %d", ModuleInfo.modBaseSize ); 318 334 319 335 pRec = &pModule->Core; … … 322 338 Assert(ret); NOREF(ret); 323 339 } 324 } 325 while (Module32Next(hSnapshot, &ModuleInfo)); 340 } while (Module32Next(hSnapshot, &ModuleInfo)); 326 341 327 342 CloseHandle(hSnapshot); 328 343 CloseHandle(hProcess); 329 344 } 345 330 346 331 347 /** … … 334 350 * 335 351 */ 336 static void VBoxServicePageSharingInspectGuest(void)352 static void vgsvcPageSharingInspectGuest(void) 337 353 { 338 354 HANDLE hSnapshot; … … 340 356 DWORD dwProcessId = GetCurrentProcessId(); 341 357 342 V BoxServiceVerbose(3, "VBoxServicePageSharingInspectGuest\n");358 VGSvcVerbose(3, "vgsvcPageSharingInspectGuest\n"); 343 359 344 360 hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 345 361 if (hSnapshot == INVALID_HANDLE_VALUE) 346 362 { 347 V BoxServiceVerbose(3, "VBoxServicePageSharingInspectGuest: CreateToolhelp32Snapshot failed with %d\n", GetLastError());363 VGSvcVerbose(3, "vgsvcPageSharingInspectGuest: CreateToolhelp32Snapshot failed with %d\n", GetLastError()); 348 364 return; 349 365 } … … 359 375 /* Skip our own process. */ 360 376 if (ProcessInfo.th32ProcessID != dwProcessId) 361 VBoxServicePageSharingInspectModules(ProcessInfo.th32ProcessID, &pNewTree);377 vgsvcPageSharingInspectModules(ProcessInfo.th32ProcessID, &pNewTree); 362 378 } 363 379 while (Process32Next(hSnapshot, &ProcessInfo)); … … 375 391 if (!cbBuffer) 376 392 { 377 V BoxServiceVerbose(1, "ZwQuerySystemInformation returned length 0\n");393 VGSvcVerbose(1, "ZwQuerySystemInformation returned length 0\n"); 378 394 goto skipkernelmodules; 379 395 } … … 386 402 if (ret != STATUS_SUCCESS) 387 403 { 388 V BoxServiceVerbose(1, "ZwQuerySystemInformation returned %x (1)\n", ret);404 VGSvcVerbose(1, "ZwQuerySystemInformation returned %x (1)\n", ret); 389 405 goto skipkernelmodules; 390 406 } … … 393 409 for (unsigned i = 0; i < pSystemModules->NumberOfModules; i++) 394 410 { 395 V BoxServiceVerbose(4, "\n\n KERNEL MODULE NAME: %s",pSystemModules->Modules[i].FullPathName[pSystemModules->Modules[i].OffsetToFileName] );396 V BoxServiceVerbose(4, "\n executable = %s",pSystemModules->Modules[i].FullPathName );397 V BoxServiceVerbose(4, "\n flags = 0x%08X\n",pSystemModules->Modules[i].Flags);411 VGSvcVerbose(4, "\n\n KERNEL MODULE NAME: %s", pSystemModules->Modules[i].FullPathName[pSystemModules->Modules[i].OffsetToFileName] ); 412 VGSvcVerbose(4, "\n executable = %s", pSystemModules->Modules[i].FullPathName ); 413 VGSvcVerbose(4, "\n flags = 0x%08X\n", pSystemModules->Modules[i].Flags); 398 414 399 415 /* User-mode modules seem to have no flags set; skip them as we detected them above. */ … … 409 425 { 410 426 /* New module; register it. */ 411 char 412 P KNOWN_MODULE pModule = (PKNOWN_MODULE)RTMemAllocZ(sizeof(*pModule));427 char szFullFilePath[512]; 428 PVGSVCPGSHKNOWNMOD pModule = (PVGSVCPGSHKNOWNMOD)RTMemAllocZ(sizeof(*pModule)); 413 429 Assert(pModule); 414 430 if (!pModule) 415 431 break; 416 432 433 /** @todo Use unicode APIs! */ 417 434 strcpy(pModule->Info.szModule, &pSystemModules->Modules[i].FullPathName[pSystemModules->Modules[i].OffsetToFileName]); 418 435 GetSystemDirectoryA(szFullFilePath, sizeof(szFullFilePath)); … … 425 442 strcat(szFullFilePath, "\\"); 426 443 strcat(szFullFilePath, pSystemModules->Modules[i].FullPathName); 427 V BoxServiceVerbose(3, "Unexpected kernel module name try %s\n", szFullFilePath);444 VGSvcVerbose(3, "Unexpected kernel module name try %s\n", szFullFilePath); 428 445 if (RTFileExists(szFullFilePath) == false) 429 446 { … … 431 448 strcat(szFullFilePath, "\\drivers\\"); 432 449 strcat(szFullFilePath, pSystemModules->Modules[i].FullPathName); 433 V BoxServiceVerbose(3, "Unexpected kernel module name try %s\n", szFullFilePath);450 VGSvcVerbose(3, "Unexpected kernel module name try %s\n", szFullFilePath); 434 451 if (RTFileExists(szFullFilePath) == false) 435 452 { 436 V BoxServiceVerbose(1, "Unexpected kernel module name %s\n", pSystemModules->Modules[i].FullPathName);453 VGSvcVerbose(1, "Unexpected kernel module name %s\n", pSystemModules->Modules[i].FullPathName); 437 454 RTMemFree(pModule); 438 455 continue; … … 445 462 if (!lpPath) 446 463 { 447 V BoxServiceVerbose(1, "Unexpected kernel module name %s (2)\n", pSystemModules->Modules[i].FullPathName);464 VGSvcVerbose(1, "Unexpected kernel module name %s (2)\n", pSystemModules->Modules[i].FullPathName); 448 465 RTMemFree(pModule); 449 466 continue; … … 458 475 459 476 pModule->Core.Key = pSystemModules->Modules[i].ImageBase; 460 VBoxServicePageSharingRegisterModule(pModule, false /* don't check memory pages */);461 462 V BoxServiceVerbose(3, "\n\n KERNEL MODULE NAME: %s", pModule->Info.szModule );463 V BoxServiceVerbose(3, "\n executable = %s", pModule->Info.szExePath );464 V BoxServiceVerbose(3, "\n base address = 0x%08X", (DWORD) pModule->Info.modBaseAddr );465 V BoxServiceVerbose(3, "\n flags = 0x%08X", pSystemModules->Modules[i].Flags);466 V BoxServiceVerbose(3, "\n base size = %d", pModule->Info.modBaseSize );477 vgsvcPageSharingRegisterModule(pModule, false /* don't check memory pages */); 478 479 VGSvcVerbose(3, "\n\n KERNEL MODULE NAME: %s", pModule->Info.szModule ); 480 VGSvcVerbose(3, "\n executable = %s", pModule->Info.szExePath ); 481 VGSvcVerbose(3, "\n base address = 0x%08X", (DWORD) pModule->Info.modBaseAddr ); 482 VGSvcVerbose(3, "\n flags = 0x%08X", pSystemModules->Modules[i].Flags); 483 VGSvcVerbose(3, "\n base size = %d", pModule->Info.modBaseSize ); 467 484 468 485 pRec = &pModule->Core; … … 478 495 479 496 /* Delete leftover modules in the old tree. */ 480 RTAvlPVDestroy(&g_pKnownModuleTree, VBoxServicePageSharingEmptyTreeCallback, NULL);497 RTAvlPVDestroy(&g_pKnownModuleTree, vgsvcPageSharingEmptyTreeCallback, NULL); 481 498 482 499 /* Check all registered modules. */ … … 487 504 } 488 505 506 489 507 /** 490 508 * RTAvlPVDestroy callback. 491 509 */ 492 static DECLCALLBACK(int) VBoxServicePageSharingEmptyTreeCallback(PAVLPVNODECORE pNode, void *pvUser)493 { 494 P KNOWN_MODULE pModule = (PKNOWN_MODULE)pNode;510 static DECLCALLBACK(int) vgsvcPageSharingEmptyTreeCallback(PAVLPVNODECORE pNode, void *pvUser) 511 { 512 PVGSVCPGSHKNOWNMOD pModule = (PVGSVCPGSHKNOWNMOD)pNode; 495 513 bool *pfUnregister = (bool *)pvUser; 496 514 497 V BoxServiceVerbose(3, "VBoxServicePageSharingEmptyTreeCallback %s %s\n", pModule->Info.szModule, pModule->szFileVersion);515 VGSvcVerbose(3, "vgsvcPageSharingEmptyTreeCallback %s %s\n", pModule->Info.szModule, pModule->szFileVersion); 498 516 499 517 /* Dereference module in the hypervisor. */ … … 514 532 515 533 #elif TARGET_NT4 516 static void VBoxServicePageSharingInspectGuest(void) 534 535 static void vgsvcPageSharingInspectGuest(void) 517 536 { 518 537 /* not implemented */ 519 538 } 539 520 540 #else 521 static void VBoxServicePageSharingInspectGuest(void) 541 542 static void vgsvcPageSharingInspectGuest(void) 522 543 { 523 544 /** @todo other platforms */ 524 545 } 546 525 547 #endif 526 548 527 /** @ copydoc VBOXSERVICE::pfnInit*/528 static DECLCALLBACK(int) VBoxServicePageSharingInit(void)529 { 530 V BoxServiceVerbose(3, "VBoxServicePageSharingInit\n");549 /** @interface_method_impl{VBOXSERVICE,pfnInit} */ 550 static DECLCALLBACK(int) vgsvcPageSharingInit(void) 551 { 552 VGSvcVerbose(3, "vgsvcPageSharingInit\n"); 531 553 532 554 int rc = RTSemEventMultiCreate(&g_PageSharingEvent); … … 540 562 { 541 563 if (rc == VERR_IO_GEN_FAILURE) 542 V BoxServiceVerbose(0, "PageSharing: Page sharing support is not available by the host\n");564 VGSvcVerbose(0, "PageSharing: Page sharing support is not available by the host\n"); 543 565 else 544 V BoxServiceError("VBoxServicePageSharingInit: Failed with rc=%Rrc\n", rc);566 VGSvcError("vgsvcPageSharingInit: Failed with rc=%Rrc\n", rc); 545 567 546 568 rc = VERR_SERVICE_DISABLED; … … 555 577 } 556 578 557 /** @copydoc VBOXSERVICE::pfnWorker */ 558 DECLCALLBACK(int) VBoxServicePageSharingWorker(bool volatile *pfShutdown) 579 580 /** 581 * @interface_method_impl{VBOXSERVICE,pfnWorker} 582 */ 583 static DECLCALLBACK(int) vgsvcPageSharingWorker(bool volatile *pfShutdown) 559 584 { 560 585 /* … … 569 594 for (;;) 570 595 { 571 BOOL fEnabled = VbglR3PageSharingIsEnabled(); 572 573 VBoxServiceVerbose(3, "VBoxServicePageSharingWorker: enabled=%d\n", fEnabled); 596 bool fEnabled = VbglR3PageSharingIsEnabled(); 597 VGSvcVerbose(3, "vgsvcPageSharingWorker: enabled=%d\n", fEnabled); 574 598 575 599 if (fEnabled) 576 VBoxServicePageSharingInspectGuest();600 vgsvcPageSharingInspectGuest(); 577 601 578 602 /* … … 589 613 if (rc != VERR_TIMEOUT && RT_FAILURE(rc)) 590 614 { 591 V BoxServiceError("VBoxServicePageSharingWorker: RTSemEventMultiWait failed; rc=%Rrc\n", rc);615 VGSvcError("vgsvcPageSharingWorker: RTSemEventMultiWait failed; rc=%Rrc\n", rc); 592 616 break; 593 617 } … … 601 625 bool fUnregister = false; 602 626 603 V BoxServiceVerbose(3, "VBoxServicePageSharingWorker: VM was restored!!\n");627 VGSvcVerbose(3, "vgsvcPageSharingWorker: VM was restored!!\n"); 604 628 /* The VM was restored, so reregister all modules the next time. */ 605 RTAvlPVDestroy(&g_pKnownModuleTree, VBoxServicePageSharingEmptyTreeCallback, &fUnregister);629 RTAvlPVDestroy(&g_pKnownModuleTree, vgsvcPageSharingEmptyTreeCallback, &fUnregister); 606 630 g_pKnownModuleTree = NULL; 607 631 … … 614 638 g_PageSharingEvent = NIL_RTSEMEVENTMULTI; 615 639 616 V BoxServiceVerbose(3, "VBoxServicePageSharingWorker: finished thread\n");640 VGSvcVerbose(3, "vgsvcPageSharingWorker: finished thread\n"); 617 641 return 0; 618 642 } … … 622 646 /** 623 647 * This gets control when VBoxService is launched with "pagefusion" by 624 * VBoxServicePageSharingWorkerProcess().648 * vgsvcPageSharingWorkerProcess(). 625 649 * 626 650 * @returns RTEXITCODE_SUCCESS. … … 629 653 * via RTProcTerminate(). 630 654 */ 631 RTEXITCODE V BoxServicePageSharingWorkerChild(void)632 { 633 V BoxServiceVerbose(3, "VBoxServicePageSharingInitFork\n");655 RTEXITCODE VGSvcPageSharingWorkerChild(void) 656 { 657 VGSvcVerbose(3, "vgsvcPageSharingInitFork\n"); 634 658 635 659 bool fShutdown = false; 636 VBoxServicePageSharingInit();637 VBoxServicePageSharingWorker(&fShutdown);660 vgsvcPageSharingInit(); 661 vgsvcPageSharingWorker(&fShutdown); 638 662 639 663 return RTEXITCODE_SUCCESS; 640 664 } 641 665 642 /** @copydoc VBOXSERVICE::pfnWorker */ 643 DECLCALLBACK(int) VBoxServicePageSharingWorkerProcess(bool volatile *pfShutdown) 666 667 /** 668 * @interface_method_impl{VBOXSERVICE,pfnWorker} 669 */ 670 static DECLCALLBACK(int) vgsvcPageSharingWorkerProcess(bool volatile *pfShutdown) 644 671 { 645 672 RTPROCESS hProcess = NIL_RTPROCESS; … … 657 684 for (;;) 658 685 { 659 BOOLfEnabled = VbglR3PageSharingIsEnabled();660 V BoxServiceVerbose(3, "VBoxServicePageSharingWorkerProcess: enabled=%d\n", fEnabled);686 bool fEnabled = VbglR3PageSharingIsEnabled(); 687 VGSvcVerbose(3, "vgsvcPageSharingWorkerProcess: enabled=%d\n", fEnabled); 661 688 662 689 /* … … 678 705 rc = RTProcCreate(pszExeName, papszArgs, RTENV_DEFAULT, 0 /* normal child */, &hProcess); 679 706 if (RT_FAILURE(rc)) 680 V BoxServiceError("VBoxServicePageSharingWorkerProcess: RTProcCreate %s failed; rc=%Rrc\n", pszExeName, rc);707 VGSvcError("vgsvcPageSharingWorkerProcess: RTProcCreate %s failed; rc=%Rrc\n", pszExeName, rc); 681 708 } 682 709 } … … 695 722 if (rc != VERR_TIMEOUT && RT_FAILURE(rc)) 696 723 { 697 V BoxServiceError("VBoxServicePageSharingWorkerProcess: RTSemEventMultiWait failed; rc=%Rrc\n", rc);724 VGSvcError("vgsvcPageSharingWorkerProcess: RTSemEventMultiWait failed; rc=%Rrc\n", rc); 698 725 break; 699 726 } … … 706 733 g_PageSharingEvent = NIL_RTSEMEVENTMULTI; 707 734 708 V BoxServiceVerbose(3, "VBoxServicePageSharingWorkerProcess: finished thread\n");735 VGSvcVerbose(3, "vgsvcPageSharingWorkerProcess: finished thread\n"); 709 736 return 0; 710 737 } … … 712 739 #endif /* RT_OS_WINDOWS */ 713 740 714 /** @copydoc VBOXSERVICE::pfnStop */ 715 static DECLCALLBACK(void) VBoxServicePageSharingStop(void) 741 /** 742 * @interface_method_impl{VBOXSERVICE,pfnStop} 743 */ 744 static DECLCALLBACK(void) vgsvcPageSharingStop(void) 716 745 { 717 746 RTSemEventMultiSignal(g_PageSharingEvent); … … 733 762 NULL, 734 763 /* methods */ 735 V BoxServiceDefaultPreInit,736 V BoxServiceDefaultOption,737 VBoxServicePageSharingInit,764 VGSvcDefaultPreInit, 765 VGSvcDefaultOption, 766 vgsvcPageSharingInit, 738 767 #ifdef RT_OS_WINDOWS 739 VBoxServicePageSharingWorkerProcess,768 vgsvcPageSharingWorkerProcess, 740 769 #else 741 VBoxServicePageSharingWorker,770 vgsvcPageSharingWorker, 742 771 #endif 743 VBoxServicePageSharingStop,744 V BoxServiceDefaultTerm772 vgsvcPageSharingStop, 773 VGSvcDefaultTerm 745 774 }; 775 -
trunk/src/VBox/Additions/common/VBoxService/VBoxServicePropCache.cpp
r57358 r58029 31 31 32 32 33 /** Internal functions, not for public use. */34 PVBOXSERVICEVEPROPCACHEENTRY vboxServicePropCacheFindInternal(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, uint32_t uFlags);35 PVBOXSERVICEVEPROPCACHEENTRY vboxServicePropCacheInsertEntryInternal(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName);36 37 33 38 34 /** @todo Docs */ 39 PVBOXSERVICEVEPROPCACHEENTRY vboxServicePropCacheFindInternal(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, uint32_t uFlags) 35 static PVBOXSERVICEVEPROPCACHEENTRY vgsvcPropCacheFindInternal(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, 36 uint32_t fFlags) 40 37 { 41 38 AssertPtrReturn(pCache, NULL); … … 65 62 66 63 /** @todo Docs */ 67 PVBOXSERVICEVEPROPCACHEENTRY vboxServicePropCacheInsertEntryInternal(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName)64 static PVBOXSERVICEVEPROPCACHEENTRY vgsvcPropCacheInsertEntryInternal(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName) 68 65 { 69 66 AssertPtrReturn(pCache, NULL); … … 86 83 if (RT_SUCCESS(rc)) 87 84 { 88 /*rc =*/RTListAppend(&pCache->NodeHead, &pNode->NodeSucc);85 RTListAppend(&pCache->NodeHead, &pNode->NodeSucc); 89 86 rc = RTCritSectLeave(&pCache->CritSect); 90 87 } … … 95 92 96 93 /** @todo Docs */ 97 int vboxServicePropCacheWritePropF(uint32_t u32ClientId, const char *pszName, uint32_t fFlags, const char *pszValueFormat, ...)94 static int vgsvcPropCacheWritePropF(uint32_t u32ClientId, const char *pszName, uint32_t fFlags, const char *pszValueFormat, ...) 98 95 { 99 96 AssertPtrReturn(pszName, VERR_INVALID_POINTER); … … 108 105 if (RTStrAPrintfV(&pszValue, pszValueFormat, va) >= 0) 109 106 { 110 if (fFlags & V BOXSERVICEPROPCACHEFLAG_TRANSIENT)107 if (fFlags & VGSVCPROPCACHE_FLAGS_TRANSIENT) 111 108 { 112 109 /* … … 135 132 } 136 133 else 137 {138 134 rc = VbglR3GuestPropWriteValue(u32ClientId, pszName, NULL); 139 }140 135 return rc; 141 136 } … … 149 144 * @param uClientId The HGCM handle of to the guest property service. 150 145 */ 151 int V BoxServicePropCacheCreate(PVBOXSERVICEVEPROPCACHE pCache, uint32_t uClientId)146 int VGSvcPropCacheCreate(PVBOXSERVICEVEPROPCACHE pCache, uint32_t uClientId) 152 147 { 153 148 AssertPtrReturn(pCache, VERR_INVALID_POINTER); … … 162 157 /** 163 158 * Updates a cache entry without submitting any changes to the host. 159 * 164 160 * This is handy for defining default values/flags. 165 161 * … … 171 167 * @param pszValueReset The property reset value. 172 168 */ 173 int VBoxServicePropCacheUpdateEntry(PVBOXSERVICEVEPROPCACHE pCache, 174 const char *pszName, uint32_t fFlags, const char *pszValueReset) 169 int VGSvcPropCacheUpdateEntry(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, uint32_t fFlags, const char *pszValueReset) 175 170 { 176 171 AssertPtrReturn(pCache, VERR_INVALID_POINTER); 177 172 AssertPtrReturn(pszName, VERR_INVALID_POINTER); 178 PVBOXSERVICEVEPROPCACHEENTRY pNode = v boxServicePropCacheFindInternal(pCache, pszName, 0);173 PVBOXSERVICEVEPROPCACHEENTRY pNode = vgsvcPropCacheFindInternal(pCache, pszName, 0); 179 174 if (pNode == NULL) 180 pNode = v boxServicePropCacheInsertEntryInternal(pCache, pszName);175 pNode = vgsvcPropCacheInsertEntryInternal(pCache, pszName); 181 176 182 177 int rc; … … 214 209 * @param ... Format arguments. 215 210 */ 216 int V BoxServicePropCacheUpdate(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, const char *pszValueFormat, ...)211 int VGSvcPropCacheUpdate(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, const char *pszValueFormat, ...) 217 212 { 218 213 AssertPtrReturn(pCache, VERR_INVALID_POINTER); … … 235 230 } 236 231 237 PVBOXSERVICEVEPROPCACHEENTRY pNode = v boxServicePropCacheFindInternal(pCache, pszName, 0);232 PVBOXSERVICEVEPROPCACHEENTRY pNode = vgsvcPropCacheFindInternal(pCache, pszName, 0); 238 233 239 234 /* Lock the cache. */ … … 242 237 { 243 238 if (pNode == NULL) 244 pNode = v boxServicePropCacheInsertEntryInternal(pCache, pszName);239 pNode = vgsvcPropCacheInsertEntryInternal(pCache, pszName); 245 240 246 241 AssertPtr(pNode); … … 249 244 bool fUpdate = false; 250 245 /* Always update this property, no matter what? */ 251 if (pNode->fFlags & V BOXSERVICEPROPCACHEFLAG_ALWAYS_UPDATE)246 if (pNode->fFlags & VGSVCPROPCACHE_FLAGS_ALWAYS_UPDATE) 252 247 fUpdate = true; 253 248 /* Did the value change so we have to update? */ … … 261 256 { 262 257 /* Write the update. */ 263 rc = v boxServicePropCacheWritePropF(pCache->uClientID, pNode->pszName, pNode->fFlags, pszValue);264 V BoxServiceVerbose(4, "[PropCache %p]: Written \"%s\"=\"%s\"(flags: %x), rc=%Rrc\n",258 rc = vgsvcPropCacheWritePropF(pCache->uClientID, pNode->pszName, pNode->fFlags, pszValue); 259 VGSvcVerbose(4, "[PropCache %p]: Written '%s'='%s' (flags: %x), rc=%Rrc\n", 265 260 pCache, pNode->pszName, pszValue, pNode->fFlags, rc); 266 261 if (RT_SUCCESS(rc)) /* Only update the node's value on successful write. */ … … 280 275 if (pNode->pszValue) /* Did we have a value before? Then the value needs to be deleted. */ 281 276 { 282 rc = v boxServicePropCacheWritePropF(pCache->uClientID, pNode->pszName,277 rc = vgsvcPropCacheWritePropF(pCache->uClientID, pNode->pszName, 283 278 0, /* Flags */ NULL /* Value */); 284 V BoxServiceVerbose(4, "[PropCache %p]: Deleted \"%s\"=\"%s\"(flags: %x), rc=%Rrc\n",279 VGSvcVerbose(4, "[PropCache %p]: Deleted '%s'='%s' (flags: %x), rc=%Rrc\n", 285 280 pCache, pNode->pszName, pNode->pszValue, pNode->fFlags, rc); 286 281 if (RT_SUCCESS(rc)) /* Only delete property value on successful Vbgl deletion. */ … … 299 294 } 300 295 301 VBoxServiceVerbose(4, "[PropCache %p]: Updating \"%s\" resulted in rc=%Rrc\n", 302 pCache, pszName, rc); 296 VGSvcVerbose(4, "[PropCache %p]: Updating '%s' resulted in rc=%Rrc\n", pCache, pszName, rc); 303 297 304 298 /* Delete temp stuff. */ … … 320 314 * @param ... Format arguments. 321 315 */ 322 int VBoxServicePropCacheUpdateByPath(PVBOXSERVICEVEPROPCACHE pCache, const char *pszValue, uint32_t fFlags, const char *pszPathFormat, ...) 316 int VGSvcPropCacheUpdateByPath(PVBOXSERVICEVEPROPCACHE pCache, const char *pszValue, uint32_t fFlags, 317 const char *pszPathFormat, ...) 323 318 { 324 319 AssertPtrReturn(pCache, VERR_INVALID_POINTER); … … 349 344 { 350 345 /** @todo Use some internal function to update the node directly, this is slow atm. */ 351 rc = V BoxServicePropCacheUpdate(pCache, pNodeIt->pszName, pszValue);346 rc = VGSvcPropCacheUpdate(pCache, pNodeIt->pszName, pszValue); 352 347 } 353 348 if (RT_FAILURE(rc)) … … 367 362 * @param pCache The property cache. 368 363 */ 369 int V BoxServicePropCacheFlush(PVBOXSERVICEVEPROPCACHE pCache)364 int VGSvcPropCacheFlush(PVBOXSERVICEVEPROPCACHE pCache) 370 365 { 371 366 AssertPtrReturn(pCache, VERR_INVALID_POINTER); … … 377 372 RTListForEach(&pCache->NodeHead, pNodeIt, VBOXSERVICEVEPROPCACHEENTRY, NodeSucc) 378 373 { 379 rc = vboxServicePropCacheWritePropF(pCache->uClientID, pNodeIt->pszName, 380 pNodeIt->fFlags, pNodeIt->pszValue); 374 rc = vgsvcPropCacheWritePropF(pCache->uClientID, pNodeIt->pszName, pNodeIt->fFlags, pNodeIt->pszValue); 381 375 if (RT_FAILURE(rc)) 382 376 break; … … 393 387 * @param pCache The property cache. 394 388 */ 395 void V BoxServicePropCacheDestroy(PVBOXSERVICEVEPROPCACHE pCache)389 void VGSvcPropCacheDestroy(PVBOXSERVICEVEPROPCACHE pCache) 396 390 { 397 391 AssertPtrReturnVoid(pCache); … … 411 405 RTListNodeRemove(&pNode->NodeSucc); 412 406 413 if (pNode->fFlags & VBOXSERVICEPROPCACHEFLAG_TEMPORARY) 414 { 415 rc = vboxServicePropCacheWritePropF(pCache->uClientID, pNode->pszName, 416 pNode->fFlags, pNode->pszValueReset); 417 } 407 if (pNode->fFlags & VGSVCPROPCACHE_FLAGS_TEMPORARY) 408 rc = vgsvcPropCacheWritePropF(pCache->uClientID, pNode->pszName, pNode->fFlags, pNode->pszValueReset); 418 409 419 410 AssertPtr(pNode->pszName); -
trunk/src/VBox/Additions/common/VBoxService/VBoxServicePropCache.h
r56294 r58029 21 21 #include "VBoxServiceInternal.h" 22 22 23 # 23 #ifdef VBOX_WITH_GUEST_PROPS 24 24 25 /** @name VGSVCPROPCACHE_FLAG_XXX - Guest Property Cache Flags. 26 * @{ */ 25 27 /** Indicates wheter a guest property is temporary and either should 26 28 * - a) get a "reset" value assigned (via VBoxServicePropCacheUpdateEntry) … … 28 30 * - b) get deleted when no reset value is specified. 29 31 */ 30 # define VBOXSERVICEPROPCACHEFLAG_TEMPORARYRT_BIT(1)32 # define VGSVCPROPCACHE_FLAGS_TEMPORARY RT_BIT(1) 31 33 /** Indicates whether a property every time needs to be updated, regardless 32 34 * if its real value changed or not. */ 33 # define VBOXSERVICEPROPCACHEFLAG_ALWAYS_UPDATERT_BIT(2)35 # define VGSVCPROPCACHE_FLAGS_ALWAYS_UPDATE RT_BIT(2) 34 36 /** The guest property gets deleted when 35 37 * - a) the property cache gets destroyed, or 36 38 * - b) the VM gets reset / shutdown / destroyed. 37 39 */ 38 #define VBOXSERVICEPROPCACHEFLAG_TRANSIENT RT_BIT(3) 40 # define VGSVCPROPCACHE_FLAGS_TRANSIENT RT_BIT(3) 41 /** @} */ 39 42 40 int VBoxServicePropCacheCreate(PVBOXSERVICEVEPROPCACHE pCache, uint32_t uClientId); 41 int VBoxServicePropCacheUpdateEntry(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, uint32_t fFlags, const char *pszValueReset); 42 int VBoxServicePropCacheUpdate(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, const char *pszValueFormat, ...); 43 int VBoxServicePropCacheUpdateByPath(PVBOXSERVICEVEPROPCACHE pCache, const char *pszValue, uint32_t fFlags, const char *pszPathFormat, ...); 44 int VBoxServicePropCacheFlush(PVBOXSERVICEVEPROPCACHE pCache); 45 void VBoxServicePropCacheDestroy(PVBOXSERVICEVEPROPCACHE pCache); 46 # endif /* VBOX_WITH_GUEST_PROPS */ 43 int VGSvcPropCacheCreate(PVBOXSERVICEVEPROPCACHE pCache, uint32_t uClientId); 44 int VGSvcPropCacheUpdateEntry(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, uint32_t fFlags, const char *pszValueReset); 45 int VGSvcPropCacheUpdate(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, const char *pszValueFormat, ...); 46 int VGSvcPropCacheUpdateByPath(PVBOXSERVICEVEPROPCACHE pCache, const char *pszValue, uint32_t fFlags, 47 const char *pszPathFormat, ...); 48 int VGSvcPropCacheFlush(PVBOXSERVICEVEPROPCACHE pCache); 49 void VGSvcPropCacheDestroy(PVBOXSERVICEVEPROPCACHE pCache); 50 #endif /* VBOX_WITH_GUEST_PROPS */ 47 51 48 #endif /* ___VBoxServicePropCache_h */52 #endif 49 53 -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceStats.cpp
r57358 r58029 62 62 typedef struct _VBOXSTATSCONTEXT 63 63 { 64 RTMSINTERVAL 65 66 uint64_t 67 uint64_t 68 uint64_t 69 uint64_t 64 RTMSINTERVAL cMsStatInterval; 65 66 uint64_t au64LastCpuLoad_Idle[VMM_MAX_CPU_COUNT]; 67 uint64_t au64LastCpuLoad_Kernel[VMM_MAX_CPU_COUNT]; 68 uint64_t au64LastCpuLoad_User[VMM_MAX_CPU_COUNT]; 69 uint64_t au64LastCpuLoad_Nice[VMM_MAX_CPU_COUNT]; 70 70 71 71 #ifdef RT_OS_WINDOWS 72 NTSTATUS (WINAPI *pfnNtQuerySystemInformation)(SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, ULONG SystemInformationLength, PULONG ReturnLength); 72 NTSTATUS (WINAPI *pfnNtQuerySystemInformation)(SYSTEM_INFORMATION_CLASS SystemInformationClass, PVOID SystemInformation, 73 ULONG SystemInformationLength, PULONG ReturnLength); 73 74 void (WINAPI *pfnGlobalMemoryStatusEx)(LPMEMORYSTATUSEX lpBuffer); 74 75 BOOL (WINAPI *pfnGetPerformanceInfo)(PPERFORMANCE_INFORMATION pPerformanceInformation, DWORD cb); … … 80 81 * Global Variables * 81 82 *********************************************************************************************************************************/ 82 static VBOXSTATSCONTEXT gCtx = {0}; 83 /** Global data. */ 84 static VBOXSTATSCONTEXT g_VMStat = {0}; 83 85 84 86 /** The semaphore we're blocking on. */ … … 86 88 87 89 88 /** @copydoc VBOXSERVICE::pfnInit */ 89 static DECLCALLBACK(int) VBoxServiceVMStatsInit(void) 90 /** 91 * @interface_method_impl{VBOXSERVICE,pfnInit} 92 */ 93 static DECLCALLBACK(int) vgsvcVMStatsInit(void) 90 94 { 91 V BoxServiceVerbose(3, "VBoxServiceVMStatsInit\n");95 VGSvcVerbose(3, "vgsvcVMStatsInit\n"); 92 96 93 97 int rc = RTSemEventMultiCreate(&g_VMStatEvent); 94 98 AssertRCReturn(rc, rc); 95 99 96 g Ctx.cMsStatInterval = 0; /* default; update disabled */97 RT_ZERO(g Ctx.au64LastCpuLoad_Idle);98 RT_ZERO(g Ctx.au64LastCpuLoad_Kernel);99 RT_ZERO(g Ctx.au64LastCpuLoad_User);100 RT_ZERO(g Ctx.au64LastCpuLoad_Nice);101 102 rc = VbglR3StatQueryInterval(&g Ctx.cMsStatInterval);100 g_VMStat.cMsStatInterval = 0; /* default; update disabled */ 101 RT_ZERO(g_VMStat.au64LastCpuLoad_Idle); 102 RT_ZERO(g_VMStat.au64LastCpuLoad_Kernel); 103 RT_ZERO(g_VMStat.au64LastCpuLoad_User); 104 RT_ZERO(g_VMStat.au64LastCpuLoad_Nice); 105 106 rc = VbglR3StatQueryInterval(&g_VMStat.cMsStatInterval); 103 107 if (RT_SUCCESS(rc)) 104 V BoxServiceVerbose(3, "VBoxStatsInit: New statistics interval %u seconds\n", gCtx.cMsStatInterval);108 VGSvcVerbose(3, "vgsvcVMStatsInit: New statistics interval %u seconds\n", g_VMStat.cMsStatInterval); 105 109 else 106 V BoxServiceVerbose(3, "VBoxStatsInit: DeviceIoControl failed with %d\n", rc);110 VGSvcVerbose(3, "vgsvcVMStatsInit: DeviceIoControl failed with %d\n", rc); 107 111 108 112 #ifdef RT_OS_WINDOWS 109 113 /* NtQuerySystemInformation might be dropped in future releases, so load 110 114 it dynamically as per Microsoft's recommendation. */ 111 *(void **)&g Ctx.pfnNtQuerySystemInformation = RTLdrGetSystemSymbol("ntdll.dll", "NtQuerySystemInformation");112 if (g Ctx.pfnNtQuerySystemInformation)113 V BoxServiceVerbose(3, "VBoxStatsInit: gCtx.pfnNtQuerySystemInformation = %x\n", gCtx.pfnNtQuerySystemInformation);115 *(void **)&g_VMStat.pfnNtQuerySystemInformation = RTLdrGetSystemSymbol("ntdll.dll", "NtQuerySystemInformation"); 116 if (g_VMStat.pfnNtQuerySystemInformation) 117 VGSvcVerbose(3, "vgsvcVMStatsInit: g_VMStat.pfnNtQuerySystemInformation = %x\n", g_VMStat.pfnNtQuerySystemInformation); 114 118 else 115 119 { 116 V BoxServiceVerbose(3, "VBoxStatsInit: ntdll.NtQuerySystemInformation not found!\n");120 VGSvcVerbose(3, "vgsvcVMStatsInit: ntdll.NtQuerySystemInformation not found!\n"); 117 121 return VERR_SERVICE_DISABLED; 118 122 } 119 123 120 124 /* GlobalMemoryStatus is win2k and up, so load it dynamically */ 121 *(void **)&g Ctx.pfnGlobalMemoryStatusEx = RTLdrGetSystemSymbol("kernel32.dll", "GlobalMemoryStatusEx");122 if (g Ctx.pfnGlobalMemoryStatusEx)123 V BoxServiceVerbose(3, "VBoxStatsInit: gCtx.GlobalMemoryStatusEx = %x\n", gCtx.pfnGlobalMemoryStatusEx);125 *(void **)&g_VMStat.pfnGlobalMemoryStatusEx = RTLdrGetSystemSymbol("kernel32.dll", "GlobalMemoryStatusEx"); 126 if (g_VMStat.pfnGlobalMemoryStatusEx) 127 VGSvcVerbose(3, "vgsvcVMStatsInit: g_VMStat.GlobalMemoryStatusEx = %x\n", g_VMStat.pfnGlobalMemoryStatusEx); 124 128 else 125 129 { 126 130 /** @todo Now fails in NT4; do we care? */ 127 V BoxServiceVerbose(3, "VBoxStatsInit: kernel32.GlobalMemoryStatusEx not found!\n");131 VGSvcVerbose(3, "vgsvcVMStatsInit: kernel32.GlobalMemoryStatusEx not found!\n"); 128 132 return VERR_SERVICE_DISABLED; 129 133 } 130 134 131 135 /* GetPerformanceInfo is xp and up, so load it dynamically */ 132 *(void **)&g Ctx.pfnGetPerformanceInfo = RTLdrGetSystemSymbol("psapi.dll", "GetPerformanceInfo");133 if (g Ctx.pfnGetPerformanceInfo)134 V BoxServiceVerbose(3, "VBoxStatsInit: gCtx.pfnGetPerformanceInfo= %x\n", gCtx.pfnGetPerformanceInfo);136 *(void **)&g_VMStat.pfnGetPerformanceInfo = RTLdrGetSystemSymbol("psapi.dll", "GetPerformanceInfo"); 137 if (g_VMStat.pfnGetPerformanceInfo) 138 VGSvcVerbose(3, "vgsvcVMStatsInit: g_VMStat.pfnGetPerformanceInfo= %x\n", g_VMStat.pfnGetPerformanceInfo); 135 139 #endif /* RT_OS_WINDOWS */ 136 140 … … 142 146 * Gathers VM statistics and reports them to the host. 143 147 */ 144 static void VBoxServiceVMStatsReport(void)148 static void vgsvcVMStatsReport(void) 145 149 { 146 150 #if defined(RT_OS_WINDOWS) 147 SYSTEM_INFO systemInfo; 148 PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION pProcInfo; 149 MEMORYSTATUSEX memStatus; 150 uint32_t cbStruct; 151 DWORD cbReturned; 152 153 Assert(gCtx.pfnGlobalMemoryStatusEx && gCtx.pfnNtQuerySystemInformation); 154 if ( !gCtx.pfnGlobalMemoryStatusEx 155 || !gCtx.pfnNtQuerySystemInformation) 151 Assert(g_VMStat.pfnGlobalMemoryStatusEx && g_VMStat.pfnNtQuerySystemInformation); 152 if ( !g_VMStat.pfnGlobalMemoryStatusEx 153 || !g_VMStat.pfnNtQuerySystemInformation) 156 154 return; 157 155 … … 162 160 163 161 /* Query and report guest statistics */ 162 SYSTEM_INFO systemInfo; 164 163 GetSystemInfo(&systemInfo); 165 164 165 MEMORYSTATUSEX memStatus; 166 166 memStatus.dwLength = sizeof(memStatus); 167 g Ctx.pfnGlobalMemoryStatusEx(&memStatus);167 g_VMStat.pfnGlobalMemoryStatusEx(&memStatus); 168 168 169 169 req.guestStats.u32PageSize = systemInfo.dwPageSize; … … 178 178 | VBOX_GUEST_STAT_PAGE_FILE_SIZE 179 179 | VBOX_GUEST_STAT_MEMORY_LOAD; 180 # ifdef VBOX_WITH_MEMBALLOON181 req.guestStats.u32PhysMemBalloon = V BoxServiceBalloonQueryPages(_4K);180 # ifdef VBOX_WITH_MEMBALLOON 181 req.guestStats.u32PhysMemBalloon = VGSvcBalloonQueryPages(_4K); 182 182 req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_PHYS_MEM_BALLOON; 183 # else183 # else 184 184 req.guestStats.u32PhysMemBalloon = 0; 185 # endif186 187 if (g Ctx.pfnGetPerformanceInfo)185 # endif 186 187 if (g_VMStat.pfnGetPerformanceInfo) 188 188 { 189 189 PERFORMANCE_INFORMATION perfInfo; 190 190 191 if (g Ctx.pfnGetPerformanceInfo(&perfInfo, sizeof(perfInfo)))191 if (g_VMStat.pfnGetPerformanceInfo(&perfInfo, sizeof(perfInfo))) 192 192 { 193 193 req.guestStats.u32Processes = perfInfo.ProcessCount; … … 200 200 req.guestStats.u32MemSystemCache = perfInfo.SystemCache; /* already in pages */ 201 201 req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_PROCESSES | VBOX_GUEST_STAT_THREADS | VBOX_GUEST_STAT_HANDLES 202 |VBOX_GUEST_STAT_MEM_COMMIT_TOTAL | VBOX_GUEST_STAT_MEM_KERNEL_TOTAL203 |VBOX_GUEST_STAT_MEM_KERNEL_PAGED | VBOX_GUEST_STAT_MEM_KERNEL_NONPAGED204 |VBOX_GUEST_STAT_MEM_SYSTEM_CACHE;202 | VBOX_GUEST_STAT_MEM_COMMIT_TOTAL | VBOX_GUEST_STAT_MEM_KERNEL_TOTAL 203 | VBOX_GUEST_STAT_MEM_KERNEL_PAGED | VBOX_GUEST_STAT_MEM_KERNEL_NONPAGED 204 | VBOX_GUEST_STAT_MEM_SYSTEM_CACHE; 205 205 } 206 206 else 207 V BoxServiceVerbose(3, "VBoxServiceVMStatsReport: GetPerformanceInfo failed with %d\n", GetLastError());207 VGSvcVerbose(3, "vgsvcVMStatsReport: GetPerformanceInfo failed with %d\n", GetLastError()); 208 208 } 209 209 210 210 /* Query CPU load information */ 211 cbStruct = systemInfo.dwNumberOfProcessors * sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION); 211 uint32_t cbStruct = systemInfo.dwNumberOfProcessors * sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION); 212 PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION pProcInfo; 212 213 pProcInfo = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)RTMemAlloc(cbStruct); 213 214 if (!pProcInfo) … … 215 216 216 217 /* Unfortunately GetSystemTimes is XP SP1 and up only, so we need to use the semi-undocumented NtQuerySystemInformation */ 217 bool fCpuInfoAvail = false; 218 NTSTATUS rc = gCtx.pfnNtQuerySystemInformation(SystemProcessorPerformanceInformation, pProcInfo, cbStruct, &cbReturned); 218 bool fCpuInfoAvail = false; 219 DWORD cbReturned; 220 NTSTATUS rc = g_VMStat.pfnNtQuerySystemInformation(SystemProcessorPerformanceInformation, pProcInfo, cbStruct, &cbReturned); 219 221 if ( !rc 220 222 && cbReturned == cbStruct) … … 224 226 if (i >= VMM_MAX_CPU_COUNT) 225 227 { 226 V BoxServiceVerbose(3, "VBoxStatsReportStatistics: skipping information for CPU%u\n", i);227 continue;228 } 229 230 if (g Ctx.au64LastCpuLoad_Kernel[i] == 0)228 VGSvcVerbose(3, "vgsvcVMStatsReport: skipping information for CPUs %u..%u\n", i, systemInfo.dwNumberOfProcessors); 229 break; 230 } 231 232 if (g_VMStat.au64LastCpuLoad_Kernel[i] == 0) 231 233 { 232 234 /* first time */ 233 g Ctx.au64LastCpuLoad_Idle[i] = pProcInfo[i].IdleTime.QuadPart;234 g Ctx.au64LastCpuLoad_Kernel[i] = pProcInfo[i].KernelTime.QuadPart;235 g Ctx.au64LastCpuLoad_User[i] = pProcInfo[i].UserTime.QuadPart;235 g_VMStat.au64LastCpuLoad_Idle[i] = pProcInfo[i].IdleTime.QuadPart; 236 g_VMStat.au64LastCpuLoad_Kernel[i] = pProcInfo[i].KernelTime.QuadPart; 237 g_VMStat.au64LastCpuLoad_User[i] = pProcInfo[i].UserTime.QuadPart; 236 238 237 239 Sleep(250); 238 240 239 rc = g Ctx.pfnNtQuerySystemInformation(SystemProcessorPerformanceInformation, pProcInfo, cbStruct, &cbReturned);241 rc = g_VMStat.pfnNtQuerySystemInformation(SystemProcessorPerformanceInformation, pProcInfo, cbStruct, &cbReturned); 240 242 Assert(!rc); 241 243 } 242 244 243 uint64_t deltaIdle = (pProcInfo[i].IdleTime.QuadPart - g Ctx.au64LastCpuLoad_Idle[i]);244 uint64_t deltaKernel = (pProcInfo[i].KernelTime.QuadPart - g Ctx.au64LastCpuLoad_Kernel[i]);245 uint64_t deltaUser = (pProcInfo[i].UserTime.QuadPart - g Ctx.au64LastCpuLoad_User[i]);245 uint64_t deltaIdle = (pProcInfo[i].IdleTime.QuadPart - g_VMStat.au64LastCpuLoad_Idle[i]); 246 uint64_t deltaKernel = (pProcInfo[i].KernelTime.QuadPart - g_VMStat.au64LastCpuLoad_Kernel[i]); 247 uint64_t deltaUser = (pProcInfo[i].UserTime.QuadPart - g_VMStat.au64LastCpuLoad_User[i]); 246 248 deltaKernel -= deltaIdle; /* idle time is added to kernel time */ 247 249 uint64_t ullTotalTime = deltaIdle + deltaKernel + deltaUser; … … 249 251 ullTotalTime = 1; 250 252 251 req.guestStats.u32CpuLoad_Idle = (uint32_t)(deltaIdle * 100 / ullTotalTime); 252 req.guestStats.u32CpuLoad_Kernel = (uint32_t)(deltaKernel* 100 / ullTotalTime); 253 req.guestStats.u32CpuLoad_User = (uint32_t)(deltaUser * 100 / ullTotalTime); 254 255 req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_CPU_LOAD_IDLE | VBOX_GUEST_STAT_CPU_LOAD_KERNEL | VBOX_GUEST_STAT_CPU_LOAD_USER; 256 req.guestStats.u32CpuId = i; 253 req.guestStats.u32CpuLoad_Idle = (uint32_t)(deltaIdle * 100 / ullTotalTime); 254 req.guestStats.u32CpuLoad_Kernel = (uint32_t)(deltaKernel* 100 / ullTotalTime); 255 req.guestStats.u32CpuLoad_User = (uint32_t)(deltaUser * 100 / ullTotalTime); 256 257 req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_CPU_LOAD_IDLE | VBOX_GUEST_STAT_CPU_LOAD_KERNEL 258 | VBOX_GUEST_STAT_CPU_LOAD_USER; 259 req.guestStats.u32CpuId = i; 257 260 rc = VbglR3StatReport(&req); 258 261 if (RT_SUCCESS(rc)) 259 V BoxServiceVerbose(3, "VBoxStatsReportStatistics: new statistics (CPU %u) reported successfully!\n", i);262 VGSvcVerbose(3, "vgsvcVMStatsReport: new statistics (CPU %u) reported successfully!\n", i); 260 263 else 261 V BoxServiceVerbose(3, "VBoxStatsReportStatistics: DeviceIoControl (stats report) failed with %d\n", GetLastError());262 263 g Ctx.au64LastCpuLoad_Idle[i]= pProcInfo[i].IdleTime.QuadPart;264 g Ctx.au64LastCpuLoad_Kernel[i]= pProcInfo[i].KernelTime.QuadPart;265 g Ctx.au64LastCpuLoad_User[i]= pProcInfo[i].UserTime.QuadPart;264 VGSvcVerbose(3, "vgsvcVMStatsReport: VbglR3StatReport failed with rc=%Rrc\n", rc); 265 266 g_VMStat.au64LastCpuLoad_Idle[i] = pProcInfo[i].IdleTime.QuadPart; 267 g_VMStat.au64LastCpuLoad_Kernel[i] = pProcInfo[i].KernelTime.QuadPart; 268 g_VMStat.au64LastCpuLoad_User[i] = pProcInfo[i].UserTime.QuadPart; 266 269 } 267 270 } … … 270 273 if (!fCpuInfoAvail) 271 274 { 272 V BoxServiceVerbose(3, "VBoxStatsReportStatistics: CPU info not available!\n");275 VGSvcVerbose(3, "vgsvcVMStatsReport: CPU info not available!\n"); 273 276 rc = VbglR3StatReport(&req); 274 277 if (RT_SUCCESS(rc)) 275 V BoxServiceVerbose(3, "VBoxStatsReportStatistics: new statistics reported successfully!\n");278 VGSvcVerbose(3, "vgsvcVMStatsReport: new statistics reported successfully!\n"); 276 279 else 277 V BoxServiceVerbose(3, "VBoxStatsReportStatistics: stats report failed with rc=%Rrc\n", rc);280 VGSvcVerbose(3, "vgsvcVMStatsReport: stats report failed with rc=%Rrc\n", rc); 278 281 } 279 282 … … 333 336 } 334 337 else 335 V BoxServiceVerbose(3, "VBoxStatsReportStatistics: memory info not available!\n");338 VGSvcVerbose(3, "vgsvcVMStatsReport: memory info not available!\n"); 336 339 337 340 req.guestStats.u32PageSize = getpagesize(); … … 340 343 | VBOX_GUEST_STAT_MEM_SYSTEM_CACHE 341 344 | VBOX_GUEST_STAT_PAGE_FILE_SIZE; 342 # ifdef VBOX_WITH_MEMBALLOON343 req.guestStats.u32PhysMemBalloon = V BoxServiceBalloonQueryPages(_4K);345 # ifdef VBOX_WITH_MEMBALLOON 346 req.guestStats.u32PhysMemBalloon = VGSvcBalloonQueryPages(_4K); 344 347 req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_PHYS_MEM_BALLOON; 345 # else348 # else 346 349 req.guestStats.u32PhysMemBalloon = 0; 347 # endif350 # endif 348 351 349 352 … … 390 393 rc = RTStrToUInt64Ex(RTStrStripL(psz), &psz, 0, &u64Idle); 391 394 392 uint64_t u64DeltaIdle = u64Idle - g Ctx.au64LastCpuLoad_Idle[u32CpuId];393 uint64_t u64DeltaSystem = u64System - g Ctx.au64LastCpuLoad_Kernel[u32CpuId];394 uint64_t u64DeltaUser = u64User - g Ctx.au64LastCpuLoad_User[u32CpuId];395 uint64_t u64DeltaNice = u64Nice - g Ctx.au64LastCpuLoad_Nice[u32CpuId];395 uint64_t u64DeltaIdle = u64Idle - g_VMStat.au64LastCpuLoad_Idle[u32CpuId]; 396 uint64_t u64DeltaSystem = u64System - g_VMStat.au64LastCpuLoad_Kernel[u32CpuId]; 397 uint64_t u64DeltaUser = u64User - g_VMStat.au64LastCpuLoad_User[u32CpuId]; 398 uint64_t u64DeltaNice = u64Nice - g_VMStat.au64LastCpuLoad_Nice[u32CpuId]; 396 399 397 400 uint64_t u64DeltaAll = u64DeltaIdle … … 402 405 u64DeltaAll = 1; 403 406 404 g Ctx.au64LastCpuLoad_Idle[u32CpuId] = u64Idle;405 g Ctx.au64LastCpuLoad_Kernel[u32CpuId] = u64System;406 g Ctx.au64LastCpuLoad_User[u32CpuId] = u64User;407 g Ctx.au64LastCpuLoad_Nice[u32CpuId] = u64Nice;407 g_VMStat.au64LastCpuLoad_Idle[u32CpuId] = u64Idle; 408 g_VMStat.au64LastCpuLoad_Kernel[u32CpuId] = u64System; 409 g_VMStat.au64LastCpuLoad_User[u32CpuId] = u64User; 410 g_VMStat.au64LastCpuLoad_Nice[u32CpuId] = u64Nice; 408 411 409 412 req.guestStats.u32CpuId = u32CpuId; … … 418 421 rc = VbglR3StatReport(&req); 419 422 if (RT_SUCCESS(rc)) 420 V BoxServiceVerbose(3, "VBoxStatsReportStatistics: new statistics (CPU %u) reported successfully!\n", u32CpuId);423 VGSvcVerbose(3, "vgsvcVMStatsReport: new statistics (CPU %u) reported successfully!\n", u32CpuId); 421 424 else 422 V BoxServiceVerbose(3, "VBoxStatsReportStatistics: stats report failed with rc=%Rrc\n", rc);425 VGSvcVerbose(3, "vgsvcVMStatsReport: stats report failed with rc=%Rrc\n", rc); 423 426 } 424 427 else 425 V BoxServiceVerbose(3, "VBoxStatsReportStatistics: skipping information for CPU%u\n", u32CpuId);428 VGSvcVerbose(3, "vgsvcVMStatsReport: skipping information for CPU%u\n", u32CpuId); 426 429 } 427 430 } … … 430 433 if (!fCpuInfoAvail) 431 434 { 432 V BoxServiceVerbose(3, "VBoxStatsReportStatistics: CPU info not available!\n");435 VGSvcVerbose(3, "vgsvcVMStatsReport: CPU info not available!\n"); 433 436 rc = VbglR3StatReport(&req); 434 437 if (RT_SUCCESS(rc)) 435 V BoxServiceVerbose(3, "VBoxStatsReportStatistics: new statistics reported successfully!\n");438 VGSvcVerbose(3, "vgsvcVMStatsReport: new statistics reported successfully!\n"); 436 439 else 437 V BoxServiceVerbose(3, "VBoxStatsReportStatistics: stats report failed with rc=%Rrc\n", rc);440 VGSvcVerbose(3, "vgsvcVMStatsReport: stats report failed with rc=%Rrc\n", rc); 438 441 } 439 442 … … 522 525 | VBOX_GUEST_STAT_PAGE_FILE_SIZE; 523 526 #ifdef VBOX_WITH_MEMBALLOON 524 req.guestStats.u32PhysMemBalloon = V BoxServiceBalloonQueryPages(_4K);527 req.guestStats.u32PhysMemBalloon = VGSvcBalloonQueryPages(_4K); 525 528 req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_PHYS_MEM_BALLOON; 526 529 #else … … 544 547 break; 545 548 546 if (cCPUs >= VMM_MAX_CPU_COUNT) 547 VBoxServiceVerbose(3, "VBoxStatsReportStatistics: skipping information for CPU%u\n", cCPUs); 548 else 549 if (cCPUs < VMM_MAX_CPU_COUNT) 549 550 { 550 551 uint64_t u64Idle = StatCPU.cpu_sysinfo.cpu[CPU_IDLE]; … … 552 553 uint64_t u64System = StatCPU.cpu_sysinfo.cpu[CPU_KERNEL]; 553 554 554 uint64_t u64DeltaIdle = u64Idle - g Ctx.au64LastCpuLoad_Idle[cCPUs];555 uint64_t u64DeltaSystem = u64System - g Ctx.au64LastCpuLoad_Kernel[cCPUs];556 uint64_t u64DeltaUser = u64User - g Ctx.au64LastCpuLoad_User[cCPUs];555 uint64_t u64DeltaIdle = u64Idle - g_VMStat.au64LastCpuLoad_Idle[cCPUs]; 556 uint64_t u64DeltaSystem = u64System - g_VMStat.au64LastCpuLoad_Kernel[cCPUs]; 557 uint64_t u64DeltaUser = u64User - g_VMStat.au64LastCpuLoad_User[cCPUs]; 557 558 558 559 uint64_t u64DeltaAll = u64DeltaIdle + u64DeltaSystem + u64DeltaUser; … … 560 561 u64DeltaAll = 1; 561 562 562 g Ctx.au64LastCpuLoad_Idle[cCPUs] = u64Idle;563 g Ctx.au64LastCpuLoad_Kernel[cCPUs] = u64System;564 g Ctx.au64LastCpuLoad_User[cCPUs] = u64User;563 g_VMStat.au64LastCpuLoad_Idle[cCPUs] = u64Idle; 564 g_VMStat.au64LastCpuLoad_Kernel[cCPUs] = u64System; 565 g_VMStat.au64LastCpuLoad_User[cCPUs] = u64User; 565 566 566 567 req.guestStats.u32CpuId = cCPUs; … … 576 577 rc = VbglR3StatReport(&req); 577 578 if (RT_SUCCESS(rc)) 578 V BoxServiceVerbose(3, "VBoxStatsReportStatistics: new statistics (CPU %u) reported successfully!\n", cCPUs);579 VGSvcVerbose(3, "vgsvcVMStatsReport: new statistics (CPU %u) reported successfully!\n", cCPUs); 579 580 else 580 V BoxServiceVerbose(3, "VBoxStatsReportStatistics: stats report failed with rc=%Rrc\n", rc);581 VGSvcVerbose(3, "vgsvcVMStatsReport: stats report failed with rc=%Rrc\n", rc); 581 582 cCPUs++; 582 583 } 584 else 585 VGSvcVerbose(3, "vgsvcVMStatsReport: skipping information for CPU%u\n", cCPUs); 583 586 } 584 587 } … … 589 592 if (!fCpuInfoAvail) 590 593 { 591 V BoxServiceVerbose(3, "VBoxStatsReportStatistics: CPU info not available!\n");594 VGSvcVerbose(3, "vgsvcVMStatsReport: CPU info not available!\n"); 592 595 rc = VbglR3StatReport(&req); 593 596 if (RT_SUCCESS(rc)) 594 V BoxServiceVerbose(3, "VBoxStatsReportStatistics: new statistics reported successfully!\n");597 VGSvcVerbose(3, "vgsvcVMStatsReport: new statistics reported successfully!\n"); 595 598 else 596 V BoxServiceVerbose(3, "VBoxStatsReportStatistics: stats report failed with rc=%Rrc\n", rc);599 VGSvcVerbose(3, "vgsvcVMStatsReport: stats report failed with rc=%Rrc\n", rc); 597 600 } 598 601 … … 606 609 } 607 610 608 /** @copydoc VBOXSERVICE::pfnWorker */ 609 DECLCALLBACK(int) VBoxServiceVMStatsWorker(bool volatile *pfShutdown) 611 612 /** 613 * @interface_method_impl{VBOXSERVICE,pfnWorker} 614 */ 615 DECLCALLBACK(int) vgsvcVMStatsWorker(bool volatile *pfShutdown) 610 616 { 611 617 int rc = VINF_SUCCESS; … … 615 621 if (RT_FAILURE(rc)) 616 622 { 617 V BoxServiceVerbose(3, "VBoxServiceVMStatsWorker: VbglR3CtlFilterMask failed with %d\n", rc);623 VGSvcVerbose(3, "vgsvcVMStatsWorker: VbglR3CtlFilterMask failed with %d\n", rc); 618 624 return rc; 619 625 } … … 637 643 if ( RT_SUCCESS(rc) 638 644 && (fEvents & VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST)) 639 { 640 VbglR3StatQueryInterval(&gCtx.cMsStatInterval); 641 } 642 643 if (gCtx.cMsStatInterval) 644 { 645 VBoxServiceVMStatsReport(); 646 cWaitMillies = gCtx.cMsStatInterval; 645 VbglR3StatQueryInterval(&g_VMStat.cMsStatInterval); 646 647 if (g_VMStat.cMsStatInterval) 648 { 649 vgsvcVMStatsReport(); 650 cWaitMillies = g_VMStat.cMsStatInterval; 647 651 } 648 652 else … … 662 666 if (rc2 != VERR_TIMEOUT && RT_FAILURE(rc2)) 663 667 { 664 V BoxServiceError("VBoxServiceVMStatsWorker: RTSemEventMultiWait failed; rc2=%Rrc\n", rc2);668 VGSvcError("vgsvcVMStatsWorker: RTSemEventMultiWait failed; rc2=%Rrc\n", rc2); 665 669 rc = rc2; 666 670 break; … … 671 675 rc = VbglR3CtlFilterMask(0, VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST); 672 676 if (RT_FAILURE(rc)) 673 V BoxServiceVerbose(3, "VBoxServiceVMStatsWorker: VbglR3CtlFilterMask failed with %d\n", rc);677 VGSvcVerbose(3, "vgsvcVMStatsWorker: VbglR3CtlFilterMask failed with %d\n", rc); 674 678 675 679 RTSemEventMultiDestroy(g_VMStatEvent); 676 680 g_VMStatEvent = NIL_RTSEMEVENTMULTI; 677 681 678 V BoxServiceVerbose(3, "VBoxStatsThread: finished statistics change request thread\n");682 VGSvcVerbose(3, "VBoxStatsThread: finished statistics change request thread\n"); 679 683 return 0; 680 684 } 681 685 682 686 683 /** @copydoc VBOXSERVICE::pfnStop */ 684 static DECLCALLBACK(void) VBoxServiceVMStatsStop(void) 687 /** 688 * @interface_method_impl{VBOXSERVICE,pfnStop} 689 */ 690 static DECLCALLBACK(void) vgsvcVMStatsStop(void) 685 691 { 686 692 RTSemEventMultiSignal(g_VMStatEvent); … … 702 708 NULL, 703 709 /* methods */ 704 V BoxServiceDefaultPreInit,705 V BoxServiceDefaultOption,706 VBoxServiceVMStatsInit,707 VBoxServiceVMStatsWorker,708 VBoxServiceVMStatsStop,709 V BoxServiceDefaultTerm710 VGSvcDefaultPreInit, 711 VGSvcDefaultOption, 712 vgsvcVMStatsInit, 713 vgsvcVMStatsWorker, 714 vgsvcVMStatsStop, 715 VGSvcDefaultTerm 710 716 }; 711 717 -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceTimeSync.cpp
r57358 r58029 83 83 #ifdef RT_OS_WINDOWS 84 84 # include <Windows.h> 85 # include <winbase.h> /** @todo r=bird: Why is this here? Windows.h should include winbase.h... */86 85 #else 87 86 # include <unistd.h> … … 105 104 *********************************************************************************************************************************/ 106 105 /** The timesync interval (milliseconds). */ 107 uint32_tg_TimeSyncInterval = 0;106 static uint32_t g_TimeSyncInterval = 0; 108 107 /** 109 108 * @see pg_vboxservice_timesync 110 109 * 111 110 * @remark OS/2: There is either a 1 second resolution on the DosSetDateTime 112 * API or a bu t in the settimeofday implementation.Thus, don't111 * API or a bug in my settimeofday implementation. Thus, don't 113 112 * bother unless there is at least a 1 second drift. 114 113 */ 115 114 #ifdef RT_OS_OS2 116 static uint32_t g_TimeSyncMinAdjust = 1000;115 static uint32_t g_TimeSyncMinAdjust = 1000; 117 116 #else 118 static uint32_t g_TimeSyncMinAdjust = 100;117 static uint32_t g_TimeSyncMinAdjust = 100; 119 118 #endif 120 119 /** @see pg_vboxservice_timesync */ 121 static uint32_t g_TimeSyncLatencyFactor = 8;120 static uint32_t g_TimeSyncLatencyFactor = 8; 122 121 /** @see pg_vboxservice_timesync */ 123 static uint32_t g_TimeSyncMaxLatency = 250;122 static uint32_t g_TimeSyncMaxLatency = 250; 124 123 /** @see pg_vboxservice_timesync */ 125 static uint32_t g_TimeSyncSetThreshold = 20*60*1000;124 static uint32_t g_TimeSyncSetThreshold = 20*60*1000; 126 125 /** Whether the next adjustment should just set the time instead of trying to 127 126 * adjust it. This is used to implement --timesync-set-start. */ 128 static bool volatile g_fTimeSyncSetNext = false;127 static bool volatile g_fTimeSyncSetNext = false; 129 128 /** Whether to set the time when the VM was restored. */ 130 static bool g_fTimeSyncSetOnRestore = true;129 static bool g_fTimeSyncSetOnRestore = true; 131 130 132 131 /** Current error count. Used to knowing when to bitch and when not to. */ 133 static uint32_t g_cTimeSyncErrors = 0;132 static uint32_t g_cTimeSyncErrors = 0; 134 133 135 134 /** The semaphore we're blocking on. */ 136 static RTSEMEVENTMULTI g_TimeSyncEvent = NIL_RTSEMEVENTMULTI;135 static RTSEMEVENTMULTI g_TimeSyncEvent = NIL_RTSEMEVENTMULTI; 137 136 138 137 /** The VM session ID. Changes whenever the VM is restored or reset. */ 139 static uint64_t g_idTimeSyncSession;138 static uint64_t g_idTimeSyncSession; 140 139 141 140 #ifdef RT_OS_WINDOWS 142 141 /** Process token. */ 143 static HANDLE g_hTokenProcess = NULL;142 static HANDLE g_hTokenProcess = NULL; 144 143 /** Old token privileges. */ 145 144 static TOKEN_PRIVILEGES g_TkOldPrivileges; 146 145 /** Backup values for time adjustment. */ 147 static DWORD g_dwWinTimeAdjustment;148 static DWORD g_dwWinTimeIncrement;149 static BOOL g_bWinTimeAdjustmentDisabled;146 static DWORD g_dwWinTimeAdjustment; 147 static DWORD g_dwWinTimeIncrement; 148 static BOOL g_bWinTimeAdjustmentDisabled; 150 149 #endif 151 150 152 151 153 /** @copydoc VBOXSERVICE::pfnPreInit */ 154 static DECLCALLBACK(int) VBoxServiceTimeSyncPreInit(void) 152 /** 153 * @interface_method_impl{VBOXSERVICE,pfnPreInit} 154 */ 155 static DECLCALLBACK(int) vgsvcTimeSyncPreInit(void) 155 156 { 156 157 #ifdef VBOX_WITH_GUEST_PROPS 157 /** @todo Merge this function with VBoxServiceTimeSyncOption() to generalize158 /** @todo Merge this function with vgsvcTimeSyncOption() to generalize 158 159 * the "command line args override guest property values" behavior. */ 159 160 … … 168 169 if (rc == VERR_HGCM_SERVICE_NOT_FOUND) /* Host service is not available. */ 169 170 { 170 V BoxServiceVerbose(0, "VMInfo: Guest property service is not available, skipping\n");171 VGSvcVerbose(0, "VMInfo: Guest property service is not available, skipping\n"); 171 172 rc = VINF_SUCCESS; 172 173 } 173 174 else 174 V BoxServiceError("Failed to connect to the guest property service! Error: %Rrc\n", rc);175 VGSvcError("Failed to connect to the guest property service! Error: %Rrc\n", rc); 175 176 } 176 177 else 177 178 { 178 rc = V BoxServiceReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-interval",179 179 rc = VGSvcReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-interval", 180 &g_TimeSyncInterval, 50, UINT32_MAX - 1); 180 181 if ( RT_SUCCESS(rc) 181 182 || rc == VERR_NOT_FOUND) 182 { 183 rc = VBoxServiceReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-min-adjust", 184 &g_TimeSyncMinAdjust, 0, 3600000); 185 } 183 rc = VGSvcReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-min-adjust", 184 &g_TimeSyncMinAdjust, 0, 3600000); 186 185 if ( RT_SUCCESS(rc) 187 186 || rc == VERR_NOT_FOUND) 188 { 189 rc = VBoxServiceReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-latency-factor", 190 &g_TimeSyncLatencyFactor, 1, 1024); 191 } 187 rc = VGSvcReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-latency-factor", 188 &g_TimeSyncLatencyFactor, 1, 1024); 192 189 if ( RT_SUCCESS(rc) 193 190 || rc == VERR_NOT_FOUND) 194 { 195 rc = VBoxServiceReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-max-latency", 196 &g_TimeSyncMaxLatency, 1, 3600000); 197 } 191 rc = VGSvcReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-max-latency", 192 &g_TimeSyncMaxLatency, 1, 3600000); 198 193 if ( RT_SUCCESS(rc) 199 194 || rc == VERR_NOT_FOUND) 200 { 201 rc = VBoxServiceReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 202 &g_TimeSyncSetThreshold, 0, 7*24*60*60*1000 /* a week */); 203 } 195 rc = VGSvcReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 196 &g_TimeSyncSetThreshold, 0, 7*24*60*60*1000 /* a week */); 204 197 if ( RT_SUCCESS(rc) 205 198 || rc == VERR_NOT_FOUND) 206 199 { 207 200 char *pszValue; 208 rc = V BoxServiceReadProp(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-start",209 201 rc = VGSvcReadProp(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-start", 202 &pszValue, NULL /* ppszFlags */, NULL /* puTimestamp */); 210 203 if (RT_SUCCESS(rc)) 211 204 { … … 218 211 { 219 212 uint32_t value; 220 rc = V BoxServiceReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-on-restore",221 213 rc = VGSvcReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-on-restore", 214 &value, 1, 1); 222 215 if (RT_SUCCESS(rc)) 223 216 g_fTimeSyncSetOnRestore = !!value; … … 237 230 238 231 239 /** @copydoc VBOXSERVICE::pfnOption */ 240 static DECLCALLBACK(int) VBoxServiceTimeSyncOption(const char **ppszShort, int argc, char **argv, int *pi) 232 /** 233 * @interface_method_impl{VBOXSERVICE,pfnOption} 234 */ 235 static DECLCALLBACK(int) vgsvcTimeSyncOption(const char **ppszShort, int argc, char **argv, int *pi) 241 236 { 242 237 int rc = -1; … … 245 240 /* no short options */; 246 241 else if (!strcmp(argv[*pi], "--timesync-interval")) 247 rc = VBoxServiceArgUInt32(argc, argv, "", pi, 248 &g_TimeSyncInterval, 50, UINT32_MAX - 1); 242 rc = VGSvcArgUInt32(argc, argv, "", pi, &g_TimeSyncInterval, 50, UINT32_MAX - 1); 249 243 else if (!strcmp(argv[*pi], "--timesync-min-adjust")) 250 rc = VBoxServiceArgUInt32(argc, argv, "", pi, 251 &g_TimeSyncMinAdjust, 0, 3600000); 244 rc = VGSvcArgUInt32(argc, argv, "", pi, &g_TimeSyncMinAdjust, 0, 3600000); 252 245 else if (!strcmp(argv[*pi], "--timesync-latency-factor")) 253 rc = VBoxServiceArgUInt32(argc, argv, "", pi, 254 &g_TimeSyncLatencyFactor, 1, 1024); 246 rc = VGSvcArgUInt32(argc, argv, "", pi, &g_TimeSyncLatencyFactor, 1, 1024); 255 247 else if (!strcmp(argv[*pi], "--timesync-max-latency")) 256 rc = VBoxServiceArgUInt32(argc, argv, "", pi, 257 &g_TimeSyncMaxLatency, 1, 3600000); 248 rc = VGSvcArgUInt32(argc, argv, "", pi, &g_TimeSyncMaxLatency, 1, 3600000); 258 249 else if (!strcmp(argv[*pi], "--timesync-set-threshold")) 259 rc = VBoxServiceArgUInt32(argc, argv, "", pi, 260 &g_TimeSyncSetThreshold, 0, 7*24*60*60*1000); /* a week */ 250 rc = VGSvcArgUInt32(argc, argv, "", pi, &g_TimeSyncSetThreshold, 0, 7*24*60*60*1000); /* a week */ 261 251 else if (!strcmp(argv[*pi], "--timesync-set-start")) 262 252 { … … 266 256 else if (!strcmp(argv[*pi], "--timesync-set-on-restore")) 267 257 { 268 rc = V BoxServiceArgUInt32(argc, argv, "", pi, &value, 1, 1);258 rc = VGSvcArgUInt32(argc, argv, "", pi, &value, 1, 1); 269 259 if (RT_SUCCESS(rc)) 270 260 g_fTimeSyncSetOnRestore = !!value; … … 275 265 276 266 277 /** @copydoc VBOXSERVICE::pfnInit */ 278 static DECLCALLBACK(int) VBoxServiceTimeSyncInit(void) 267 /** 268 * @interface_method_impl{VBOXSERVICE,pfnInit} 269 */ 270 static DECLCALLBACK(int) vgsvcTimeSyncInit(void) 279 271 { 280 272 /* … … 313 305 DWORD dwErr = GetLastError(); 314 306 rc = RTErrConvertFromWin32(dwErr); 315 VBoxServiceError("VBoxServiceTimeSyncInit: Adjusting token privileges (SE_SYSTEMTIME_NAME) failed with status code %u/%Rrc!\n", dwErr, rc); 307 VGSvcError("vgsvcTimeSyncInit: Adjusting token privileges (SE_SYSTEMTIME_NAME) failed with status code %u/%Rrc!\n", 308 dwErr, rc); 316 309 } 317 310 } … … 320 313 DWORD dwErr = GetLastError(); 321 314 rc = RTErrConvertFromWin32(dwErr); 322 VBoxServiceError("VBoxServiceTimeSyncInit: Looking up token privileges (SE_SYSTEMTIME_NAME) failed with status code %u/%Rrc!\n", dwErr, rc); 315 VGSvcError("vgsvcTimeSyncInit: Looking up token privileges (SE_SYSTEMTIME_NAME) failed with status code %u/%Rrc!\n", 316 dwErr, rc); 323 317 } 324 318 if (RT_FAILURE(rc)) … … 332 326 DWORD dwErr = GetLastError(); 333 327 rc = RTErrConvertFromWin32(dwErr); 334 VBoxServiceError("VBoxServiceTimeSyncInit: Opening process token (SE_SYSTEMTIME_NAME) failed with status code %u/%Rrc!\n", dwErr, rc); 328 VGSvcError("vgsvcTimeSyncInit: Opening process token (SE_SYSTEMTIME_NAME) failed with status code %u/%Rrc!\n", 329 dwErr, rc); 335 330 g_hTokenProcess = NULL; 336 331 } … … 338 333 339 334 if (GetSystemTimeAdjustment(&g_dwWinTimeAdjustment, &g_dwWinTimeIncrement, &g_bWinTimeAdjustmentDisabled)) 340 V BoxServiceVerbose(3, "VBoxServiceTimeSyncInit: Initially %ld (100ns) units per %ld (100 ns) units interval, disabled=%d\n",341 335 VGSvcVerbose(3, "vgsvcTimeSyncInit: Initially %ld (100ns) units per %ld (100 ns) units interval, disabled=%d\n", 336 g_dwWinTimeAdjustment, g_dwWinTimeIncrement, g_bWinTimeAdjustmentDisabled ? 1 : 0); 342 337 else 343 338 { 344 339 DWORD dwErr = GetLastError(); 345 340 rc = RTErrConvertFromWin32(dwErr); 346 V BoxServiceError("VBoxServiceTimeSyncInit: Could not get time adjustment values! Last error: %ld!\n", dwErr);341 VGSvcError("vgsvcTimeSyncInit: Could not get time adjustment values! Last error: %ld!\n", dwErr); 347 342 } 348 343 #endif /* RT_OS_WINDOWS */ … … 359 354 * @param pDrift The time adjustment. 360 355 */ 361 static bool VBoxServiceTimeSyncAdjust(PCRTTIMESPEC pDrift)356 static bool vgsvcTimeSyncAdjust(PCRTTIMESPEC pDrift) 362 357 { 363 358 #ifdef RT_OS_WINDOWS 364 /** @todo r=bird: NT4 doesn't have GetSystemTimeAdjustment according to MSDN. */365 359 /** @todo r=bird: g_hTokenProcess cannot be NULL here. 366 * VBoxServiceTimeSyncInit will fail and the service will not be367 * started with it being NULL. VBoxServiceTimeSyncInit OTOH will *NOT*368 * be called until theservice thread has terminated. If anything360 * vgsvcTimeSyncInit will fail and the service will not be started with 361 * it being NULL. vgsvcTimeSyncInit OTOH will *NOT* be called until the 362 * service thread has terminated. If anything 369 363 * else is the case, there is buggy code somewhere.*/ 370 364 if (g_hTokenProcess == NULL) /* Is the token already closed when shutting down? */ … … 397 391 } 398 392 399 V BoxServiceVerbose(3, "VBoxServiceTimeSyncAdjust: Drift=%lldms\n", RTTimeSpecGetMilli(pDrift));400 V BoxServiceVerbose(3, "VBoxServiceTimeSyncAdjust: OrgTA=%ld, CurTA=%ld, NewTA=%ld, DiffNew=%ld, DiffMax=%ld\n",401 393 VGSvcVerbose(3, "vgsvcTimeSyncAdjust: Drift=%lldms\n", RTTimeSpecGetMilli(pDrift)); 394 VGSvcVerbose(3, "vgsvcTimeSyncAdjust: OrgTA=%ld, CurTA=%ld, NewTA=%ld, DiffNew=%ld, DiffMax=%ld\n", 395 g_dwWinTimeAdjustment, dwWinTimeAdjustment, dwWinNewTimeAdjustment, dwDiffNew, dwDiffMax); 402 396 if (SetSystemTimeAdjustment(dwWinNewTimeAdjustment, FALSE /* Periodic adjustments enabled. */)) 403 397 { … … 407 401 408 402 if (g_cTimeSyncErrors++ < 10) 409 V BoxServiceError("VBoxServiceTimeSyncAdjust: SetSystemTimeAdjustment failed, error=%u\n", GetLastError());403 VGSvcError("vgsvcTimeSyncAdjust: SetSystemTimeAdjustment failed, error=%u\n", GetLastError()); 410 404 } 411 405 else if (g_cTimeSyncErrors++ < 10) 412 V BoxServiceError("VBoxServiceTimeSyncAdjust: GetSystemTimeAdjustment failed, error=%ld\n", GetLastError());406 VGSvcError("vgsvcTimeSyncAdjust: GetSystemTimeAdjustment failed, error=%ld\n", GetLastError()); 413 407 414 408 #elif defined(RT_OS_OS2) || defined(RT_OS_HAIKU) … … 424 418 { 425 419 if (g_cVerbosity >= 1) 426 V BoxServiceVerbose(1, "VBoxServiceTimeSyncAdjust: adjtime by %RDtimespec\n", pDrift);420 VGSvcVerbose(1, "vgsvcTimeSyncAdjust: adjtime by %RDtimespec\n", pDrift); 427 421 g_cTimeSyncErrors = 0; 428 422 return true; … … 438 432 * Cancels any pending time adjustment. 439 433 * 440 * Called when we've caught up and before calls to VBoxServiceTimeSyncSet.441 */ 442 static void VBoxServiceTimeSyncCancelAdjust(void)434 * Called when we've caught up and before calls to vgsvcTimeSyncSet. 435 */ 436 static void vgsvcTimeSyncCancelAdjust(void) 443 437 { 444 438 #ifdef RT_OS_WINDOWS 445 439 /** @todo r=bird: g_hTokenProcess cannot be NULL here. See argumentation in 446 * VBoxServiceTimeSyncAdjust. */440 * vgsvcTimeSyncAdjust. */ 447 441 if (g_hTokenProcess == NULL) /* No process token (anymore)? */ 448 442 return; 449 443 if (SetSystemTimeAdjustment(0, TRUE /* Periodic adjustments disabled. */)) 450 V BoxServiceVerbose(3, "VBoxServiceTimeSyncCancelAdjust: Windows Time Adjustment is now disabled.\n");444 VGSvcVerbose(3, "vgsvcTimeSyncCancelAdjust: Windows Time Adjustment is now disabled.\n"); 451 445 else if (g_cTimeSyncErrors++ < 10) 452 V BoxServiceError("VBoxServiceTimeSyncCancelAdjust: SetSystemTimeAdjustment(,disable) failed, error=%u\n", GetLastError());446 VGSvcError("vgsvcTimeSyncCancelAdjust: SetSystemTimeAdjustment(,disable) failed, error=%u\n", GetLastError()); 453 447 #endif /* !RT_OS_WINDOWS */ 454 448 } … … 462 456 * @param pDrift The time adjustment. 463 457 */ 464 static void VBoxServiceTimeSyncSet(PCRTTIMESPEC pDrift)458 static void vgsvcTimeSyncSet(PCRTTIMESPEC pDrift) 465 459 { 466 460 /* … … 478 472 char sz[64]; 479 473 RTTIME Time; 480 VBoxServiceVerbose(1, "time set to %s\n", 481 RTTimeToString(RTTimeExplode(&Time, &NewGuestTime), sz, sizeof(sz))); 474 VGSvcVerbose(1, "time set to %s\n", RTTimeToString(RTTimeExplode(&Time, &NewGuestTime), sz, sizeof(sz))); 482 475 #ifdef DEBUG 483 476 RTTIMESPEC Tmp; 484 477 if (g_cVerbosity >= 3) 485 VBoxServiceVerbose(3, " now %s\n", 486 RTTimeToString(RTTimeExplode(&Time, RTTimeNow(&Tmp)), sz, sizeof(sz))); 478 VGSvcVerbose(3, " now %s\n", RTTimeToString(RTTimeExplode(&Time, RTTimeNow(&Tmp)), sz, sizeof(sz))); 487 479 #endif 488 480 } 489 481 } 490 482 else if (g_cTimeSyncErrors++ < 10) 491 VBoxServiceError("VBoxServiceTimeSyncSet: RTTimeSet(%RDtimespec) failed: %Rrc\n", &NewGuestTime, rc); 492 } 493 494 495 /** @copydoc VBOXSERVICE::pfnWorker */ 496 DECLCALLBACK(int) VBoxServiceTimeSyncWorker(bool volatile *pfShutdown) 483 VGSvcError("vgsvcTimeSyncSet: RTTimeSet(%RDtimespec) failed: %Rrc\n", &NewGuestTime, rc); 484 } 485 486 487 /** 488 * @interface_method_impl{VBOXSERVICE,pfnWorker} 489 */ 490 DECLCALLBACK(int) vgsvcTimeSyncWorker(bool volatile *pfShutdown) 497 491 { 498 492 RTTIME Time; … … 523 517 { 524 518 if (g_cTimeSyncErrors++ < 10) 525 V BoxServiceError("VBoxServiceTimeSyncWorker: VbglR3GetHostTime failed; rc2=%Rrc\n", rc2);519 VGSvcError("vgsvcTimeSyncWorker: VbglR3GetHostTime failed; rc2=%Rrc\n", rc2); 526 520 break; 527 521 } … … 544 538 if (idNewSession != g_idTimeSyncSession) 545 539 { 546 V BoxServiceVerbose(3, "VBoxServiceTimeSyncWorker: The VM session ID changed, forcing resync.\n");540 VGSvcVerbose(3, "vgsvcTimeSyncWorker: The VM session ID changed, forcing resync.\n"); 547 541 TimeSyncSetThreshold = 0; 548 542 g_idTimeSyncSession = idNewSession; … … 566 560 if (g_cVerbosity >= 3) 567 561 { 568 VBoxServiceVerbose(3, "VBoxServiceTimeSyncWorker: Host: %s (MinAdjust: %RU32 ms)\n", 569 RTTimeToString(RTTimeExplode(&Time, &HostNow), sz, sizeof(sz)), MinAdjust); 570 VBoxServiceVerbose(3, "VBoxServiceTimeSyncWorker: Guest: - %s => %RDtimespec drift\n", 571 RTTimeToString(RTTimeExplode(&Time, &GuestNow), sz, sizeof(sz)), 572 &Drift); 562 VGSvcVerbose(3, "vgsvcTimeSyncWorker: Host: %s (MinAdjust: %RU32 ms)\n", 563 RTTimeToString(RTTimeExplode(&Time, &HostNow), sz, sizeof(sz)), MinAdjust); 564 VGSvcVerbose(3, "vgsvcTimeSyncWorker: Guest: - %s => %RDtimespec drift\n", 565 RTTimeToString(RTTimeExplode(&Time, &GuestNow), sz, sizeof(sz)), &Drift); 573 566 } 574 567 … … 585 578 if ( AbsDriftMilli > TimeSyncSetThreshold 586 579 || g_fTimeSyncSetNext 587 || ! VBoxServiceTimeSyncAdjust(&Drift))580 || !vgsvcTimeSyncAdjust(&Drift)) 588 581 { 589 VBoxServiceTimeSyncCancelAdjust();590 VBoxServiceTimeSyncSet(&Drift);582 vgsvcTimeSyncCancelAdjust(); 583 vgsvcTimeSyncSet(&Drift); 591 584 } 592 585 } 593 586 else 594 VBoxServiceTimeSyncCancelAdjust();587 vgsvcTimeSyncCancelAdjust(); 595 588 break; 596 589 } 597 V BoxServiceVerbose(3, "VBoxServiceTimeSyncWorker: %RDtimespec: latency too high (%RDtimespec) sleeping 1s\n", GuestElapsed);590 VGSvcVerbose(3, "vgsvcTimeSyncWorker: %RDtimespec: latency too high (%RDtimespec) sleeping 1s\n", GuestElapsed); 598 591 RTThreadSleep(1000); 599 592 } while (--cTries > 0); … … 615 608 if (rc2 != VERR_TIMEOUT && RT_FAILURE(rc2)) 616 609 { 617 V BoxServiceError("VBoxServiceTimeSyncWorker: RTSemEventMultiWait failed; rc2=%Rrc\n", rc2);610 VGSvcError("vgsvcTimeSyncWorker: RTSemEventMultiWait failed; rc2=%Rrc\n", rc2); 618 611 rc = rc2; 619 612 break; … … 621 614 } 622 615 623 VBoxServiceTimeSyncCancelAdjust();616 vgsvcTimeSyncCancelAdjust(); 624 617 RTSemEventMultiDestroy(g_TimeSyncEvent); 625 618 g_TimeSyncEvent = NIL_RTSEMEVENTMULTI; … … 628 621 629 622 630 /** @copydoc VBOXSERVICE::pfnStop */ 631 static DECLCALLBACK(void) VBoxServiceTimeSyncStop(void) 623 /** 624 * @interface_method_impl{VBOXSERVICE,pfnStop} 625 */ 626 static DECLCALLBACK(void) vgsvcTimeSyncStop(void) 632 627 { 633 628 RTSemEventMultiSignal(g_TimeSyncEvent); … … 635 630 636 631 637 /** @copydoc VBOXSERVICE::pfnTerm */ 638 static DECLCALLBACK(void) VBoxServiceTimeSyncTerm(void) 632 /** 633 * @interface_method_impl{VBOXSERVICE,pfnTerm} 634 */ 635 static DECLCALLBACK(void) vgsvcTimeSyncTerm(void) 639 636 { 640 637 #ifdef RT_OS_WINDOWS … … 647 644 { 648 645 DWORD dwErr = GetLastError(); 649 V BoxServiceError("VBoxServiceTimeSyncTerm: Restoring token privileges (SE_SYSTEMTIME_NAME) failed with code %u!\n", dwErr);646 VGSvcError("vgsvcTimeSyncTerm: Restoring token privileges (SE_SYSTEMTIME_NAME) failed with code %u!\n", dwErr); 650 647 } 651 648 CloseHandle(g_hTokenProcess); … … 699 696 , 700 697 /* methods */ 701 VBoxServiceTimeSyncPreInit,702 VBoxServiceTimeSyncOption,703 VBoxServiceTimeSyncInit,704 VBoxServiceTimeSyncWorker,705 VBoxServiceTimeSyncStop,706 VBoxServiceTimeSyncTerm698 vgsvcTimeSyncPreInit, 699 vgsvcTimeSyncOption, 700 vgsvcTimeSyncInit, 701 vgsvcTimeSyncWorker, 702 vgsvcTimeSyncStop, 703 vgsvcTimeSyncTerm 707 704 }; 708 705 -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceToolBox.cpp
r57358 r58029 106 106 107 107 108 109 108 110 /** 109 111 * Displays a common header for all help text to stdout. 110 112 */ 111 static void VBoxServiceToolboxShowUsageHeader(void)113 static void vgsvcToolboxShowUsageHeader(void) 112 114 { 113 115 RTPrintf(VBOX_PRODUCT " Guest Toolbox Version " … … 123 125 * Displays a help text to stdout. 124 126 */ 125 static void VBoxServiceToolboxShowUsage(void)126 { 127 VBoxServiceToolboxShowUsageHeader();127 static void vgsvcToolboxShowUsage(void) 128 { 129 vgsvcToolboxShowUsageHeader(); 128 130 RTPrintf(" VBoxService [--use-toolbox] vbox_<command> [<general options>] <parameters>\n\n" 129 131 "General options:\n\n" … … 151 153 * Displays the program's version number. 152 154 */ 153 static void VBoxServiceToolboxShowVersion(void)155 static void vgsvcToolboxShowVersion(void) 154 156 { 155 157 RTPrintf("%sr%d\n", VBOX_VERSION_STRING, RTBldCfgRevision()); … … 162 164 * @return IPRT status code. 163 165 */ 164 static int VBoxServiceToolboxStrmInit(void)166 static int vgsvcToolboxStrmInit(void) 165 167 { 166 168 /* Set stdout's mode to binary. This is required for outputting all the machine-readable … … 182 184 * different stream versions later. 183 185 */ 184 static void VBoxServiceToolboxPrintStrmHeader(const char *pszToolName, uint32_t uVersion)186 static void vgsvcToolboxPrintStrmHeader(const char *pszToolName, uint32_t uVersion) 185 187 { 186 188 AssertPtrReturnVoid(pszToolName); … … 194 196 * 195 197 */ 196 static void VBoxServiceToolboxPrintStrmTermination()198 static void vgsvcToolboxPrintStrmTermination() 197 199 { 198 200 RTPrintf("%c%c%c%c", 0, 0, 0, 0); … … 204 206 * and print an error message and return an error if necessary. 205 207 */ 206 static int v boxServiceToolboxParseMode(const char *pcszMode, RTFMODE *pfMode)208 static int vgsvcToolboxParseMode(const char *pcszMode, RTFMODE *pfMode) 207 209 { 208 210 int rc = RTStrToUInt32Ex(pcszMode, NULL, 8 /* Base */, pfMode); 209 211 if (RT_FAILURE(rc)) /* Only octet based values supported right now! */ 210 RTMsgError("Mode flag strings not implemented yet! Use octal numbers instead. (%s)\n", 211 pcszMode); 212 RTMsgError("Mode flag strings not implemented yet! Use octal numbers instead. (%s)\n", pcszMode); 212 213 return rc; 213 214 } … … 220 221 * @param pList Pointer to list to destroy. 221 222 */ 222 static void VBoxServiceToolboxPathBufDestroy(PRTLISTNODE pList)223 static void vgsvcToolboxPathBufDestroy(PRTLISTNODE pList) 223 224 { 224 225 AssertPtr(pList); … … 247 248 * @param pszName Name of entry to add. 248 249 */ 249 static int VBoxServiceToolboxPathBufAddPathEntry(PRTLISTNODE pList, const char *pszName)250 static int vgsvcToolboxPathBufAddPathEntry(PRTLISTNODE pList, const char *pszName) 250 251 { 251 252 AssertPtrReturn(pList, VERR_INVALID_PARAMETER); … … 258 259 AssertPtr(pNode->pszName); 259 260 260 /*rc =*/RTListAppend(pList, &pNode->Node);261 RTListAppend(pList, &pNode->Node); 261 262 } 262 263 else … … 275 276 * else stdout will be used. 276 277 */ 277 static int VBoxServiceToolboxCatOutput(RTFILE hInput, RTFILE hOutput)278 static int vgsvcToolboxCatOutput(RTFILE hInput, RTFILE hOutput) 278 279 { 279 280 int rc = VINF_SUCCESS; … … 336 337 * @param argv Pointer to argument array. 337 338 */ 338 static RTEXITCODE VBoxServiceToolboxCat(int argc, char **argv)339 static RTEXITCODE vgsvcToolboxCat(int argc, char **argv) 339 340 { 340 341 static const RTGETOPTDEF s_aOptions[] = … … 360 361 RTGETOPTSTATE GetState; 361 362 362 RTGetOptInit(&GetState, argc, argv, 363 s_aOptions, RT_ELEMENTS(s_aOptions), 364 1 /*iFirst*/, 0 /*fFlags*/); 363 RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1 /*iFirst*/, 0 /*fFlags*/); 365 364 366 365 int rc = VINF_SUCCESS; … … 370 369 RTFILE hOutput = NIL_RTFILE; 371 370 uint32_t fFlags = RTFILE_O_CREATE_REPLACE /* Output file flags. */ 372 373 371 | RTFILE_O_WRITE 372 | RTFILE_O_DENY_WRITE; 374 373 375 374 /* Init directory list. */ … … 398 397 399 398 case 'h': 400 VBoxServiceToolboxShowUsageHeader();399 vgsvcToolboxShowUsageHeader(); 401 400 RTPrintf("%s", g_paszCatHelp); 402 401 return RTEXITCODE_SUCCESS; … … 411 410 412 411 case 'V': 413 VBoxServiceToolboxShowVersion();412 vgsvcToolboxShowVersion(); 414 413 return RTEXITCODE_SUCCESS; 415 414 … … 419 418 420 419 case VINF_GETOPT_NOT_OPTION: 421 { 422 /* Add file(s) to buffer. This enables processing multiple paths 423 * at once. 424 * 425 * Since the non-options (RTGETOPTINIT_FLAGS_OPTS_FIRST) come last when 426 * processing this loop it's safe to immediately exit on syntax errors 427 * or showing the help text (see above). */ 428 rc = VBoxServiceToolboxPathBufAddPathEntry(&inputList, ValueUnion.psz); 429 break; 430 } 420 /* Add file(s) to buffer. This enables processing multiple paths 421 * at once. 422 * 423 * Since the non-options (RTGETOPTINIT_FLAGS_OPTS_FIRST) come last when 424 * processing this loop it's safe to immediately exit on syntax errors 425 * or showing the help text (see above). */ 426 rc = vgsvcToolboxPathBufAddPathEntry(&inputList, ValueUnion.psz); 427 break; 431 428 432 429 default: … … 441 438 rc = RTFileOpen(&hOutput, pszOutput, fFlags); 442 439 if (RT_FAILURE(rc)) 443 RTMsgError("Could not create output file '%s', rc=%Rrc\n", 444 pszOutput, rc); 440 RTMsgError("Could not create output file '%s', rc=%Rrc\n", pszOutput, rc); 445 441 } 446 442 … … 456 452 if (RT_SUCCESS(rc)) 457 453 { 458 rc = VBoxServiceToolboxCatOutput(hInput, hOutput);454 rc = vgsvcToolboxCatOutput(hInput, hOutput); 459 455 RTFileClose(hInput); 460 456 } … … 463 459 PCRTSTATUSMSG pMsg = RTErrGet(rc); 464 460 if (pMsg) 465 RTMsgError("Could not open input file '%s': %s\n", 466 pNodeIt->pszName, pMsg->pszMsgFull); 461 RTMsgError("Could not open input file '%s': %s\n", pNodeIt->pszName, pMsg->pszMsgFull); 467 462 else 468 463 RTMsgError("Could not open input file '%s', rc=%Rrc\n", pNodeIt->pszName, rc); … … 475 470 /* If not input files were defined, process stdin. */ 476 471 if (RTListNodeIsFirst(&inputList, &inputList)) 477 rc = VBoxServiceToolboxCatOutput(hInput, hOutput);472 rc = vgsvcToolboxCatOutput(hInput, hOutput); 478 473 } 479 474 } … … 481 476 if (hOutput != NIL_RTFILE) 482 477 RTFileClose(hOutput); 483 VBoxServiceToolboxPathBufDestroy(&inputList);478 vgsvcToolboxPathBufDestroy(&inputList); 484 479 485 480 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; … … 491 486 * 492 487 * @return IPRT status code. 493 * @param pszName Object name. 494 * @param cbName Size of object name. 495 * @param uOutputFlags Output / handling flags of type VBOXSERVICETOOLBOXOUTPUTFLAG. 496 * @param pObjInfo Pointer to object information. 497 */ 498 static int VBoxServiceToolboxPrintFsInfo(const char *pszName, uint16_t cbName, 499 uint32_t uOutputFlags, 500 PRTFSOBJINFO pObjInfo) 488 * @param pszName Object name. 489 * @param cbName Size of object name. 490 * @param fOutputFlags Output / handling flags of type 491 * VBOXSERVICETOOLBOXOUTPUTFLAG. 492 * @param pObjInfo Pointer to object information. 493 */ 494 static int vgsvcToolboxPrintFsInfo(const char *pszName, size_t cbName, uint32_t fOutputFlags, PRTFSOBJINFO pObjInfo) 501 495 { 502 496 AssertPtrReturn(pszName, VERR_INVALID_POINTER); … … 520 514 /** @todo sticy bits++ */ 521 515 522 if (!( uOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_LONG))523 { 524 if ( uOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE)516 if (!(fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_LONG)) 517 { 518 if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE) 525 519 { 526 520 /** @todo Skip node_id if not present/available! */ 527 RTPrintf("ftype=%c%cnode_id=%RU64%cname_len=% RU16%cname=%s%c",521 RTPrintf("ftype=%c%cnode_id=%RU64%cname_len=%zu%cname=%s%c", 528 522 chFileType, 0, (uint64_t)pObjInfo->Attr.u.Unix.INodeId, 0, 529 523 cbName, 0, pszName, 0); 530 524 } 531 525 else 532 RTPrintf("%c %#18llx %3 d%s\n",526 RTPrintf("%c %#18llx %3zu %s\n", 533 527 chFileType, (uint64_t)pObjInfo->Attr.u.Unix.INodeId, cbName, pszName); 534 528 535 if ( uOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE) /* End of data block. */529 if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE) /* End of data block. */ 536 530 RTPrintf("%c%c", 0, 0); 537 531 } 538 532 else 539 533 { 540 if ( uOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE)534 if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE) 541 535 { 542 536 RTPrintf("ftype=%c%c", chFileType, 0); … … 591 585 szTimeModification, 0, 592 586 szTimeAccess, 0); 593 RTPrintf("cname_len=% RU16%cname=%s%c",587 RTPrintf("cname_len=%zu%cname=%s%c", 594 588 cbName, 0, pszName, 0); 595 589 … … 637 631 RTTimeSpecGetNano(&pObjInfo->ModificationTime), /** @todo really ns? */ 638 632 RTTimeSpecGetNano(&pObjInfo->AccessTime)); /** @todo really ns? */ 639 RTPrintf(" %2 d%s\n", cbName, pszName);633 RTPrintf(" %2zu %s\n", cbName, pszName); 640 634 } 641 635 } … … 651 645 * @return IPRT status code. 652 646 * @param pszDir Directory (path) to ouptut. 653 * @param uFlags Flags of type VBOXSERVICETOOLBOXLSFLAG. 654 * @param uOutputFlags Flags of type VBOXSERVICETOOLBOXOUTPUTFLAG. 655 */ 656 static int VBoxServiceToolboxLsHandleDir(const char *pszDir, 657 uint32_t uFlags, uint32_t uOutputFlags) 647 * @param fFlags Flags of type VBOXSERVICETOOLBOXLSFLAG. 648 * @param fOutputFlags Flags of type VBOXSERVICETOOLBOXOUTPUTFLAG. 649 */ 650 static int vgsvcToolboxLsHandleDir(const char *pszDir, uint32_t fFlags, uint32_t fOutputFlags) 658 651 { 659 652 AssertPtrReturn(pszDir, VERR_INVALID_PARAMETER); 660 653 661 if ( uFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE)654 if (fFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE) 662 655 RTPrintf("dname=%s%c", pszDir, 0); 663 else if ( uFlags & VBOXSERVICETOOLBOXLSFLAG_RECURSIVE)656 else if (fFlags & VBOXSERVICETOOLBOXLSFLAG_RECURSIVE) 664 657 RTPrintf("%s:\n", pszDir); 665 658 … … 668 661 if (RT_FAILURE(rc)) 669 662 { 670 if (!( uOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE))663 if (!(fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE)) 671 664 RTMsgError("Failed to retrieve absolute path of '%s', rc=%Rrc\n", pszDir, rc); 672 665 return rc; … … 677 670 if (RT_FAILURE(rc)) 678 671 { 679 if (!( uOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE))672 if (!(fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE)) 680 673 RTMsgError("Failed to open directory '%s', rc=%Rrc\n", szPathAbs, rc); 681 674 return rc; … … 699 692 { 700 693 memcpy(&pNode->dirEntry, &DirEntry, sizeof(RTDIRENTRYEX)); 701 /*rc =*/RTListAppend(&dirList, &pNode->Node);694 RTListAppend(&dirList, &pNode->Node); 702 695 } 703 696 else … … 712 705 if (RT_FAILURE(rc2)) 713 706 { 714 if (!(uOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE)) 715 RTMsgError("Failed to close dir '%s', rc=%Rrc\n", 716 pszDir, rc2); 707 if (!(fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE)) 708 RTMsgError("Failed to close dir '%s', rc=%Rrc\n", pszDir, rc2); 717 709 if (RT_SUCCESS(rc)) 718 710 rc = rc2; … … 724 716 RTListForEach(&dirList, pNodeIt, VBOXSERVICETOOLBOXDIRENTRY, Node) 725 717 { 726 rc = VBoxServiceToolboxPrintFsInfo(pNodeIt->dirEntry.szName, pNodeIt->dirEntry.cbName, 727 uOutputFlags, 728 &pNodeIt->dirEntry.Info); 718 rc = vgsvcToolboxPrintFsInfo(pNodeIt->dirEntry.szName, pNodeIt->dirEntry.cbName, 719 fOutputFlags, &pNodeIt->dirEntry.Info); 729 720 if (RT_FAILURE(rc)) 730 721 break; … … 733 724 /* If everything went fine we do the second run (if needed) ... */ 734 725 if ( RT_SUCCESS(rc) 735 && ( uFlags & VBOXSERVICETOOLBOXLSFLAG_RECURSIVE))726 && (fFlags & VBOXSERVICETOOLBOXLSFLAG_RECURSIVE)) 736 727 { 737 728 /* Process all sub-directories. */ … … 742 733 { 743 734 case RTFS_TYPE_SYMLINK: 744 if (!( uFlags & VBOXSERVICETOOLBOXLSFLAG_SYMLINKS))735 if (!(fFlags & VBOXSERVICETOOLBOXLSFLAG_SYMLINKS)) 745 736 break; 746 737 /* Fall through is intentional. */ 747 738 case RTFS_TYPE_DIRECTORY: 739 { 740 const char *pszName = pNodeIt->dirEntry.szName; 741 if ( !RTStrICmp(pszName, ".") 742 || !RTStrICmp(pszName, "..")) 748 743 { 749 const char *pszName = pNodeIt->dirEntry.szName; 750 if ( !RTStrICmp(pszName, ".") 751 || !RTStrICmp(pszName, "..")) 752 { 753 /* Skip dot directories. */ 754 continue; 755 } 756 757 char szPath[RTPATH_MAX]; 758 rc = RTPathJoin(szPath, sizeof(szPath), 759 pszDir, pNodeIt->dirEntry.szName); 760 if (RT_SUCCESS(rc)) 761 rc = VBoxServiceToolboxLsHandleDir(szPath, 762 uFlags, uOutputFlags); 744 /* Skip dot directories. */ 745 continue; 763 746 } 747 748 char szPath[RTPATH_MAX]; 749 rc = RTPathJoin(szPath, sizeof(szPath), pszDir, pNodeIt->dirEntry.szName); 750 if (RT_SUCCESS(rc)) 751 rc = vgsvcToolboxLsHandleDir(szPath, fFlags, fOutputFlags); 764 752 break; 753 } 765 754 766 755 default: /* Ignore the rest. */ … … 804 793 * @param argv Pointer to argument array. 805 794 */ 806 static RTEXITCODE VBoxServiceToolboxLs(int argc, char **argv)795 static RTEXITCODE vgsvcToolboxLs(int argc, char **argv) 807 796 { 808 797 static const RTGETOPTDEF s_aOptions[] = 809 798 { 810 799 { "--machinereadable", VBOXSERVICETOOLBOXOPT_MACHINE_READABLE, RTGETOPT_REQ_NOTHING }, 811 { "--dereference", 'L', 812 { NULL, 'l', 813 { NULL, 'R', 800 { "--dereference", 'L', RTGETOPT_REQ_NOTHING }, 801 { NULL, 'l', RTGETOPT_REQ_NOTHING }, 802 { NULL, 'R', RTGETOPT_REQ_NOTHING }, 814 803 { "--verbose", VBOXSERVICETOOLBOXOPT_VERBOSE, RTGETOPT_REQ_NOTHING} 815 804 }; … … 818 807 RTGETOPTUNION ValueUnion; 819 808 RTGETOPTSTATE GetState; 820 int rc = RTGetOptInit(&GetState, argc, argv, 821 s_aOptions, RT_ELEMENTS(s_aOptions), 809 int rc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 822 810 1 /*iFirst*/, RTGETOPTINIT_FLAGS_OPTS_FIRST); 823 811 AssertRCReturn(rc, RTEXITCODE_INIT); … … 832 820 833 821 while ( (ch = RTGetOpt(&GetState, &ValueUnion)) 834 822 && RT_SUCCESS(rc)) 835 823 { 836 824 /* For options that require an argument, ValueUnion has received the value. */ … … 838 826 { 839 827 case 'h': 840 VBoxServiceToolboxShowUsageHeader();828 vgsvcToolboxShowUsageHeader(); 841 829 RTPrintf("%s", g_paszLsHelp); 842 830 return RTEXITCODE_SUCCESS; … … 863 851 864 852 case 'V': 865 VBoxServiceToolboxShowVersion();853 vgsvcToolboxShowVersion(); 866 854 return RTEXITCODE_SUCCESS; 867 855 … … 873 861 * processing this loop it's safe to immediately exit on syntax errors 874 862 * or showing the help text (see above). */ 875 rc = VBoxServiceToolboxPathBufAddPathEntry(&fileList, ValueUnion.psz);863 rc = vgsvcToolboxPathBufAddPathEntry(&fileList, ValueUnion.psz); 876 864 /** @todo r=bird: Nit: creating a list here is not really 877 865 * necessary since you've got one in argv that's … … 893 881 if (RT_SUCCESS(rc)) 894 882 { 895 rc = VBoxServiceToolboxPathBufAddPathEntry(&fileList, szDirCur);883 rc = vgsvcToolboxPathBufAddPathEntry(&fileList, szDirCur); 896 884 if (RT_FAILURE(rc)) 897 885 RTMsgError("Adding current directory failed, rc=%Rrc\n", rc); … … 904 892 if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE) 905 893 { 906 rc = VBoxServiceToolboxStrmInit();894 rc = vgsvcToolboxStrmInit(); 907 895 if (RT_FAILURE(rc)) 908 896 RTMsgError("Error while initializing parseable streams, rc=%Rrc\n", rc); 909 VBoxServiceToolboxPrintStrmHeader("vbt_ls", 1 /* Stream version */);897 vgsvcToolboxPrintStrmHeader("vbt_ls", 1 /* Stream version */); 910 898 } 911 899 … … 917 905 RTFSOBJINFO objInfo; 918 906 int rc2 = RTPathQueryInfoEx(pNodeIt->pszName, &objInfo, 919 RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK /* @todo Follow link? */);907 RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK /** @todo Follow link? */); 920 908 if (RT_FAILURE(rc2)) 921 909 { 922 910 if (!(fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE)) 923 RTMsgError("Cannot access '%s': No such file or directory\n", 924 pNodeIt->pszName); 911 RTMsgError("Cannot access '%s': No such file or directory\n", pNodeIt->pszName); 925 912 rc = VERR_FILE_NOT_FOUND; 926 913 /* Do not break here -- process every element in the list … … 929 916 else 930 917 { 931 rc2 = VBoxServiceToolboxPrintFsInfo(pNodeIt->pszName,932 933 934 918 rc2 = vgsvcToolboxPrintFsInfo(pNodeIt->pszName, 919 strlen(pNodeIt->pszName) /* cbName */, 920 fOutputFlags, 921 &objInfo); 935 922 if (RT_FAILURE(rc2)) 936 923 rc = rc2; … … 939 926 else 940 927 { 941 int rc2 = VBoxServiceToolboxLsHandleDir(pNodeIt->pszName, 942 fFlags, fOutputFlags); 928 int rc2 = vgsvcToolboxLsHandleDir(pNodeIt->pszName, fFlags, fOutputFlags); 943 929 if (RT_FAILURE(rc2)) 944 930 rc = rc2; … … 947 933 948 934 if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE) /* Output termination. */ 949 VBoxServiceToolboxPrintStrmTermination();935 vgsvcToolboxPrintStrmTermination(); 950 936 } 951 937 else if (fVerbose) 952 938 RTMsgError("Failed with rc=%Rrc\n", rc); 953 939 954 VBoxServiceToolboxPathBufDestroy(&fileList);940 vgsvcToolboxPathBufDestroy(&fileList); 955 941 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 956 942 } … … 958 944 959 945 /* Try using RTPathRmCmd. */ 960 static RTEXITCODE VBoxServiceToolboxRm(int argc, char **argv)946 static RTEXITCODE vgsvcToolboxRm(int argc, char **argv) 961 947 { 962 948 return RTPathRmCmd(argc, argv); … … 989 975 */ 990 976 static void toolboxMkTempReport(const char *pcszMessage, const char *pcszFile, 991 bool fActive, int rc, uint32_t fOutputFlags, 992 int *prc) 977 bool fActive, int rc, uint32_t fOutputFlags, int *prc) 993 978 { 994 979 if (!fActive) … … 1013 998 * @param argv Pointer to argument array. 1014 999 */ 1015 static RTEXITCODE VBoxServiceToolboxMkTemp(int argc, char **argv)1000 static RTEXITCODE vgsvcToolboxMkTemp(int argc, char **argv) 1016 1001 { 1017 1002 static const RTGETOPTDEF s_aOptions[] = … … 1039 1024 RTGETOPTUNION ValueUnion; 1040 1025 RTGETOPTSTATE GetState; 1041 rc = RTGetOptInit(&GetState, argc, argv, s_aOptions, 1042 RT_ELEMENTS(s_aOptions), 1 /*iFirst*/, 1043 RTGETOPTINIT_FLAGS_OPTS_FIRST); 1026 rc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1 /*iFirst*/, RTGETOPTINIT_FLAGS_OPTS_FIRST); 1044 1027 AssertRCReturn(rc, RTEXITCODE_INIT); 1045 1028 … … 1061 1044 { 1062 1045 case 'h': 1063 VBoxServiceToolboxShowUsageHeader();1046 vgsvcToolboxShowUsageHeader(); 1064 1047 RTPrintf("%s", g_paszMkTempHelp); 1065 1048 return RTEXITCODE_SUCCESS; 1066 1049 1067 1050 case 'V': 1068 VBoxServiceToolboxShowVersion();1051 vgsvcToolboxShowVersion(); 1069 1052 return RTEXITCODE_SUCCESS; 1070 1053 … … 1078 1061 1079 1062 case 'm': 1080 rc = v boxServiceToolboxParseMode(ValueUnion.psz, &fMode);1063 rc = vgsvcToolboxParseMode(ValueUnion.psz, &fMode); 1081 1064 if (RT_FAILURE(rc)) 1082 1065 return RTEXITCODE_SYNTAX; … … 1104 1087 } 1105 1088 } 1089 1106 1090 /* Print magic/version. */ 1107 1091 if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE) 1108 1092 { 1109 rc = VBoxServiceToolboxStrmInit();1093 rc = vgsvcToolboxStrmInit(); 1110 1094 if (RT_FAILURE(rc)) 1111 1095 RTMsgError("Error while initializing parseable streams, rc=%Rrc\n", rc); 1112 VBoxServiceToolboxPrintStrmHeader("vbt_mktemp", 1 /* Stream version */);1096 vgsvcToolboxPrintStrmHeader("vbt_mktemp", 1 /* Stream version */); 1113 1097 } 1114 1098 … … 1119 1103 return RTEXITCODE_SYNTAX; 1120 1104 } 1105 1121 1106 /* We need exactly one template, containing at least one 'X'. */ 1122 1107 if (cNonOptions != 1) 1123 1108 { 1124 toolboxMkTempReport("Please specify exactly one template.\n", "", 1125 true, VERR_INVALID_PARAMETER, fOutputFlags, &rc); 1109 toolboxMkTempReport("Please specify exactly one template.\n", "", true, VERR_INVALID_PARAMETER, fOutputFlags, &rc); 1126 1110 return RTEXITCODE_SYNTAX; 1127 1111 } 1128 1112 pcszTemplate = argv[argc - 1]; 1113 1129 1114 /* Validate that the template is as IPRT requires (asserted by IPRT). */ 1130 1115 if ( RTPathHasPath(pcszTemplate) … … 1133 1118 { 1134 1119 toolboxMkTempReport("Template '%s' should contain a file name with no path and at least three consecutive 'X' characters or ending in 'X'.\n", 1135 pcszTemplate, true, VERR_INVALID_PARAMETER, 1136 fOutputFlags, &rc); 1120 pcszTemplate, true, VERR_INVALID_PARAMETER, fOutputFlags, &rc); 1137 1121 return RTEXITCODE_FAILURE; 1138 1122 } 1139 1123 if (pcszPath && !RTPathStartsWithRoot(pcszPath)) 1140 1124 { 1141 toolboxMkTempReport("Path '%s' should be absolute.\n", 1142 pcszPath, true, VERR_INVALID_PARAMETER, 1143 fOutputFlags, &rc); 1125 toolboxMkTempReport("Path '%s' should be absolute.\n", pcszPath, true, VERR_INVALID_PARAMETER, fOutputFlags, &rc); 1144 1126 return RTEXITCODE_FAILURE; 1145 1127 } 1146 1128 if (pcszPath) 1147 1129 { 1148 rc = RTStrCopy(szTemplateWithPath, sizeof(szTemplateWithPath), 1149 pcszPath); 1130 rc = RTStrCopy(szTemplateWithPath, sizeof(szTemplateWithPath), pcszPath); 1150 1131 if (RT_FAILURE(rc)) 1151 1132 { 1152 toolboxMkTempReport("Path '%s' too long.\n", pcszPath, true, 1153 VERR_INVALID_PARAMETER, fOutputFlags, &rc); 1133 toolboxMkTempReport("Path '%s' too long.\n", pcszPath, true, VERR_INVALID_PARAMETER, fOutputFlags, &rc); 1154 1134 return RTEXITCODE_FAILURE; 1155 1135 } … … 1160 1140 if (RT_FAILURE(rc)) 1161 1141 { 1162 toolboxMkTempReport("Failed to get the temporary directory.\n", 1163 "", true, VERR_INVALID_PARAMETER, 1164 fOutputFlags, &rc); 1142 toolboxMkTempReport("Failed to get the temporary directory.\n", "", true, VERR_INVALID_PARAMETER, fOutputFlags, &rc); 1165 1143 return RTEXITCODE_FAILURE; 1166 1144 } 1167 1145 } 1168 rc = RTPathAppend(szTemplateWithPath, sizeof(szTemplateWithPath), 1169 pcszTemplate); 1146 rc = RTPathAppend(szTemplateWithPath, sizeof(szTemplateWithPath), pcszTemplate); 1170 1147 if (RT_FAILURE(rc)) 1171 1148 { 1172 toolboxMkTempReport("Template '%s' too long for path.\n", 1173 pcszTemplate, true, VERR_INVALID_PARAMETER, 1174 fOutputFlags, &rc); 1149 toolboxMkTempReport("Template '%s' too long for path.\n", pcszTemplate, true, VERR_INVALID_PARAMETER, fOutputFlags, &rc); 1175 1150 return RTEXITCODE_FAILURE; 1176 1151 } … … 1178 1153 if (fFlags & VBOXSERVICETOOLBOXMKTEMPFLAG_DIRECTORY) 1179 1154 { 1180 rc = 1181 1182 1155 rc = fFlags & VBOXSERVICETOOLBOXMKTEMPFLAG_SECURE 1156 ? RTDirCreateTempSecure(szTemplateWithPath) 1157 : RTDirCreateTemp(szTemplateWithPath, fMode); 1183 1158 toolboxMkTempReport("Created temporary directory '%s'.\n", 1184 1159 szTemplateWithPath, RT_SUCCESS(rc), rc, … … 1186 1161 /* RTDirCreateTemp[Secure] sets the template to "" on failure. */ 1187 1162 toolboxMkTempReport("The following error occurred while creating a temporary directory from template '%s': %Rrc.\n", 1188 pcszTemplate, RT_FAILURE(rc), rc, fOutputFlags, 1189 NULL); 1163 pcszTemplate, RT_FAILURE(rc), rc, fOutputFlags, NULL /*prc*/); 1190 1164 } 1191 1165 else 1192 1166 { 1193 rc = 1194 1195 1167 rc = fFlags & VBOXSERVICETOOLBOXMKTEMPFLAG_SECURE 1168 ? RTFileCreateTempSecure(szTemplateWithPath) 1169 : RTFileCreateTemp(szTemplateWithPath, fMode); 1196 1170 toolboxMkTempReport("Created temporary file '%s'.\n", 1197 1171 szTemplateWithPath, RT_SUCCESS(rc), rc, … … 1199 1173 /* RTFileCreateTemp[Secure] sets the template to "" on failure. */ 1200 1174 toolboxMkTempReport("The following error occurred while creating a temporary file from template '%s': %Rrc.\n", 1201 pcszTemplate, RT_FAILURE(rc), rc, fOutputFlags, 1202 NULL); 1175 pcszTemplate, RT_FAILURE(rc), rc, fOutputFlags, NULL /*prc*/); 1203 1176 } 1204 1177 if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE) /* Output termination. */ 1205 VBoxServiceToolboxPrintStrmTermination();1178 vgsvcToolboxPrintStrmTermination(); 1206 1179 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 1207 1180 } … … 1228 1201 * @param argv Pointer to argument array. 1229 1202 */ 1230 static RTEXITCODE VBoxServiceToolboxMkDir(int argc, char **argv)1203 static RTEXITCODE vgsvcToolboxMkDir(int argc, char **argv) 1231 1204 { 1232 1205 static const RTGETOPTDEF s_aOptions[] = … … 1240 1213 RTGETOPTUNION ValueUnion; 1241 1214 RTGETOPTSTATE GetState; 1242 int rc = RTGetOptInit(&GetState, argc, argv, 1243 s_aOptions, RT_ELEMENTS(s_aOptions), 1215 int rc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1244 1216 1 /*iFirst*/, RTGETOPTINIT_FLAGS_OPTS_FIRST); 1245 1217 AssertRCReturn(rc, RTEXITCODE_INIT); … … 1260 1232 1261 1233 case 'm': 1262 rc = v boxServiceToolboxParseMode(ValueUnion.psz, &fDirMode);1234 rc = vgsvcToolboxParseMode(ValueUnion.psz, &fDirMode); 1263 1235 if (RT_FAILURE(rc)) 1264 1236 return RTEXITCODE_SYNTAX; … … 1273 1245 1274 1246 case 'h': 1275 VBoxServiceToolboxShowUsageHeader();1247 vgsvcToolboxShowUsageHeader(); 1276 1248 RTPrintf("%s", g_paszMkDirHelp); 1277 1249 return RTEXITCODE_SUCCESS; 1278 1250 1279 1251 case 'V': 1280 VBoxServiceToolboxShowVersion();1252 vgsvcToolboxShowVersion(); 1281 1253 return RTEXITCODE_SUCCESS; 1282 1254 … … 1332 1304 * @param argv Pointer to argument array. 1333 1305 */ 1334 static RTEXITCODE VBoxServiceToolboxStat(int argc, char **argv)1306 static RTEXITCODE vgsvcToolboxStat(int argc, char **argv) 1335 1307 { 1336 1308 static const RTGETOPTDEF s_aOptions[] = … … 1346 1318 RTGETOPTUNION ValueUnion; 1347 1319 RTGETOPTSTATE GetState; 1348 RTGetOptInit(&GetState, argc, argv, 1349 s_aOptions, RT_ELEMENTS(s_aOptions), 1350 1 /*iFirst*/, RTGETOPTINIT_FLAGS_OPTS_FIRST); 1320 RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1 /*iFirst*/, RTGETOPTINIT_FLAGS_OPTS_FIRST); 1351 1321 1352 1322 int rc = VINF_SUCCESS; … … 1384 1354 1385 1355 case 'h': 1386 VBoxServiceToolboxShowUsageHeader();1356 vgsvcToolboxShowUsageHeader(); 1387 1357 RTPrintf("%s", g_paszStatHelp); 1388 1358 return RTEXITCODE_SUCCESS; 1389 1359 1390 1360 case 'V': 1391 VBoxServiceToolboxShowVersion();1361 vgsvcToolboxShowVersion(); 1392 1362 return RTEXITCODE_SUCCESS; 1393 1363 1394 1364 case VINF_GETOPT_NOT_OPTION: 1395 1365 { 1396 1366 /** @todo r=bird: The whole fileList is unecessary because you're using 1397 1367 * RTGETOPTINIT_FLAGS_OPTS_FIRST. You can obviously do the processing right … … 1399 1369 * continue there. */ 1400 1370 1401 1402 1403 1404 1405 1406 1407 rc = VBoxServiceToolboxPathBufAddPathEntry(&fileList, ValueUnion.psz);1408 1409 1371 /* Add file(s) to buffer. This enables processing multiple files 1372 * at once. 1373 * 1374 * Since the non-options (RTGETOPTINIT_FLAGS_OPTS_FIRST) come last when 1375 * processing this loop it's safe to immediately exit on syntax errors 1376 * or showing the help text (see above). */ 1377 rc = vgsvcToolboxPathBufAddPathEntry(&fileList, ValueUnion.psz); 1378 break; 1379 } 1410 1380 1411 1381 default: … … 1418 1388 if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE) /* Output termination. */ 1419 1389 { 1420 rc = VBoxServiceToolboxStrmInit();1390 rc = vgsvcToolboxStrmInit(); 1421 1391 if (RT_FAILURE(rc)) 1422 1392 RTMsgError("Error while initializing parseable streams, rc=%Rrc\n", rc); 1423 VBoxServiceToolboxPrintStrmHeader("vbt_stat", 1 /* Stream version */);1393 vgsvcToolboxPrintStrmHeader("vbt_stat", 1 /* Stream version */); 1424 1394 } 1425 1395 … … 1433 1403 /** @todo r=bird: You can get a number of other errors here, like access denied. */ 1434 1404 if (!(fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE)) 1435 RTMsgError("Cannot stat for '%s': No such file or directory (%Rrc)\n", 1436 pNodeIt->pszName, rc); 1405 RTMsgError("Cannot stat for '%s': No such file or directory (%Rrc)\n", pNodeIt->pszName, rc); 1437 1406 rc = VERR_FILE_NOT_FOUND; 1438 1407 /* Do not break here -- process every element in the list … … 1441 1410 else 1442 1411 { 1443 rc2 = VBoxServiceToolboxPrintFsInfo(pNodeIt->pszName,1444 1445 1446 1412 rc2 = vgsvcToolboxPrintFsInfo(pNodeIt->pszName, 1413 strlen(pNodeIt->pszName) /* cbName */, 1414 fOutputFlags, 1415 &objInfo); 1447 1416 if (RT_FAILURE(rc2)) 1448 1417 rc = rc2; … … 1451 1420 1452 1421 if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE) /* Output termination. */ 1453 VBoxServiceToolboxPrintStrmTermination();1422 vgsvcToolboxPrintStrmTermination(); 1454 1423 1455 1424 /* At this point the overall result (success/failure) should be in rc. */ … … 1461 1430 RTMsgError("Failed with rc=%Rrc\n", rc); 1462 1431 1463 VBoxServiceToolboxPathBufDestroy(&fileList);1432 vgsvcToolboxPathBufDestroy(&fileList); 1464 1433 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 1465 1434 } … … 1473 1442 * @param pszTool The name of the tool. 1474 1443 */ 1475 static PFNHANDLER v boxServiceToolboxLookUpHandler(const char *pszTool)1444 static PFNHANDLER vgsvcToolboxLookUpHandler(const char *pszTool) 1476 1445 { 1477 1446 static struct … … 1482 1451 const s_aTools[] = 1483 1452 { 1484 { "cat", VBoxServiceToolboxCat },1485 { "ls", VBoxServiceToolboxLs },1486 { "rm", VBoxServiceToolboxRm },1487 { "mktemp", VBoxServiceToolboxMkTemp },1488 { "mkdir", VBoxServiceToolboxMkDir },1489 { "stat", VBoxServiceToolboxStat },1453 { "cat", vgsvcToolboxCat }, 1454 { "ls", vgsvcToolboxLs }, 1455 { "rm", vgsvcToolboxRm }, 1456 { "mktemp", vgsvcToolboxMkTemp }, 1457 { "mkdir", vgsvcToolboxMkDir }, 1458 { "stat", vgsvcToolboxStat }, 1490 1459 }; 1491 1460 … … 1516 1485 * internal toolbox command was handled. 1517 1486 */ 1518 bool V BoxServiceToolboxMain(int argc, char **argv, RTEXITCODE *prcExit)1487 bool VGSvcToolboxMain(int argc, char **argv, RTEXITCODE *prcExit) 1519 1488 { 1520 1489 … … 1524 1493 AssertReturn(argc > 0, false); 1525 1494 const char *pszTool = RTPathFilename(argv[0]); 1526 PFNHANDLER pfnHandler = v boxServiceToolboxLookUpHandler(pszTool);1495 PFNHANDLER pfnHandler = vgsvcToolboxLookUpHandler(pszTool); 1527 1496 if (!pfnHandler) 1528 1497 { … … 1536 1505 argv += 2; 1537 1506 pszTool = argv[0]; 1538 pfnHandler = v boxServiceToolboxLookUpHandler(pszTool);1507 pfnHandler = vgsvcToolboxLookUpHandler(pszTool); 1539 1508 if (!pfnHandler) 1540 1509 { … … 1542 1511 if (!strcmp(pszTool, "-V")) 1543 1512 { 1544 VBoxServiceToolboxShowVersion();1513 vgsvcToolboxShowVersion(); 1545 1514 return true; 1546 1515 } … … 1548 1517 && (strcmp(pszTool, "-h"))) 1549 1518 *prcExit = RTEXITCODE_SYNTAX; 1550 VBoxServiceToolboxShowUsage();1519 vgsvcToolboxShowUsage(); 1551 1520 return true; 1552 1521 } -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceUtils.cpp
r57358 r58029 32 32 #include "VBoxServiceInternal.h" 33 33 34 34 35 #ifdef VBOX_WITH_GUEST_PROPS 35 36 … … 48 49 * on success. Optional. 49 50 */ 50 int VBoxServiceReadProp(uint32_t u32ClientId, const char *pszPropName, 51 char **ppszValue, char **ppszFlags, uint64_t *puTimestamp) 51 int VGSvcReadProp(uint32_t u32ClientId, const char *pszPropName, char **ppszValue, char **ppszFlags, uint64_t *puTimestamp) 52 52 { 53 53 AssertPtrReturn(pszPropName, VERR_INVALID_POINTER); … … 69 69 if (!pvBuf) 70 70 { 71 V BoxServiceError("Guest Property: Failed to allocate %zu bytes\n", cbBuf);71 VGSvcError("Guest Property: Failed to allocate %zu bytes\n", cbBuf); 72 72 rc = VERR_NO_MEMORY; 73 73 break; … … 76 76 char *pszFlags; 77 77 uint64_t uTimestamp; 78 rc = VbglR3GuestPropRead(u32ClientId, pszPropName, 79 pvBuf, cbBuf, 80 &pszValue, &uTimestamp, &pszFlags, NULL); 78 rc = VbglR3GuestPropRead(u32ClientId, pszPropName, pvBuf, cbBuf, &pszValue, &uTimestamp, &pszFlags, NULL); 81 79 if (RT_FAILURE(rc)) 82 80 { … … 88 86 } 89 87 if (rc == VERR_NOT_FOUND) 90 V BoxServiceVerbose(2, "Guest Property: %s not found\n", pszPropName);88 VGSvcVerbose(2, "Guest Property: %s not found\n", pszPropName); 91 89 else 92 V BoxServiceError("Guest Property: Failed to query \"%s\": %Rrc\n", pszPropName, rc);90 VGSvcError("Guest Property: Failed to query '%s': %Rrc\n", pszPropName, rc); 93 91 break; 94 92 } 95 93 96 VBoxServiceVerbose(2, "Guest Property: Read \"%s\" = \"%s\", timestamp %RU64n\n", 97 pszPropName, pszValue, uTimestamp); 94 VGSvcVerbose(2, "Guest Property: Read '%s' = '%s', timestamp %RU64n\n", pszPropName, pszValue, uTimestamp); 98 95 *ppszValue = RTStrDup(pszValue); 99 96 if (!*ppszValue) 100 97 { 101 V BoxServiceError("Guest Property: RTStrDup failed for \"%s\"\n", pszValue);98 VGSvcError("Guest Property: RTStrDup failed for '%s'\n", pszValue); 102 99 rc = VERR_NO_MEMORY; 103 100 break; … … 127 124 * 128 125 */ 129 int VBoxServiceReadPropUInt32(uint32_t u32ClientId, const char *pszPropName, 130 uint32_t *pu32, uint32_t u32Min, uint32_t u32Max) 126 int VGSvcReadPropUInt32(uint32_t u32ClientId, const char *pszPropName, uint32_t *pu32, uint32_t u32Min, uint32_t u32Max) 131 127 { 132 128 char *pszValue; 133 int rc = VBoxServiceReadProp(u32ClientId, pszPropName, &pszValue, 134 NULL /* ppszFlags */, NULL /* puTimestamp */); 129 int rc = VGSvcReadProp(u32ClientId, pszPropName, &pszValue, NULL /* ppszFlags */, NULL /* puTimestamp */); 135 130 if (RT_SUCCESS(rc)) 136 131 { … … 139 134 if ( RT_SUCCESS(rc) 140 135 && (*pu32 < u32Min || *pu32 > u32Max)) 141 { 142 rc = VBoxServiceError("The guest property value %s = %RU32 is out of range [%RU32..%RU32].\n", 143 pszPropName, *pu32, u32Min, u32Max); 144 } 136 rc = VGSvcError("The guest property value %s = %RU32 is out of range [%RU32..%RU32].\n", 137 pszPropName, *pu32, u32Min, u32Max); 145 138 RTStrFree(pszValue); 146 139 } … … 165 158 * on success. Optional. 166 159 */ 167 int V BoxServiceReadHostProp(uint32_t u32ClientId, const char *pszPropName, bool fReadOnly,168 160 int VGSvcReadHostProp(uint32_t u32ClientId, const char *pszPropName, bool fReadOnly, 161 char **ppszValue, char **ppszFlags, uint64_t *puTimestamp) 169 162 { 170 163 AssertPtrReturn(ppszValue, VERR_INVALID_PARAMETER); … … 172 165 char *pszValue = NULL; 173 166 char *pszFlags = NULL; 174 int rc = V BoxServiceReadProp(u32ClientId, pszPropName, &pszValue, &pszFlags, puTimestamp);167 int rc = VGSvcReadProp(u32ClientId, pszPropName, &pszValue, &pszFlags, puTimestamp); 175 168 if (RT_SUCCESS(rc)) 176 169 { … … 218 211 * @param ... Format arguments. 219 212 */ 220 int V BoxServiceWritePropF(uint32_t u32ClientId, const char *pszName, const char *pszValueFormat, ...)213 int VGSvcWritePropF(uint32_t u32ClientId, const char *pszName, const char *pszValueFormat, ...) 221 214 { 222 215 AssertPtr(pszName); … … 226 219 va_list va; 227 220 va_start(va, pszValueFormat); 228 V BoxServiceVerbose(3, "Writing guest property \"%s\" = \"%N\"\n", pszName, pszValueFormat, &va);221 VGSvcVerbose(3, "Writing guest property '%s' = '%N'\n", pszName, pszValueFormat, &va); 229 222 va_end(va); 230 223 … … 234 227 235 228 if (RT_FAILURE(rc)) 236 V BoxServiceError("Error writing guest property \"%s\"(rc=%Rrc)\n", pszName, rc);229 VGSvcError("Error writing guest property '%s' (rc=%Rrc)\n", pszName, rc); 237 230 } 238 231 else 239 232 { 240 V BoxServiceVerbose(3, "Deleting guest property \"%s\"\n", pszName);233 VGSvcVerbose(3, "Deleting guest property '%s'\n", pszName); 241 234 rc = VbglR3GuestPropWriteValue(u32ClientId, pszName, NULL); 242 235 if (RT_FAILURE(rc)) 243 V BoxServiceError("Error deleting guest property \"%s\"(rc=%Rrc)\n", pszName, rc);236 VGSvcError("Error deleting guest property '%s' (rc=%Rrc)\n", pszName, rc); 244 237 } 245 238 return rc; … … 255 248 * @returns Success indicator. 256 249 */ 257 static bool VBoxServiceGetFileVersionOwn(LPSTR pVerData, 258 PDWORD pdwMajor, 259 PDWORD pdwMinor, 260 PDWORD pdwBuildNumber, 261 PDWORD pdwRevisionNumber) 250 static bool vgsvcUtilGetFileVersionOwn(LPSTR pVerData, PDWORD pdwMajor, PDWORD pdwMinor, PDWORD pdwBuildNumber, 251 PDWORD pdwRevisionNumber) 262 252 { 263 253 UINT cchStrValue = 0; … … 275 265 276 266 /** 277 * Worker for V BoxServiceGetFileVersionString.267 * Worker for VGSvcUtilWinGetFileVersionString. 278 268 * 279 269 * @returns VBox status code. 280 270 * @param pszFilename ASCII & ANSI & UTF-8 compliant name. 281 271 */ 282 static int VBoxServiceGetFileVersion(const char *pszFilename, 283 PDWORD pdwMajor, 284 PDWORD pdwMinor, 285 PDWORD pdwBuildNumber, 286 PDWORD pdwRevisionNumber) 272 static int vgsvcUtilGetFileVersion(const char *pszFilename, PDWORD pdwMajor, PDWORD pdwMinor, PDWORD pdwBuildNumber, 273 PDWORD pdwRevisionNumber) 287 274 { 288 275 int rc; … … 307 294 * it goes beyond the range of an uint16_t / WORD. 308 295 */ 309 if ( VBoxServiceGetFileVersionOwn(pVerData, pdwMajor, pdwMinor, pdwBuildNumber, pdwRevisionNumber))296 if (vgsvcUtilGetFileVersionOwn(pVerData, pdwMajor, pdwMinor, pdwBuildNumber, pdwRevisionNumber)) 310 297 rc = VINF_SUCCESS; 311 298 else … … 325 312 { 326 313 rc = RTErrConvertFromWin32(GetLastError()); 327 V BoxServiceVerbose(3, "No file version value for file \"%s\"available! (%d / rc=%Rrc)\n",328 314 VGSvcVerbose(3, "No file version value for file '%s' available! (%d / rc=%Rrc)\n", 315 pszFilename, GetLastError(), rc); 329 316 } 330 317 } … … 333 320 { 334 321 rc = RTErrConvertFromWin32(GetLastError()); 335 V BoxServiceVerbose(0, "GetFileVersionInfo(%s) -> %u / %Rrc\n", pszFilename, GetLastError(), rc);322 VGSvcVerbose(0, "GetFileVersionInfo(%s) -> %u / %Rrc\n", pszFilename, GetLastError(), rc); 336 323 } 337 324 … … 340 327 else 341 328 { 342 V BoxServiceVerbose(0, "Failed to allocate %u byte for file version info for '%s'\n", cbVerData, pszFilename);329 VGSvcVerbose(0, "Failed to allocate %u byte for file version info for '%s'\n", cbVerData, pszFilename); 343 330 rc = VERR_NO_TMP_MEMORY; 344 331 } … … 347 334 { 348 335 rc = RTErrConvertFromWin32(GetLastError()); 349 V BoxServiceVerbose(3, "GetFileVersionInfoSize(%s) -> %u / %Rrc\n", pszFilename, GetLastError(), rc);336 VGSvcVerbose(3, "GetFileVersionInfoSize(%s) -> %u / %Rrc\n", pszFilename, GetLastError(), rc); 350 337 } 351 338 return rc; … … 365 352 * at least 2 bytes! 366 353 */ 367 int VBoxServiceGetFileVersionString(const char *pszPath, const char *pszFilename, 368 char *pszVersion, size_t cbVersion) 354 int VGSvcUtilWinGetFileVersionString(const char *pszPath, const char *pszFilename, char *pszVersion, size_t cbVersion) 369 355 { 370 356 /* … … 383 369 { 384 370 DWORD dwMajor, dwMinor, dwBuild, dwRev; 385 rc = VBoxServiceGetFileVersion(szFullPath, &dwMajor, &dwMinor, &dwBuild, &dwRev);371 rc = vgsvcUtilGetFileVersion(szFullPath, &dwMajor, &dwMinor, &dwBuild, &dwRev); 386 372 if (RT_SUCCESS(rc)) 387 373 RTStrPrintf(pszVersion, cbVersion, "%u.%u.%ur%u", dwMajor, dwMinor, dwBuild, dwRev); -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceUtils.h
r56294 r58029 22 22 23 23 #ifdef VBOX_WITH_GUEST_PROPS 24 int VBoxServiceReadProp(uint32_t u32ClientId, const char *pszPropName, char **ppszValue, char **ppszFlags, uint64_t *puTimestamp); 25 int VBoxServiceReadPropUInt32(uint32_t u32ClientId, const char *pszPropName, uint32_t *pu32, uint32_t u32Min, uint32_t u32Max); 26 int VBoxServiceReadHostProp(uint32_t u32ClientId, const char *pszPropName, bool fReadOnly, char **ppszValue, char **ppszFlags, uint64_t *puTimestamp); 27 int VBoxServiceWritePropF(uint32_t u32ClientId, const char *pszName, const char *pszValueFormat, ...); 24 int VGSvcReadProp(uint32_t u32ClientId, const char *pszPropName, char **ppszValue, char **ppszFlags, uint64_t *puTimestamp); 25 int VGSvcReadPropUInt32(uint32_t u32ClientId, const char *pszPropName, uint32_t *pu32, uint32_t u32Min, uint32_t u32Max); 26 int VGSvcReadHostProp(uint32_t u32ClientId, const char *pszPropName, bool fReadOnly, char **ppszValue, char **ppszFlags, 27 uint64_t *puTimestamp); 28 int VGSvcWritePropF(uint32_t u32ClientId, const char *pszName, const char *pszValueFormat, ...); 28 29 #endif 29 30 30 31 #ifdef RT_OS_WINDOWS 31 int V BoxServiceGetFileVersionString(const char *pszPath, const char *pszFileName, char *pszVersion, size_t cbVersion);32 int VGSvcUtilWinGetFileVersionString(const char *pszPath, const char *pszFileName, char *pszVersion, size_t cbVersion); 32 33 #endif 33 34 -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo-win.cpp
r57925 r58029 95 95 * Internal Functions * 96 96 *********************************************************************************************************************************/ 97 static uint32_t VBoxServiceVMInfoWinSessionHasProcesses(PLUID pSession, PVBOXSERVICEVMINFOPROC const paProcs, DWORD cProcs);98 static bool VBoxServiceVMInfoWinIsLoggedIn(PVBOXSERVICEVMINFOUSER a_pUserInfo, PLUID a_pSession);99 static int VBoxServiceVMInfoWinProcessesEnumerate(PVBOXSERVICEVMINFOPROC *ppProc, DWORD *pdwCount);100 static void VBoxServiceVMInfoWinProcessesFree(DWORD cProcs, PVBOXSERVICEVMINFOPROC paProcs);101 static int v boxServiceVMInfoWinWriteLastInput(PVBOXSERVICEVEPROPCACHE pCache, const char *pszUser, const char *pszDomain);97 static uint32_t vgsvcVMInfoWinSessionHasProcesses(PLUID pSession, PVBOXSERVICEVMINFOPROC const paProcs, DWORD cProcs); 98 static bool vgsvcVMInfoWinIsLoggedIn(PVBOXSERVICEVMINFOUSER a_pUserInfo, PLUID a_pSession); 99 static int vgsvcVMInfoWinProcessesEnumerate(PVBOXSERVICEVMINFOPROC *ppProc, DWORD *pdwCount); 100 static void vgsvcVMInfoWinProcessesFree(DWORD cProcs, PVBOXSERVICEVMINFOPROC paProcs); 101 static int vgsvcVMInfoWinWriteLastInput(PVBOXSERVICEVEPROPCACHE pCache, const char *pszUser, const char *pszDomain); 102 102 103 103 … … 156 156 if (RT_FAILURE(rc)) 157 157 { 158 V BoxServiceVerbose(1, "Secur32.dll APIs are not availble (%Rrc)\n", rc);158 VGSvcVerbose(1, "Secur32.dll APIs are not availble (%Rrc)\n", rc); 159 159 g_pfnLsaGetLogonSessionData = NULL; 160 160 g_pfnLsaEnumerateLogonSessions = NULL; … … 175 175 if (RT_FAILURE(rc)) 176 176 { 177 V BoxServiceVerbose(1, "WtsApi32.dll APIs are not availble (%Rrc)\n", rc);177 VGSvcVerbose(1, "WtsApi32.dll APIs are not availble (%Rrc)\n", rc); 178 178 g_pfnWTSFreeMemory = NULL; 179 179 g_pfnWTSQuerySessionInformationA = NULL; … … 193 193 if (RT_FAILURE(rc)) 194 194 { 195 V BoxServiceVerbose(1, "psapi.dll APIs are not availble (%Rrc)\n", rc);195 VGSvcVerbose(1, "psapi.dll APIs are not availble (%Rrc)\n", rc); 196 196 g_pfnEnumProcesses = NULL; 197 197 g_pfnGetModuleFileNameExW = NULL; … … 227 227 228 228 229 static bool v boxServiceVMInfoSession0Separation(void)229 static bool vgsvcVMInfoSession0Separation(void) 230 230 { 231 231 return g_WinVersion.dwPlatformId == VER_PLATFORM_WIN32_NT … … 239 239 * @return IPRT status code. 240 240 */ 241 static int VBoxServiceVMInfoWinProcessesGetModuleNameA(PVBOXSERVICEVMINFOPROC const pProc, 242 PRTUTF16 *ppszName) 241 static int vgsvcVMInfoWinProcessesGetModuleNameA(PVBOXSERVICEVMINFOPROC const pProc, PRTUTF16 *ppszName) 243 242 { 244 243 AssertPtrReturn(pProc, VERR_INVALID_POINTER); … … 261 260 DWORD dwErr = GetLastError(); 262 261 if (g_cVerbosity) 263 VBoxServiceError("Unable to open process with PID=%ld, error=%ld\n", 264 pProc->id, dwErr); 262 VGSvcError("Unable to open process with PID=%u, error=%u\n", pProc->id, dwErr); 265 263 rc = RTErrConvertFromWin32(dwErr); 266 264 } … … 283 281 if ( RT_FAILURE(rc) 284 282 && g_cVerbosity > 3) 285 { 286 VBoxServiceError("Unable to retrieve process name for PID=%ld, error=%ld\n", 287 pProc->id, GetLastError()); 288 } 283 VGSvcError("Unable to retrieve process name for PID=%u, error=%u\n", pProc->id, GetLastError()); 289 284 else 290 285 { … … 310 305 * @param tkClass The kind of token information to get. 311 306 */ 312 static int VBoxServiceVMInfoWinProcessesGetTokenInfo(PVBOXSERVICEVMINFOPROC pProc, 313 TOKEN_INFORMATION_CLASS tkClass) 307 static int vgsvcVMInfoWinProcessesGetTokenInfo(PVBOXSERVICEVMINFOPROC pProc, TOKEN_INFORMATION_CLASS tkClass) 314 308 { 315 309 AssertPtrReturn(pProc, VERR_INVALID_POINTER); … … 321 315 dwErr = GetLastError(); 322 316 if (g_cVerbosity > 4) 323 VBoxServiceError("Unable to open process with PID=%ld, error=%ld\n", 324 pProc->id, dwErr); 317 VGSvcError("Unable to open process with PID=%u, error=%u\n", pProc->id, dwErr); 325 318 return RTErrConvertFromWin32(dwErr); 326 319 } … … 335 328 { 336 329 case TokenStatistics: 330 /** @todo r=bird: Someone has been reading too many MSDN examples. You shall 331 * use RTMemAlloc here! There is absolutely not reason for 332 * complicating things uncessarily by using HeapAlloc! */ 337 333 dwTokenInfoSize = sizeof(TOKEN_STATISTICS); 338 pvTokenInfo = HeapAlloc(GetProcessHeap(), 339 HEAP_ZERO_MEMORY, dwTokenInfoSize); 334 pvTokenInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwTokenInfoSize); 340 335 AssertPtr(pvTokenInfo); 341 336 break; … … 352 347 353 348 default: 354 V BoxServiceError("Token class not implemented: %ld\n", tkClass);349 VGSvcError("Token class not implemented: %d\n", tkClass); 355 350 rc = VERR_NOT_IMPLEMENTED; 356 351 break; … … 370 365 { 371 366 case TokenGroups: 372 pvTokenInfo = (PTOKEN_GROUPS)HeapAlloc(GetProcessHeap(), 373 HEAP_ZERO_MEMORY, dwRetLength); 367 pvTokenInfo = (PTOKEN_GROUPS)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwRetLength); 374 368 if (!pvTokenInfo) 375 369 dwErr = GetLastError(); … … 378 372 379 373 case TokenUser: 380 pvTokenInfo = (PTOKEN_USER)HeapAlloc(GetProcessHeap(), 381 HEAP_ZERO_MEMORY, dwRetLength); 374 pvTokenInfo = (PTOKEN_USER)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwRetLength); 382 375 if (!pvTokenInfo) 383 376 dwErr = GetLastError(); … … 478 471 if (dwErr != ERROR_SUCCESS) 479 472 { 480 VBoxServiceError("Error retrieving SID of process PID=%ld: %ld\n", 481 pProc->id, dwErr); 473 VGSvcError("Error retrieving SID of process PID=%u: %u\n", pProc->id, dwErr); 482 474 if (pProc->pSid) 483 475 { … … 506 498 { 507 499 if (g_cVerbosity) 508 VBoxServiceError("Unable to query token information for PID=%ld, error=%ld\n", 509 pProc->id, dwErr); 500 VGSvcError("Unable to query token information for PID=%u, error=%u\n", pProc->id, dwErr); 510 501 rc = RTErrConvertFromWin32(dwErr); 511 502 } … … 526 517 * @param pcProcs Where to store the returned process count. 527 518 */ 528 static int VBoxServiceVMInfoWinProcessesEnumerate(PVBOXSERVICEVMINFOPROC *ppaProcs, PDWORD pcProcs)519 static int vgsvcVMInfoWinProcessesEnumerate(PVBOXSERVICEVMINFOPROC *ppaProcs, PDWORD pcProcs) 529 520 { 530 521 AssertPtr(ppaProcs); … … 582 573 paProcs[i].pSid = NULL; 583 574 584 int rc2 = VBoxServiceVMInfoWinProcessesGetTokenInfo(&paProcs[i], TokenUser);575 int rc2 = vgsvcVMInfoWinProcessesGetTokenInfo(&paProcs[i], TokenUser); 585 576 if (RT_FAILURE(rc2) && g_cVerbosity) 586 VBoxServiceError("Get token class \"user\" for process %ld failed, rc=%Rrc\n", 587 paProcs[i].id, rc2); 588 589 rc2 = VBoxServiceVMInfoWinProcessesGetTokenInfo(&paProcs[i], TokenGroups); 577 VGSvcError("Get token class 'user' for process %u failed, rc=%Rrc\n", paProcs[i].id, rc2); 578 579 rc2 = vgsvcVMInfoWinProcessesGetTokenInfo(&paProcs[i], TokenGroups); 590 580 if (RT_FAILURE(rc2) && g_cVerbosity) 591 VBoxServiceError("Get token class \"groups\" for process %ld failed, rc=%Rrc\n", 592 paProcs[i].id, rc2); 593 594 rc2 = VBoxServiceVMInfoWinProcessesGetTokenInfo(&paProcs[i], TokenStatistics); 581 VGSvcError("Get token class 'groups' for process %u failed, rc=%Rrc\n", paProcs[i].id, rc2); 582 583 rc2 = vgsvcVMInfoWinProcessesGetTokenInfo(&paProcs[i], TokenStatistics); 595 584 if (RT_FAILURE(rc2) && g_cVerbosity) 596 VBoxServiceError("Get token class \"statistics\" for process %ld failed, rc=%Rrc\n", 597 paProcs[i].id, rc2); 585 VGSvcError("Get token class 'statistics' for process %u failed, rc=%Rrc\n", paProcs[i].id, rc2); 598 586 } 599 587 … … 605 593 } 606 594 else 607 VBoxServiceVMInfoWinProcessesFree(cProcesses, paProcs);595 vgsvcVMInfoWinProcessesFree(cProcesses, paProcs); 608 596 } 609 597 else … … 617 605 /** 618 606 * Frees the process structures returned by 619 * VBoxServiceVMInfoWinProcessesEnumerate() before.607 * vgsvcVMInfoWinProcessesEnumerate() before. 620 608 * 621 609 * @param paProcs What 622 610 */ 623 static void VBoxServiceVMInfoWinProcessesFree(DWORD cProcs, PVBOXSERVICEVMINFOPROC paProcs)611 static void vgsvcVMInfoWinProcessesFree(DWORD cProcs, PVBOXSERVICEVMINFOPROC paProcs) 624 612 { 625 613 for (DWORD i = 0; i < cProcs; i++) … … 644 632 * @param puSession Looked up session number. Optional. 645 633 */ 646 static uint32_t VBoxServiceVMInfoWinSessionHasProcesses(PLUID pSession, 647 PVBOXSERVICEVMINFOPROC const paProcs, DWORD cProcs, 648 PULONG puTerminalSession) 634 static uint32_t vgsvcVMInfoWinSessionHasProcesses(PLUID pSession, 635 PVBOXSERVICEVMINFOPROC const paProcs, DWORD cProcs, PULONG puTerminalSession) 649 636 { 650 637 if (!pSession) 651 638 { 652 V BoxServiceVerbose(1, "Session became invalid while enumerating!\n");639 VGSvcVerbose(1, "Session became invalid while enumerating!\n"); 653 640 return 0; 654 641 } … … 660 647 if (rcNt != STATUS_SUCCESS) 661 648 { 662 V BoxServiceError("Could not get logon session data! rcNt=%#x\n", rcNt);649 VGSvcError("Could not get logon session data! rcNt=%#x\n", rcNt); 663 650 return 0; 664 651 } … … 666 653 if (!IsValidSid(pSessionData->Sid)) 667 654 { 668 V BoxServiceError("User SID=%p is not valid\n", pSessionData->Sid);655 VGSvcError("User SID=%p is not valid\n", pSessionData->Sid); 669 656 if (pSessionData) 670 657 g_pfnLsaFreeReturnBuffer(pSessionData); … … 692 679 { 693 680 PRTUTF16 pszName; 694 int rc2 = VBoxServiceVMInfoWinProcessesGetModuleNameA(&paProcs[i], &pszName);695 V BoxServiceVerbose(4, "Session %RU32: PID=%ld(fInt=%RTbool): %ls\n",696 697 681 int rc2 = vgsvcVMInfoWinProcessesGetModuleNameA(&paProcs[i], &pszName); 682 VGSvcVerbose(4, "Session %RU32: PID=%u (fInt=%RTbool): %ls\n", 683 pSessionData->Session, paProcs[i].id, paProcs[i].fInteractive, 684 RT_SUCCESS(rc2) ? pszName : L"<Unknown>"); 698 685 if (RT_SUCCESS(rc2)) 699 686 RTUtf16Free(pszName); … … 727 714 * @param pszWhat What this is. For the log. 728 715 */ 729 static void VBoxServiceVMInfoWinSafeCopy(PWCHAR pwszDst, size_t cbDst, LSA_UNICODE_STRING const *pSrc, const char *pszWhat)716 static void vgsvcVMInfoWinSafeCopy(PWCHAR pwszDst, size_t cbDst, LSA_UNICODE_STRING const *pSrc, const char *pszWhat) 730 717 { 731 718 Assert(RT_ALIGN(cbDst, sizeof(WCHAR)) == cbDst); … … 734 721 if (cbCopy + sizeof(WCHAR) > cbDst) 735 722 { 736 VBoxServiceVerbose(0, "%s is too long - %u bytes, buffer %u bytes! It will be truncated.\n", 737 pszWhat, cbCopy, cbDst); 723 VGSvcVerbose(0, "%s is too long - %u bytes, buffer %u bytes! It will be truncated.\n", pszWhat, cbCopy, cbDst); 738 724 cbCopy = cbDst - sizeof(WCHAR); 739 725 } … … 751 737 * @param pSession The session to check. 752 738 */ 753 static bool VBoxServiceVMInfoWinIsLoggedIn(PVBOXSERVICEVMINFOUSER pUserInfo, PLUID pSession)739 static bool vgsvcVMInfoWinIsLoggedIn(PVBOXSERVICEVMINFOUSER pUserInfo, PLUID pSession) 754 740 { 755 741 AssertPtrReturn(pUserInfo, false); … … 769 755 /* If we don't have enough memory it's hard to judge whether the specified user 770 756 * is logged in or not, so just assume he/she's not. */ 771 V BoxServiceVerbose(3, "Not enough memory to retrieve logon session data!\n");757 VGSvcVerbose(3, "Not enough memory to retrieve logon session data!\n"); 772 758 break; 773 759 … … 778 764 779 765 default: 780 V BoxServiceError("LsaGetLogonSessionData failed with error %u\n", ulError);766 VGSvcError("LsaGetLogonSessionData failed with error %u\n", ulError); 781 767 break; 782 768 } … … 787 773 if (!pSessionData) 788 774 { 789 V BoxServiceError("Invalid logon session data!\n");775 VGSvcError("Invalid logon session data!\n"); 790 776 return false; 791 777 } 792 778 793 VBoxServiceVerbose(3, "Session data: Name=%ls, SessionID=%RU32, LogonID=%ld,%ld, LogonType=%ld\n", 794 pSessionData->UserName.Buffer, 795 pSessionData->Session, 796 pSessionData->LogonId.HighPart, pSessionData->LogonId.LowPart, 797 pSessionData->LogonType); 798 799 if (vboxServiceVMInfoSession0Separation()) 779 VGSvcVerbose(3, "Session data: Name=%ls, SessionID=%RU32, LogonID=%d,%u, LogonType=%u\n", 780 pSessionData->UserName.Buffer, pSessionData->Session, 781 pSessionData->LogonId.HighPart, pSessionData->LogonId.LowPart, pSessionData->LogonType); 782 783 if (vgsvcVMInfoSession0Separation()) 800 784 { 801 785 /* Starting at Windows Vista user sessions begin with session 1, so 802 786 * ignore (stale) session 0 users. */ 803 787 if ( pSessionData->Session == 0 804 /* Also check the logon time. */788 /* Also check the logon time. */ 805 789 || pSessionData->LogonTime.QuadPart == 0) 806 790 { … … 823 807 || (SECURITY_LOGON_TYPE)pSessionData->LogonType == CachedInteractive)) 824 808 { 825 VBoxServiceVerbose(3, "Session LogonType=%ld is supported -- looking up SID + type ...\n", 826 pSessionData->LogonType); 809 VGSvcVerbose(3, "Session LogonType=%u is supported -- looking up SID + type ...\n", pSessionData->LogonType); 827 810 828 811 /* 829 812 * Copy out relevant data. 830 813 */ 831 VBoxServiceVMInfoWinSafeCopy(pUserInfo->wszUser, sizeof(pUserInfo->wszUser), 832 &pSessionData->UserName, "User name"); 833 VBoxServiceVMInfoWinSafeCopy(pUserInfo->wszAuthenticationPackage, sizeof(pUserInfo->wszAuthenticationPackage), 834 &pSessionData->AuthenticationPackage, "Authentication pkg name"); 835 VBoxServiceVMInfoWinSafeCopy(pUserInfo->wszLogonDomain, sizeof(pUserInfo->wszLogonDomain), 836 &pSessionData->LogonDomain, "Logon domain name"); 814 vgsvcVMInfoWinSafeCopy(pUserInfo->wszUser, sizeof(pUserInfo->wszUser), &pSessionData->UserName, "User name"); 815 vgsvcVMInfoWinSafeCopy(pUserInfo->wszAuthenticationPackage, sizeof(pUserInfo->wszAuthenticationPackage), 816 &pSessionData->AuthenticationPackage, "Authentication pkg name"); 817 vgsvcVMInfoWinSafeCopy(pUserInfo->wszLogonDomain, sizeof(pUserInfo->wszLogonDomain), 818 &pSessionData->LogonDomain, "Logon domain name"); 837 819 838 820 TCHAR szOwnerName[_MAX_PATH] = { 0 }; … … 857 839 */ 858 840 if (dwErr != ERROR_NONE_MAPPED) 859 VBoxServiceError("Failed looking up account info for user=%ls, error=$ld!\n", 860 pUserInfo->wszUser, dwErr); 841 VGSvcError("Failed looking up account info for user=%ls, error=$ld!\n", pUserInfo->wszUser, dwErr); 861 842 } 862 843 else … … 864 845 if (enmOwnerType == SidTypeUser) /* Only recognize users; we don't care about the rest! */ 865 846 { 866 VBoxServiceVerbose(3, "Account User=%ls, Session=%ld, LogonID=%ld,%ld, AuthPkg=%ls, Domain=%ls\n", 867 pUserInfo->wszUser, pSessionData->Session, pSessionData->LogonId.HighPart, 868 pSessionData->LogonId.LowPart, pUserInfo->wszAuthenticationPackage, 869 pUserInfo->wszLogonDomain); 847 VGSvcVerbose(3, "Account User=%ls, Session=%u, LogonID=%d,%u, AuthPkg=%ls, Domain=%ls\n", 848 pUserInfo->wszUser, pSessionData->Session, pSessionData->LogonId.HighPart, 849 pSessionData->LogonId.LowPart, pUserInfo->wszAuthenticationPackage, pUserInfo->wszLogonDomain); 870 850 871 851 /** … … 893 873 894 874 if (s_fSkipRDPDetection) 895 V BoxServiceVerbose(0, "Detection of logged-in users via RDP is disabled\n");875 VGSvcVerbose(0, "Detection of logged-in users via RDP is disabled\n"); 896 876 } 897 877 … … 913 893 if (cbRet) 914 894 iState = *pBuffer; 915 VBoxServiceVerbose(3, "Account User=%ls, WTSConnectState=%d (%ld)\n", 916 pUserInfo->wszUser, iState, cbRet); 895 VGSvcVerbose(3, "Account User=%ls, WTSConnectState=%d (%u)\n", pUserInfo->wszUser, iState, cbRet); 917 896 if ( iState == WTSActive /* User logged on to WinStation. */ 918 897 || iState == WTSShadow /* Shadowing another WinStation. */ … … 921 900 /** @todo On Vista and W2K, always "old" user name are still 922 901 * there. Filter out the old one! */ 923 VBoxServiceVerbose(3, "Account User=%ls using TCS/RDP, state=%d \n", 924 pUserInfo->wszUser, iState); 902 VGSvcVerbose(3, "Account User=%ls using TCS/RDP, state=%d \n", pUserInfo->wszUser, iState); 925 903 fFoundUser = true; 926 904 } … … 939 917 */ 940 918 case ERROR_CTX_WINSTATION_NOT_FOUND: 941 VBoxServiceVerbose(3, "No WinStation found for user=%ls\n", 942 pUserInfo->wszUser); 919 VGSvcVerbose(3, "No WinStation found for user=%ls\n", pUserInfo->wszUser); 943 920 break; 944 921 945 922 default: 946 V BoxServiceVerbose(3, "Cannot query WTS connection state for user=%ls, error=%ld\n",947 923 VGSvcVerbose(3, "Cannot query WTS connection state for user=%ls, error=%u\n", 924 pUserInfo->wszUser, dwLastErr); 948 925 break; 949 926 } … … 954 931 } 955 932 else 956 VBoxServiceVerbose(3, "SID owner type=%d not handled, skipping\n", 957 enmOwnerType); 958 } 959 960 VBoxServiceVerbose(3, "Account User=%ls %s logged in\n", 961 pUserInfo->wszUser, fFoundUser ? "is" : "is not"); 933 VGSvcVerbose(3, "SID owner type=%d not handled, skipping\n", enmOwnerType); 934 } 935 936 VGSvcVerbose(3, "Account User=%ls %s logged in\n", pUserInfo->wszUser, fFoundUser ? "is" : "is not"); 962 937 } 963 938 … … 970 945 971 946 972 static int vboxServiceVMInfoWinWriteLastInput(PVBOXSERVICEVEPROPCACHE pCache, 973 const char *pszUser, const char *pszDomain) 947 static int vgsvcVMInfoWinWriteLastInput(PVBOXSERVICEVEPROPCACHE pCache, const char *pszUser, const char *pszDomain) 974 948 { 975 949 AssertPtrReturn(pCache, VERR_INVALID_POINTER); … … 980 954 981 955 char szPipeName[255]; 982 if (RTStrPrintf(szPipeName, sizeof(szPipeName), "%s%s", 983 956 /** @todo r=bird: Pointless if. */ 957 if (RTStrPrintf(szPipeName, sizeof(szPipeName), "%s%s", VBOXTRAY_IPC_PIPE_PREFIX, pszUser)) 984 958 { 985 959 bool fReportToHost = false; … … 990 964 if (RT_SUCCESS(rc)) 991 965 { 992 VBOXTRAYIPCHEADER ipcHdr = { VBOXTRAY_IPC_HDR_MAGIC, 0 /* Header version */, 993 VBOXTRAYIPCMSGTYPE_USERLASTINPUT, 0 /* No msg */ }; 966 VBOXTRAYIPCHEADER ipcHdr = 967 { 968 /* .uMagic = */ VBOXTRAY_IPC_HDR_MAGIC, 969 /* .uHdrVersion = */ 0, 970 /* .uMsgType = */ VBOXTRAYIPCMSGTYPE_USERLASTINPUT, 971 /* .cbMsgData = */ 0 /* No msg */ 972 }; 994 973 995 974 rc = RTLocalIpcSessionWrite(hSession, &ipcHdr, sizeof(ipcHdr)); … … 997 976 VBOXTRAYIPCRES_USERLASTINPUT ipcRes; 998 977 if (RT_SUCCESS(rc)) 999 rc = RTLocalIpcSessionRead(hSession, &ipcRes, sizeof(ipcRes), 1000 NULL /* Exact read */); 978 rc = RTLocalIpcSessionRead(hSession, &ipcRes, sizeof(ipcRes), NULL /* Exact read */); 1001 979 if ( RT_SUCCESS(rc) 1002 980 /* If uLastInput is set to UINT32_MAX VBoxTray was not able to retrieve the … … 1008 986 : VBoxGuestUserState_Idle; 1009 987 1010 rc = vboxServiceUserUpdateF(pCache, pszUser, pszDomain, "UsageState", 1011 userState == VBoxGuestUserState_InUse 1012 ? "InUse" : "Idle"); 988 rc = VGSvcUserUpdateF(pCache, pszUser, pszDomain, "UsageState", 989 userState == VBoxGuestUserState_InUse ? "InUse" : "Idle"); 1013 990 1014 991 /* … … 1018 995 */ 1019 996 fReportToHost = rc == VINF_SUCCESS; 1020 V BoxServiceVerbose(4, "User \"%s\" (domain \"%s\") is idle for %RU32, fReportToHost=%RTbool\n",1021 997 VGSvcVerbose(4, "User '%s' (domain '%s') is idle for %RU32, fReportToHost=%RTbool\n", 998 pszUser, pszDomain ? pszDomain : "<None>", ipcRes.uLastInput, fReportToHost); 1022 999 1023 1000 #if 0 /* Do we want to write the idle time as well? */ 1024 1001 /* Also write the user's current idle time, if there is any. */ 1025 1002 if (userState == VBoxGuestUserState_Idle) 1026 rc = vboxServiceUserUpdateF(pCache, pszUser, pszDomain, "IdleTimeMs", 1027 "%RU32", ipcRes.uLastInputMs); 1003 rc = vgsvcUserUpdateF(pCache, pszUser, pszDomain, "IdleTimeMs", "%RU32", ipcRes.uLastInputMs); 1028 1004 else 1029 rc = vboxServiceUserUpdateF(pCache, pszUser, pszDomain, "IdleTimeMs", 1030 NULL /* Delete property */); 1005 rc = vgsvcUserUpdateF(pCache, pszUser, pszDomain, "IdleTimeMs", NULL /* Delete property */); 1031 1006 1032 1007 if (RT_SUCCESS(rc)) … … 1035 1010 #ifdef DEBUG 1036 1011 else if (ipcRes.uLastInput == UINT32_MAX) 1037 VBoxServiceVerbose(4, "Last input for user \"%s\" is not supported, skipping\n", 1038 pszUser, rc); 1039 1040 VBoxServiceVerbose(4, "Getting last input for user \"%s\" ended with rc=%Rrc\n", 1041 pszUser, rc); 1012 VGSvcVerbose(4, "Last input for user '%s' is not supported, skipping\n", pszUser, rc); 1013 1014 VGSvcVerbose(4, "Getting last input for user '%s' ended with rc=%Rrc\n", pszUser, rc); 1042 1015 #endif 1043 1016 int rc2 = RTLocalIpcSessionClose(hSession); … … 1053 1026 /* No VBoxTray (or too old version which does not support IPC) running 1054 1027 for the given user. Not much we can do then. */ 1055 VBoxServiceVerbose(4, "VBoxTray for user \"%s\" not running (anymore), no last input available\n", 1056 pszUser); 1028 VGSvcVerbose(4, "VBoxTray for user '%s' not running (anymore), no last input available\n", pszUser); 1057 1029 1058 1030 /* Overwrite rc from above. */ 1059 rc = vboxServiceUserUpdateF(pCache, pszUser, pszDomain, 1060 "UsageState", "Idle"); 1031 rc = VGSvcUserUpdateF(pCache, pszUser, pszDomain, "UsageState", "Idle"); 1061 1032 1062 1033 fReportToHost = rc == VINF_SUCCESS; … … 1067 1038 1068 1039 default: 1069 VBoxServiceError("Error querying last input for user \"%s\", rc=%Rrc\n", 1070 pszUser, rc); 1040 VGSvcError("Error querying last input for user '%s', rc=%Rrc\n", pszUser, rc); 1071 1041 break; 1072 1042 } … … 1076 1046 { 1077 1047 Assert(userState != VBoxGuestUserState_Unknown); 1078 int rc2 = VbglR3GuestUserReportState(pszUser, pszDomain, userState, 1079 NULL /* No details */, 0); 1048 int rc2 = VbglR3GuestUserReportState(pszUser, pszDomain, userState, NULL /* No details */, 0); 1080 1049 if (RT_FAILURE(rc2)) 1081 VBoxServiceError("Error reporting usage state %ld for user \"%s\" to host, rc=%Rrc\n", 1082 userState, pszUser, rc2); 1083 1050 VGSvcError("Error reporting usage state %d for user '%s' to host, rc=%Rrc\n", userState, pszUser, rc2); 1084 1051 if (RT_SUCCESS(rc)) 1085 1052 rc = rc2; … … 1102 1069 * @param pcUsersInList Where to store the number of users in the list. 1103 1070 */ 1104 int VBoxServiceVMInfoWinWriteUsers(PVBOXSERVICEVEPROPCACHE pCache, 1105 char **ppszUserList, uint32_t *pcUsersInList) 1071 int VGSvcVMInfoWinWriteUsers(PVBOXSERVICEVEPROPCACHE pCache, char **ppszUserList, uint32_t *pcUsersInList) 1106 1072 { 1107 1073 AssertPtrReturn(pCache, VERR_INVALID_POINTER); … … 1128 1094 if (rcNt != STATUS_SUCCESS) 1129 1095 { 1130 ULONG u lError = LsaNtStatusToWinError(rcNt);1131 switch (u lError)1096 ULONG uError = LsaNtStatusToWinError(rcNt); 1097 switch (uError) 1132 1098 { 1133 1099 case ERROR_NOT_ENOUGH_MEMORY: 1134 V BoxServiceError("Not enough memory to enumerate logon sessions!\n");1100 VGSvcError("Not enough memory to enumerate logon sessions!\n"); 1135 1101 break; 1136 1102 … … 1138 1104 /* If we're about to shutdown when we were in the middle of enumerating the logon 1139 1105 * sessions, skip the error to not confuse the user with an unnecessary log message. */ 1140 V BoxServiceVerbose(3, "Shutdown in progress ...\n");1141 u lError = ERROR_SUCCESS;1106 VGSvcVerbose(3, "Shutdown in progress ...\n"); 1107 uError = ERROR_SUCCESS; 1142 1108 break; 1143 1109 1144 1110 default: 1145 V BoxServiceError("LsaEnumerate failed with error %RU32\n", ulError);1111 VGSvcError("LsaEnumerate failed with error %RU32\n", uError); 1146 1112 break; 1147 1113 } … … 1150 1116 g_pfnLsaFreeReturnBuffer(paSessions); 1151 1117 1152 return RTErrConvertFromWin32(u lError);1153 } 1154 V BoxServiceVerbose(3, "Found %ldsessions\n", cSessions);1118 return RTErrConvertFromWin32(uError); 1119 } 1120 VGSvcVerbose(3, "Found %u sessions\n", cSessions); 1155 1121 1156 1122 PVBOXSERVICEVMINFOPROC paProcs; 1157 1123 DWORD cProcs; 1158 rc = VBoxServiceVMInfoWinProcessesEnumerate(&paProcs, &cProcs);1124 rc = vgsvcVMInfoWinProcessesEnumerate(&paProcs, &cProcs); 1159 1125 if (RT_FAILURE(rc)) 1160 1126 { 1161 1127 if (rc == VERR_NO_MEMORY) 1162 V BoxServiceError("Not enough memory to enumerate processes\n");1128 VGSvcError("Not enough memory to enumerate processes\n"); 1163 1129 else 1164 V BoxServiceError("Failed to enumerate processes, rc=%Rrc\n", rc);1130 VGSvcError("Failed to enumerate processes, rc=%Rrc\n", rc); 1165 1131 } 1166 1132 else … … 1169 1135 pUserInfo = (PVBOXSERVICEVMINFOUSER)RTMemAllocZ(cSessions * sizeof(VBOXSERVICEVMINFOUSER) + 1); 1170 1136 if (!pUserInfo) 1171 V BoxServiceError("Not enough memory to store enumerated users!\n");1137 VGSvcError("Not enough memory to store enumerated users!\n"); 1172 1138 else 1173 1139 { … … 1180 1146 for (ULONG i = 0; i < cSessions; i++) 1181 1147 { 1182 V BoxServiceVerbose(3, "Handling session %RU32 (of %RU32)\n", i + 1, cSessions);1148 VGSvcVerbose(3, "Handling session %RU32 (of %RU32)\n", i + 1, cSessions); 1183 1149 1184 1150 VBOXSERVICEVMINFOUSER userSession; 1185 if ( VBoxServiceVMInfoWinIsLoggedIn(&userSession, &paSessions[i]))1151 if (vgsvcVMInfoWinIsLoggedIn(&userSession, &paSessions[i])) 1186 1152 { 1187 V BoxServiceVerbose(4, "Handling user=%ls, domain=%ls, package=%ls, session=%RU32\n",1188 1189 1153 VGSvcVerbose(4, "Handling user=%ls, domain=%ls, package=%ls, session=%RU32\n", 1154 userSession.wszUser, userSession.wszLogonDomain, userSession.wszAuthenticationPackage, 1155 userSession.ulLastSession); 1190 1156 1191 1157 /* Retrieve assigned processes of current session. */ 1192 uint32_t cCurSessionProcs = VBoxServiceVMInfoWinSessionHasProcesses(&paSessions[i], paProcs, cProcs,1158 uint32_t cCurSessionProcs = vgsvcVMInfoWinSessionHasProcesses(&paSessions[i], paProcs, cProcs, 1193 1159 NULL /* Terminal session ID */); 1194 1160 /* Don't return here when current session does not have assigned processes … … 1201 1167 RTStrPrintf(szDebugSessionPath, sizeof(szDebugSessionPath), 1202 1168 "/VirtualBox/GuestInfo/Debug/LSA/Session/%RU32", userSession.ulLastSession); 1203 VBoxServiceWritePropF(s_uDebugGuestPropClientID, szDebugSessionPath, 1204 "#%RU32: cSessionProcs=%RU32 (of %RU32 procs total)", s_uDebugIter, cCurSessionProcs, cProcs); 1169 VGSvcWritePropF(s_uDebugGuestPropClientID, szDebugSessionPath, 1170 "#%RU32: cSessionProcs=%RU32 (of %RU32 procs total)", 1171 s_uDebugIter, cCurSessionProcs, cProcs); 1205 1172 } 1206 1173 … … 1220 1187 if (userSession.ulLastSession > pCurUser->ulLastSession) 1221 1188 { 1222 V BoxServiceVerbose(4, "Updating user=%ls to %u processes (last used session: %RU32)\n",1189 VGSvcVerbose(4, "Updating user=%ls to %u processes (last used session: %RU32)\n", 1223 1190 pCurUser->wszUser, cCurSessionProcs, userSession.ulLastSession); 1224 1191 1225 1192 if (!cCurSessionProcs) 1226 VBoxServiceVerbose(3, "Stale session for user=%ls detected! Processes: %RU32 -> %RU32, Session: %RU32 -> %RU32\n", 1227 pCurUser->wszUser, 1228 pCurUser->ulNumProcs, cCurSessionProcs, 1229 pCurUser->ulLastSession, userSession.ulLastSession); 1193 VGSvcVerbose(3, "Stale session for user=%ls detected! Processes: %RU32 -> %RU32, Session: %RU32 -> %RU32\n", 1194 pCurUser->wszUser, pCurUser->ulNumProcs, cCurSessionProcs, 1195 pCurUser->ulLastSession, userSession.ulLastSession); 1230 1196 1231 1197 pCurUser->ulNumProcs = cCurSessionProcs; … … 1237 1203 else if (pCurUser->ulLastSession == userSession.ulLastSession) 1238 1204 { 1239 V BoxServiceVerbose(4, "Updating processes for user=%ls (old procs=%RU32, new procs=%RU32, session=%RU32)\n",1240 1205 VGSvcVerbose(4, "Updating processes for user=%ls (old procs=%RU32, new procs=%RU32, session=%RU32)\n", 1206 pCurUser->wszUser, pCurUser->ulNumProcs, cCurSessionProcs, pCurUser->ulLastSession); 1241 1207 1242 1208 pCurUser->ulNumProcs = cCurSessionProcs; … … 1250 1216 if (!fFoundUser) 1251 1217 { 1252 V BoxServiceVerbose(4, "Adding new user=%ls (session=%RU32) with %RU32 processes\n",1253 1218 VGSvcVerbose(4, "Adding new user=%ls (session=%RU32) with %RU32 processes\n", 1219 userSession.wszUser, userSession.ulLastSession, cCurSessionProcs); 1254 1220 1255 1221 memcpy(&pUserInfo[cUniqueUsers], &userSession, sizeof(VBOXSERVICEVMINFOUSER)); … … 1262 1228 1263 1229 if (g_cVerbosity > 3) 1264 VBoxServiceWritePropF(s_uDebugGuestPropClientID, "/VirtualBox/GuestInfo/Debug/LSA", 1265 "#%RU32: cSessions=%RU32, cProcs=%RU32, cUniqueUsers=%RU32", 1266 s_uDebugIter, cSessions, cProcs, cUniqueUsers); 1267 1268 VBoxServiceVerbose(3, "Found %u unique logged-in user(s)\n", 1269 cUniqueUsers); 1230 VGSvcWritePropF(s_uDebugGuestPropClientID, "/VirtualBox/GuestInfo/Debug/LSA", 1231 "#%RU32: cSessions=%RU32, cProcs=%RU32, cUniqueUsers=%RU32", 1232 s_uDebugIter, cSessions, cProcs, cUniqueUsers); 1233 1234 VGSvcVerbose(3, "Found %u unique logged-in user(s)\n", cUniqueUsers); 1270 1235 1271 1236 for (ULONG i = 0; i < cUniqueUsers; i++) … … 1274 1239 { 1275 1240 char szDebugUserPath[255]; RTStrPrintf(szDebugUserPath, sizeof(szDebugUserPath), "/VirtualBox/GuestInfo/Debug/LSA/User/%RU32", i); 1276 V BoxServiceWritePropF(s_uDebugGuestPropClientID, szDebugUserPath,1277 1278 1241 VGSvcWritePropF(s_uDebugGuestPropClientID, szDebugUserPath, 1242 "#%RU32: szName=%ls, sessionID=%RU32, cProcs=%RU32", 1243 s_uDebugIter, pUserInfo[i].wszUser, pUserInfo[i].ulLastSession, pUserInfo[i].ulNumProcs); 1279 1244 } 1280 1245 … … 1285 1250 if (fAddUser) 1286 1251 { 1287 V BoxServiceVerbose(3, "User \"%ls\"has %RU32 interactive processes (session=%RU32)\n",1288 1252 VGSvcVerbose(3, "User '%ls' has %RU32 interactive processes (session=%RU32)\n", 1253 pUserInfo[i].wszUser, pUserInfo[i].ulNumProcs, pUserInfo[i].ulLastSession); 1289 1254 1290 1255 if (cUsersInList > 0) … … 1309 1274 /* Do idle detection. */ 1310 1275 if (RT_SUCCESS(rc)) 1311 rc = v boxServiceVMInfoWinWriteLastInput(pCache, pszUser, pszDomain);1276 rc = vgsvcVMInfoWinWriteLastInput(pCache, pszUser, pszDomain); 1312 1277 } 1313 1278 else … … 1323 1288 RTMemFree(pUserInfo); 1324 1289 } 1325 VBoxServiceVMInfoWinProcessesFree(cProcs, paProcs);1290 vgsvcVMInfoWinProcessesFree(cProcs, paProcs); 1326 1291 } 1327 1292 if (paSessions) … … 1341 1306 1342 1307 1343 int V BoxServiceWinGetComponentVersions(uint32_t uClientID)1308 int VGSvcVMInfoWinGetComponentVersions(uint32_t uClientID) 1344 1309 { 1345 1310 int rc; … … 1409 1374 { 1410 1375 char szVer[128]; 1411 V BoxServiceGetFileVersionString(aVBoxFiles[i].pszFilePath, aVBoxFiles[i].pszFileName, szVer, sizeof(szVer));1376 VGSvcUtilWinGetFileVersionString(aVBoxFiles[i].pszFilePath, aVBoxFiles[i].pszFileName, szVer, sizeof(szVer)); 1412 1377 char szPropPath[256]; 1413 1378 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestAdd/Components/%s", aVBoxFiles[i].pszFileName); 1414 rc = V BoxServiceWritePropF(uClientID, szPropPath, "%s", szVer);1379 rc = VGSvcWritePropF(uClientID, szPropPath, "%s", szVer); 1415 1380 } 1416 1381 -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp
r57920 r58029 125 125 126 126 #ifdef VBOX_WITH_DBUS 127 /** ConsoleKit defines (taken from 0.4.5). */ 128 #define CK_NAME "org.freedesktop.ConsoleKit" 129 #define CK_PATH "/org/freedesktop/ConsoleKit" 130 #define CK_INTERFACE "org.freedesktop.ConsoleKit" 131 132 #define CK_MANAGER_PATH "/org/freedesktop/ConsoleKit/Manager" 133 #define CK_MANAGER_INTERFACE "org.freedesktop.ConsoleKit.Manager" 134 #define CK_SEAT_INTERFACE "org.freedesktop.ConsoleKit.Seat" 135 #define CK_SESSION_INTERFACE "org.freedesktop.ConsoleKit.Session" 127 /** @name ConsoleKit defines (taken from 0.4.5). 128 * @{ */ 129 # define CK_NAME "org.freedesktop.ConsoleKit" 130 # define CK_PATH "/org/freedesktop/ConsoleKit" 131 # define CK_INTERFACE "org.freedesktop.ConsoleKit" 132 # define CK_MANAGER_PATH "/org/freedesktop/ConsoleKit/Manager" 133 # define CK_MANAGER_INTERFACE "org.freedesktop.ConsoleKit.Manager" 134 # define CK_SEAT_INTERFACE "org.freedesktop.ConsoleKit.Seat" 135 # define CK_SESSION_INTERFACE "org.freedesktop.ConsoleKit.Session" 136 /** @} */ 136 137 #endif 137 138 … … 144 145 * @return IPRT status code. 145 146 */ 146 int V BoxServiceVMInfoSignal(void)147 int VGSvcVMInfoSignal(void) 147 148 { 148 149 /* Trigger a re-enumeration of all logged-in users by unblocking … … 155 156 156 157 157 /** @copydoc VBOXSERVICE::pfnPreInit */ 158 static DECLCALLBACK(int) VBoxServiceVMInfoPreInit(void) 158 /** 159 * @interface_method_impl{VBOXSERVICE,pfnPreInit} 160 */ 161 static DECLCALLBACK(int) vbsvcVMInfoPreInit(void) 159 162 { 160 163 return VINF_SUCCESS; … … 162 165 163 166 164 /** @copydoc VBOXSERVICE::pfnOption */ 165 static DECLCALLBACK(int) VBoxServiceVMInfoOption(const char **ppszShort, int argc, char **argv, int *pi) 167 /** 168 * @interface_method_impl{VBOXSERVICE,pfnOption} 169 */ 170 static DECLCALLBACK(int) vbsvcVMInfoOption(const char **ppszShort, int argc, char **argv, int *pi) 166 171 { 167 172 /** @todo Use RTGetOpt here. */ … … 171 176 /* no short options */; 172 177 else if (!strcmp(argv[*pi], "--vminfo-interval")) 173 rc = VBoxServiceArgUInt32(argc, argv, "", pi, 174 &g_cMsVMInfoInterval, 1, UINT32_MAX - 1); 178 rc = VGSvcArgUInt32(argc, argv, "", pi, &g_cMsVMInfoInterval, 1, UINT32_MAX - 1); 175 179 else if (!strcmp(argv[*pi], "--vminfo-user-idle-threshold")) 176 rc = VBoxServiceArgUInt32(argc, argv, "", pi, 177 &g_uVMInfoUserIdleThresholdMS, 1, UINT32_MAX - 1); 180 rc = VGSvcArgUInt32(argc, argv, "", pi, &g_uVMInfoUserIdleThresholdMS, 1, UINT32_MAX - 1); 178 181 return rc; 179 182 } 180 183 181 184 182 /** @copydoc VBOXSERVICE::pfnInit */ 183 static DECLCALLBACK(int) VBoxServiceVMInfoInit(void) 185 /** 186 * @interface_method_impl{VBOXSERVICE,pfnInit} 187 */ 188 static DECLCALLBACK(int) vbsvcVMInfoInit(void) 184 189 { 185 190 /* … … 206 211 rc = VbglR3GuestPropConnect(&g_uVMInfoGuestPropSvcClientID); 207 212 if (RT_SUCCESS(rc)) 208 V BoxServiceVerbose(3, "Property Service Client ID: %#x\n", g_uVMInfoGuestPropSvcClientID);213 VGSvcVerbose(3, "Property Service Client ID: %#x\n", g_uVMInfoGuestPropSvcClientID); 209 214 else 210 215 { … … 213 218 if (rc == VERR_HGCM_SERVICE_NOT_FOUND) /* Host service is not available. */ 214 219 { 215 V BoxServiceVerbose(0, "Guest property service is not available, disabling the service\n");220 VGSvcVerbose(0, "Guest property service is not available, disabling the service\n"); 216 221 rc = VERR_SERVICE_DISABLED; 217 222 } 218 223 else 219 V BoxServiceError("Failed to connect to the guest property service! Error: %Rrc\n", rc);224 VGSvcError("Failed to connect to the guest property service! Error: %Rrc\n", rc); 220 225 RTSemEventMultiDestroy(g_hVMInfoEvent); 221 226 g_hVMInfoEvent = NIL_RTSEMEVENTMULTI; … … 224 229 if (RT_SUCCESS(rc)) 225 230 { 226 V BoxServicePropCacheCreate(&g_VMInfoPropCache, g_uVMInfoGuestPropSvcClientID);231 VGSvcPropCacheCreate(&g_VMInfoPropCache, g_uVMInfoGuestPropSvcClientID); 227 232 228 233 /* 229 234 * Declare some guest properties with flags and reset values. 230 235 */ 231 int rc2 = VBoxServicePropCacheUpdateEntry(&g_VMInfoPropCache, g_pszPropCacheValLoggedInUsersList, 232 VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_TRANSIENT, NULL /* Delete on exit */); 236 int rc2 = VGSvcPropCacheUpdateEntry(&g_VMInfoPropCache, g_pszPropCacheValLoggedInUsersList, 237 VGSVCPROPCACHE_FLAGS_TEMPORARY | VGSVCPROPCACHE_FLAGS_TRANSIENT, 238 NULL /* Delete on exit */); 233 239 if (RT_FAILURE(rc2)) 234 V BoxServiceError("Failed to init property cache value \"%s\", rc=%Rrc\n", g_pszPropCacheValLoggedInUsersList, rc2);235 236 rc2 = V BoxServicePropCacheUpdateEntry(&g_VMInfoPropCache, g_pszPropCacheValLoggedInUsers,237 VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_TRANSIENT, "0");240 VGSvcError("Failed to init property cache value '%s', rc=%Rrc\n", g_pszPropCacheValLoggedInUsersList, rc2); 241 242 rc2 = VGSvcPropCacheUpdateEntry(&g_VMInfoPropCache, g_pszPropCacheValLoggedInUsers, 243 VGSVCPROPCACHE_FLAGS_TEMPORARY | VGSVCPROPCACHE_FLAGS_TRANSIENT, "0"); 238 244 if (RT_FAILURE(rc2)) 239 V BoxServiceError("Failed to init property cache value \"%s\", rc=%Rrc\n", g_pszPropCacheValLoggedInUsers, rc2);240 241 rc2 = V BoxServicePropCacheUpdateEntry(&g_VMInfoPropCache, g_pszPropCacheValNoLoggedInUsers,242 VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_TRANSIENT, "true");245 VGSvcError("Failed to init property cache value '%s', rc=%Rrc\n", g_pszPropCacheValLoggedInUsers, rc2); 246 247 rc2 = VGSvcPropCacheUpdateEntry(&g_VMInfoPropCache, g_pszPropCacheValNoLoggedInUsers, 248 VGSVCPROPCACHE_FLAGS_TEMPORARY | VGSVCPROPCACHE_FLAGS_TRANSIENT, "true"); 243 249 if (RT_FAILURE(rc2)) 244 VBoxServiceError("Failed to init property cache value \"%s\", rc=%Rrc\n", g_pszPropCacheValNoLoggedInUsers, rc2); 245 246 rc2 = VBoxServicePropCacheUpdateEntry(&g_VMInfoPropCache, g_pszPropCacheValNetCount, 247 VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_ALWAYS_UPDATE, NULL /* Delete on exit */); 250 VGSvcError("Failed to init property cache value '%s', rc=%Rrc\n", g_pszPropCacheValNoLoggedInUsers, rc2); 251 252 rc2 = VGSvcPropCacheUpdateEntry(&g_VMInfoPropCache, g_pszPropCacheValNetCount, 253 VGSVCPROPCACHE_FLAGS_TEMPORARY | VGSVCPROPCACHE_FLAGS_ALWAYS_UPDATE, 254 NULL /* Delete on exit */); 248 255 if (RT_FAILURE(rc2)) 249 V BoxServiceError("Failed to init property cache value \"%s\", rc=%Rrc\n", g_pszPropCacheValNetCount, rc2);256 VGSvcError("Failed to init property cache value '%s', rc=%Rrc\n", g_pszPropCacheValNetCount, rc2); 250 257 251 258 /* … … 254 261 */ 255 262 char *pszValue; 256 rc2 = V BoxServiceReadHostProp(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--vminfo-user-idle-threshold", true /* Read only */,257 263 rc2 = VGSvcReadHostProp(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--vminfo-user-idle-threshold", 264 true /* Read only */, &pszValue, NULL /* Flags */, NULL /* Timestamp */); 258 265 if (RT_SUCCESS(rc2)) 259 266 { … … 276 283 * @param puTimestamp Timestamp of property to retrieve. Optional. 277 284 */ 278 static int vboxServiceGetLAClientValue(uint32_t uClientID, const char *pszProperty, 279 char **ppszValue, uint64_t *puTimestamp) 285 static int vgsvcGetLAClientValue(uint32_t uClientID, const char *pszProperty, char **ppszValue, uint64_t *puTimestamp) 280 286 { 281 287 AssertReturn(uClientID, VERR_INVALID_PARAMETER); … … 285 291 286 292 char pszClientPath[255]; 293 /** @todo r=bird: Another pointless RTStrPrintf test with wrong status code to boot. */ 287 294 if (RTStrPrintf(pszClientPath, sizeof(pszClientPath), 288 295 "/VirtualBox/HostInfo/VRDP/Client/%RU32/%s", uClientID, pszProperty)) 289 296 { 290 rc = V BoxServiceReadHostProp(g_uVMInfoGuestPropSvcClientID, pszClientPath, true /* Read only */,291 297 rc = VGSvcReadHostProp(g_uVMInfoGuestPropSvcClientID, pszClientPath, true /* Read only */, 298 ppszValue, NULL /* Flags */, puTimestamp); 292 299 } 293 300 else … … 306 313 * @param pClient Pointer where to store the client information. 307 314 */ 308 static int v boxServiceGetLAClientInfo(uint32_t uClientID, PVBOXSERVICELACLIENTINFO pClient)315 static int vgsvcGetLAClientInfo(uint32_t uClientID, PVBOXSERVICELACLIENTINFO pClient) 309 316 { 310 317 AssertReturn(uClientID, VERR_INVALID_PARAMETER); 311 318 AssertPtrReturn(pClient, VERR_INVALID_POINTER); 312 319 313 int rc = v boxServiceGetLAClientValue(uClientID, "Name", &pClient->pszName,320 int rc = vgsvcGetLAClientValue(uClientID, "Name", &pClient->pszName, 314 321 NULL /* Timestamp */); 315 322 if (RT_SUCCESS(rc)) 316 323 { 317 324 char *pszAttach; 318 rc = vboxServiceGetLAClientValue(uClientID, "Attach", &pszAttach, 319 &pClient->uAttachedTS); 325 rc = vgsvcGetLAClientValue(uClientID, "Attach", &pszAttach, &pClient->uAttachedTS); 320 326 if (RT_SUCCESS(rc)) 321 327 { 322 328 AssertPtr(pszAttach); 323 pClient->fAttached = !RTStrICmp(pszAttach, "1") ? true : false;329 pClient->fAttached = RTStrICmp(pszAttach, "1") == 0; 324 330 325 331 RTStrFree(pszAttach); … … 327 333 } 328 334 if (RT_SUCCESS(rc)) 329 rc = vboxServiceGetLAClientValue(uClientID, "Location", &pClient->pszLocation, 330 NULL /* Timestamp */); 335 rc = vgsvcGetLAClientValue(uClientID, "Location", &pClient->pszLocation, NULL /* Timestamp */); 331 336 if (RT_SUCCESS(rc)) 332 rc = vboxServiceGetLAClientValue(uClientID, "Domain", &pClient->pszDomain, 333 NULL /* Timestamp */); 337 rc = vgsvcGetLAClientValue(uClientID, "Domain", &pClient->pszDomain, NULL /* Timestamp */); 334 338 if (RT_SUCCESS(rc)) 335 339 pClient->uID = uClientID; … … 344 348 * @param pClient Pointer to client information structure to free. 345 349 */ 346 static void v boxServiceFreeLAClientInfo(PVBOXSERVICELACLIENTINFO pClient)350 static void vgsvcFreeLAClientInfo(PVBOXSERVICELACLIENTINFO pClient) 347 351 { 348 352 if (pClient) … … 378 382 * the property. 379 383 */ 380 int vboxServiceUserUpdateF(PVBOXSERVICEVEPROPCACHE pCache, const char *pszUser, const char *pszDomain,381 384 int VGSvcUserUpdateF(PVBOXSERVICEVEPROPCACHE pCache, const char *pszUser, const char *pszDomain, 385 const char *pszKey, const char *pszValueFormat, ...) 382 386 { 383 387 AssertPtrReturn(pCache, VERR_INVALID_POINTER); … … 392 396 if (pszDomain) 393 397 { 398 /** @todo r=bird: RTStrAPrintf returns -1, not zero on failure! */ 394 399 if (!RTStrAPrintf(&pszName, "%s%s@%s/%s", g_pszPropCacheValUser, pszUser, pszDomain, pszKey)) 395 400 rc = VERR_NO_MEMORY; … … 397 402 else 398 403 { 404 /** @todo r=bird: RTStrAPrintf returns -1, not zero on failure! You got it 405 * right 5 lines further down... */ 399 406 if (!RTStrAPrintf(&pszName, "%s%s/%s", g_pszPropCacheValUser, pszUser, pszKey)) 400 407 rc = VERR_NO_MEMORY; … … 416 423 417 424 if (RT_SUCCESS(rc)) 418 rc = V BoxServicePropCacheUpdate(pCache, pszName, pszValue);425 rc = VGSvcPropCacheUpdate(pCache, pszName, pszValue); 419 426 if (rc == VINF_SUCCESS) /* VBoxServicePropCacheUpdate will also return VINF_NO_CHANGE. */ 420 427 { 421 428 /** @todo Combine updating flags w/ updating the actual value. */ 422 rc = V BoxServicePropCacheUpdateEntry(pCache, pszName,423 VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_TRANSIENT,424 429 rc = VGSvcPropCacheUpdateEntry(pCache, pszName, 430 VGSVCPROPCACHE_FLAGS_TEMPORARY | VGSVCPROPCACHE_FLAGS_TRANSIENT, 431 NULL /* Delete on exit */); 425 432 } 426 433 … … 436 443 * Errors are ignored. 437 444 */ 438 static void v boxserviceVMInfoWriteFixedProperties(void)445 static void vgsvcVMInfoWriteFixedProperties(void) 439 446 { 440 447 /* … … 443 450 char szInfo[256]; 444 451 int rc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szInfo, sizeof(szInfo)); 445 V BoxServiceWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/Product",446 452 VGSvcWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/Product", 453 "%s", RT_FAILURE(rc) ? "" : szInfo); 447 454 448 455 rc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szInfo, sizeof(szInfo)); 449 V BoxServiceWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/Release",450 456 VGSvcWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/Release", 457 "%s", RT_FAILURE(rc) ? "" : szInfo); 451 458 452 459 rc = RTSystemQueryOSInfo(RTSYSOSINFO_VERSION, szInfo, sizeof(szInfo)); 453 V BoxServiceWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/Version",454 460 VGSvcWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/Version", 461 "%s", RT_FAILURE(rc) ? "" : szInfo); 455 462 456 463 rc = RTSystemQueryOSInfo(RTSYSOSINFO_SERVICE_PACK, szInfo, sizeof(szInfo)); 457 V BoxServiceWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/ServicePack",458 464 VGSvcWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/OS/ServicePack", 465 "%s", RT_FAILURE(rc) ? "" : szInfo); 459 466 460 467 /* … … 465 472 char *pszAddRev; 466 473 rc = VbglR3GetAdditionsVersion(&pszAddVer, &pszAddVerExt, &pszAddRev); 467 V BoxServiceWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/Version",468 469 V BoxServiceWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/VersionExt",470 471 V BoxServiceWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/Revision",472 474 VGSvcWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/Version", 475 "%s", RT_FAILURE(rc) ? "" : pszAddVer); 476 VGSvcWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/VersionExt", 477 "%s", RT_FAILURE(rc) ? "" : pszAddVerExt); 478 VGSvcWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/Revision", 479 "%s", RT_FAILURE(rc) ? "" : pszAddRev); 473 480 if (RT_SUCCESS(rc)) 474 481 { … … 484 491 char *pszInstDir; 485 492 rc = VbglR3GetAdditionsInstallationPath(&pszInstDir); 486 V BoxServiceWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/InstallDir",487 493 VGSvcWritePropF(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/InstallDir", 494 "%s", RT_FAILURE(rc) ? "" : pszInstDir); 488 495 if (RT_SUCCESS(rc)) 489 496 RTStrFree(pszInstDir); 490 497 491 V BoxServiceWinGetComponentVersions(g_uVMInfoGuestPropSvcClientID);498 VGSvcVMInfoWinGetComponentVersions(g_uVMInfoGuestPropSvcClientID); 492 499 #endif 493 500 } 501 494 502 495 503 #if defined(VBOX_WITH_DBUS) && defined(RT_OS_LINUX) /* Not yet for Solaris/FreeBSB. */ … … 497 505 * Simple wrapper to work around compiler-specific va_list madness. 498 506 */ 499 static dbus_bool_t vboxService_dbus_message_get_args(DBusMessage *message, 500 DBusError *error, 501 int first_arg_type, 502 ...) 507 static dbus_bool_t vboxService_dbus_message_get_args(DBusMessage *message, DBusError *error, int first_arg_type, ...) 503 508 { 504 509 va_list va; 505 510 va_start(va, first_arg_type); 506 dbus_bool_t ret = dbus_message_get_args_valist(message, error, 507 first_arg_type, va); 511 dbus_bool_t ret = dbus_message_get_args_valist(message, error, first_arg_type, va); 508 512 va_end(va); 509 513 return ret; … … 511 515 #endif 512 516 517 513 518 /** 514 519 * Provide information about active users. 515 520 */ 516 static int v boxserviceVMInfoWriteUsers(void)521 static int vgsvcVMInfoWriteUsers(void) 517 522 { 518 int rc = VINF_SUCCESS;523 int rc; 519 524 char *pszUserList = NULL; 520 525 uint32_t cUsersInList = 0; … … 522 527 #ifdef RT_OS_WINDOWS 523 528 # ifndef TARGET_NT4 524 rc = VBoxServiceVMInfoWinWriteUsers(&g_VMInfoPropCache, 525 &pszUserList, &cUsersInList); 529 rc = VGSvcVMInfoWinWriteUsers(&g_VMInfoPropCache, &pszUserList, &cUsersInList); 526 530 # else 527 531 rc = VERR_NOT_IMPLEMENTED; … … 549 553 /* Allocate a first array to hold 32 users max. */ 550 554 char **papszUsers = (char **)RTMemAllocZ(cListSize * sizeof(char *)); 551 if (!papszUsers) 555 if (papszUsers) 556 rc = VINF_SUCCESS; 557 else 552 558 rc = VERR_NO_MEMORY; 553 559 … … 558 564 { 559 565 # ifdef RT_OS_DARWIN /* No ut_user->ut_session on Darwin */ 560 VBoxServiceVerbose(4, "Found entry \"%s\" (type: %d, PID: %RU32)\n", 561 ut_user->ut_user, ut_user->ut_type, ut_user->ut_pid); 566 VGSvcVerbose(4, "Found entry '%s' (type: %d, PID: %RU32)\n", ut_user->ut_user, ut_user->ut_type, ut_user->ut_pid); 562 567 # else 563 V BoxServiceVerbose(4, "Found entry \"%s\"(type: %d, PID: %RU32, session: %RU32)\n",564 568 VGSvcVerbose(4, "Found entry '%s' (type: %d, PID: %RU32, session: %RU32)\n", 569 ut_user->ut_user, ut_user->ut_type, ut_user->ut_pid, ut_user->ut_session); 565 570 # endif 566 571 if (cUsersInList > cListSize) … … 582 587 if (!fFound) 583 588 { 584 VBoxServiceVerbose(4, "Adding user \"%s\" (type: %d) to list\n", 585 ut_user->ut_user, ut_user->ut_type); 589 VGSvcVerbose(4, "Adding user '%s' (type: %d) to list\n", ut_user->ut_user, ut_user->ut_type); 586 590 587 591 rc = RTStrDupEx(&papszUsers[cUsersInList], (const char *)ut_user->ut_user); … … 602 606 { 603 607 /* Handle desktop sessions using ConsoleKit. */ 604 V BoxServiceVerbose(4, "Checking ConsoleKit sessions ...\n");608 VGSvcVerbose(4, "Checking ConsoleKit sessions ...\n"); 605 609 fHaveLibDbus = true; 606 610 dbus_error_init(&dbErr); … … 612 616 { 613 617 /* Get all available sessions. */ 618 /** @todo r=bird: What's the point of hardcoding things here when we've taken the pain of defining CK_XXX constants at the top of the file (or vice versa)? */ 614 619 DBusMessage *pMsgSessions = dbus_message_new_method_call("org.freedesktop.ConsoleKit", 615 620 "/org/freedesktop/ConsoleKit/Manager", … … 617 622 "GetSessions"); 618 623 if ( pMsgSessions 619 && (dbus_message_get_type(pMsgSessions) == DBUS_MESSAGE_TYPE_METHOD_CALL))624 && dbus_message_get_type(pMsgSessions) == DBUS_MESSAGE_TYPE_METHOD_CALL) 620 625 { 621 626 DBusMessage *pReplySessions = dbus_connection_send_with_reply_and_block(pConnection, … … 625 630 && !dbus_error_is_set(&dbErr)) 626 631 { 627 char **ppszSessions; int cSessions; 628 if ( (dbus_message_get_type(pMsgSessions) == DBUS_MESSAGE_TYPE_METHOD_CALL) 632 char **ppszSessions; 633 int cSessions; 634 if ( dbus_message_get_type(pMsgSessions) == DBUS_MESSAGE_TYPE_METHOD_CALL 629 635 && vboxService_dbus_message_get_args(pReplySessions, &dbErr, DBUS_TYPE_ARRAY, 630 636 DBUS_TYPE_OBJECT_PATH, &ppszSessions, &cSessions, 631 637 DBUS_TYPE_INVALID /* Termination */)) 632 638 { 633 V BoxServiceVerbose(4, "ConsoleKit: retrieved %RU16 session(s)\n", cSessions);639 VGSvcVerbose(4, "ConsoleKit: retrieved %RU16 session(s)\n", cSessions); 634 640 635 641 char **ppszCurSession = ppszSessions; 636 for (ppszCurSession; 637 ppszCurSession && *ppszCurSession; ppszCurSession++) 642 for (ppszCurSession; ppszCurSession && *ppszCurSession; ppszCurSession++) 638 643 { 639 V BoxServiceVerbose(4, "ConsoleKit: processing session '%s' ...\n", *ppszCurSession);644 VGSvcVerbose(4, "ConsoleKit: processing session '%s' ...\n", *ppszCurSession); 640 645 641 646 /* Only respect active sessions .*/ … … 649 654 { 650 655 DBusMessage *pReplySessionActive = dbus_connection_send_with_reply_and_block(pConnection, 651 pMsgSessionActive, 30 * 1000 /* 30s timeout */, 656 pMsgSessionActive, 657 30 * 1000 /*sec*/, 652 658 &dbErr); 653 659 if ( pReplySessionActive … … 672 678 } 673 679 674 V BoxServiceVerbose(4, "ConsoleKit: session '%s' is %s\n",680 VGSvcVerbose(4, "ConsoleKit: session '%s' is %s\n", 675 681 *ppszCurSession, fActive ? "active" : "not active"); 676 682 … … 686 692 { 687 693 DBusMessage *pReplyUnixUser = dbus_connection_send_with_reply_and_block(pConnection, 688 pMsgUnixUser, 30 * 1000 /* 30s timeout */, 694 pMsgUnixUser, 695 30 * 1000 /* 30s timeout */, 689 696 &dbErr); 690 697 if ( pReplyUnixUser … … 711 718 if (ppwEntry->pw_uid >= uid_min /* Only respect users, not daemons etc. */) 712 719 { 713 V BoxServiceVerbose(4, "ConsoleKit: session '%s' -> %s (uid: %RU32)\n",714 720 VGSvcVerbose(4, "ConsoleKit: session '%s' -> %s (uid: %RU32)\n", 721 *ppszCurSession, ppwEntry->pw_name, uid); 715 722 716 723 bool fFound = false; … … 720 727 if (!fFound) 721 728 { 722 VBoxServiceVerbose(4, "ConsoleKit: adding user \"%s\" to list\n", 723 ppwEntry->pw_name); 729 VGSvcVerbose(4, "ConsoleKit: adding user '%s' to list\n", ppwEntry->pw_name); 724 730 725 731 rc = RTStrDupEx(&papszUsers[cUsersInList], (const char *)ppwEntry->pw_name); … … 732 738 } 733 739 else 734 V BoxServiceError("ConsoleKit: unable to lookup user name for uid=%RU32\n", uid);740 VGSvcError("ConsoleKit: unable to lookup user name for uid=%RU32\n", uid); 735 741 } 736 742 else … … 747 753 { 748 754 s_iBitchedAboutConsoleKit++; 749 V BoxServiceError("ConsoleKit: unable to retrieve user for session '%s' (msg type=%d): %s\n",750 751 755 VGSvcError("ConsoleKit: unable to retrieve user for session '%s' (msg type=%d): %s\n", 756 *ppszCurSession, dbus_message_get_type(pMsgUnixUser), 757 dbus_error_is_set(&dbErr) ? dbErr.message : "No error information available"); 752 758 } 753 759 } … … 760 766 } 761 767 else 762 { 763 VBoxServiceError("ConsoleKit: unable to retrieve session parameters (msg type=%d): %s\n", 764 dbus_message_get_type(pMsgSessions), 765 dbus_error_is_set(&dbErr) ? dbErr.message : "No error information available"); 766 } 768 VGSvcError("ConsoleKit: unable to retrieve session parameters (msg type=%d): %s\n", 769 dbus_message_get_type(pMsgSessions), 770 dbus_error_is_set(&dbErr) ? dbErr.message : "No error information available"); 767 771 dbus_message_unref(pReplySessions); 768 772 } … … 780 784 { 781 785 s_iBitchedAboutConsoleKit++; 782 V BoxServiceError("Unable to invoke ConsoleKit (%d/3) -- maybe not installed / used? Error: %s\n",783 784 786 VGSvcError("Unable to invoke ConsoleKit (%d/3) -- maybe not installed / used? Error: %s\n", 787 s_iBitchedAboutConsoleKit, 788 dbus_error_is_set(&dbErr) ? dbErr.message : "No error information available"); 785 789 } 786 790 } … … 795 799 { 796 800 s_iBitchedAboutDBus++; 797 V BoxServiceError("Unable to connect to system D-Bus (%d/3): %s\n", s_iBitchedAboutDBus,798 801 VGSvcError("Unable to connect to system D-Bus (%d/3): %s\n", s_iBitchedAboutDBus, 802 fHaveLibDbus && dbus_error_is_set(&dbErr) ? dbErr.message : "D-Bus not installed"); 799 803 } 800 804 } … … 811 815 size_t cchUserList = 0; 812 816 if (RT_SUCCESS(rc)) 813 {814 817 for (uint32_t i = 0; i < cUsersInList; i++) 815 818 cchUserList += (i != 0) + strlen(papszUsers[i]); 816 }817 819 818 820 /* Build the user list. */ … … 846 848 Assert(RT_FAILURE(rc) || cUsersInList == 0 || (pszUserList && *pszUserList)); 847 849 848 /* If the user enumeration above failed, reset the user count to 0 except 850 /* 851 * If the user enumeration above failed, reset the user count to 0 except 849 852 * we didn't have enough memory anymore. In that case we want to preserve 850 853 * the previous user count in order to not confuse third party tools which 851 * rely on that count. */ 854 * rely on that count. 855 */ 852 856 if (RT_FAILURE(rc)) 853 857 { … … 856 860 static int s_iVMInfoBitchedOOM = 0; 857 861 if (s_iVMInfoBitchedOOM++ < 3) 858 V BoxServiceVerbose(0, "Warning: Not enough memory available to enumerate users! Keeping old value (%RU32)\n",859 862 VGSvcVerbose(0, "Warning: Not enough memory available to enumerate users! Keeping old value (%RU32)\n", 863 g_cVMInfoLoggedInUsers); 860 864 cUsersInList = g_cVMInfoLoggedInUsers; 861 865 } … … 866 870 g_cVMInfoLoggedInUsers = cUsersInList; 867 871 868 VBoxServiceVerbose(4, "cUsersInList=%RU32, pszUserList=%s, rc=%Rrc\n", 869 cUsersInList, pszUserList ? pszUserList : "<NULL>", rc); 872 VGSvcVerbose(4, "cUsersInList=%RU32, pszUserList=%s, rc=%Rrc\n", cUsersInList, pszUserList ? pszUserList : "<NULL>", rc); 870 873 871 874 if (pszUserList) 872 875 { 873 876 AssertMsg(cUsersInList, ("pszUserList contains users whereas cUsersInList is 0\n")); 874 rc = V BoxServicePropCacheUpdate(&g_VMInfoPropCache, g_pszPropCacheValLoggedInUsersList, "%s", pszUserList);877 rc = VGSvcPropCacheUpdate(&g_VMInfoPropCache, g_pszPropCacheValLoggedInUsersList, "%s", pszUserList); 875 878 } 876 879 else 877 rc = V BoxServicePropCacheUpdate(&g_VMInfoPropCache, g_pszPropCacheValLoggedInUsersList, NULL);880 rc = VGSvcPropCacheUpdate(&g_VMInfoPropCache, g_pszPropCacheValLoggedInUsersList, NULL); 878 881 if (RT_FAILURE(rc)) 879 V BoxServiceError("Error writing logged in users list, rc=%Rrc\n", rc);880 881 rc = V BoxServicePropCacheUpdate(&g_VMInfoPropCache, g_pszPropCacheValLoggedInUsers, "%RU32", cUsersInList);882 VGSvcError("Error writing logged in users list, rc=%Rrc\n", rc); 883 884 rc = VGSvcPropCacheUpdate(&g_VMInfoPropCache, g_pszPropCacheValLoggedInUsers, "%RU32", cUsersInList); 882 885 if (RT_FAILURE(rc)) 883 VBoxServiceError("Error writing logged in users count, rc=%Rrc\n", rc); 884 885 rc = VBoxServicePropCacheUpdate(&g_VMInfoPropCache, g_pszPropCacheValNoLoggedInUsers, 886 cUsersInList == 0 ? "true" : "false"); 886 VGSvcError("Error writing logged in users count, rc=%Rrc\n", rc); 887 888 rc = VGSvcPropCacheUpdate(&g_VMInfoPropCache, g_pszPropCacheValNoLoggedInUsers, cUsersInList == 0 ? "true" : "false"); 887 889 if (RT_FAILURE(rc)) 888 V BoxServiceError("Error writing no logged in users beacon, rc=%Rrc\n", rc);890 VGSvcError("Error writing no logged in users beacon, rc=%Rrc\n", rc); 889 891 890 892 if (pszUserList) 891 893 RTStrFree(pszUserList); 892 894 893 V BoxServiceVerbose(4, "Writing users returned with rc=%Rrc\n", rc);895 VGSvcVerbose(4, "Writing users returned with rc=%Rrc\n", rc); 894 896 return rc; 895 897 } … … 899 901 * Provide information about the guest network. 900 902 */ 901 static int v boxserviceVMInfoWriteNetwork(void)903 static int vgsvcVMInfoWriteNetwork(void) 902 904 { 903 905 int rc = VINF_SUCCESS; … … 913 915 if (!pAdpInfo) 914 916 { 915 V BoxServiceError("VMInfo/Network: Failed to allocate IP_ADAPTER_INFO\n");917 VGSvcError("VMInfo/Network: Failed to allocate IP_ADAPTER_INFO\n"); 916 918 return VERR_NO_MEMORY; 917 919 } … … 928 930 else if (dwRet == ERROR_NO_DATA) 929 931 { 930 V BoxServiceVerbose(3, "VMInfo/Network: No network adapters available\n");932 VGSvcVerbose(3, "VMInfo/Network: No network adapters available\n"); 931 933 932 934 /* If no network adapters available / present in the … … 939 941 if (pAdpInfo) 940 942 RTMemFree(pAdpInfo); 941 V BoxServiceError("VMInfo/Network: Failed to get adapter info: Error %d\n", dwRet);943 VGSvcError("VMInfo/Network: Failed to get adapter info: Error %d\n", dwRet); 942 944 return RTErrConvertFromWin32(dwRet); 943 945 } … … 952 954 if (WSAENETDOWN == wsaErr) 953 955 { 954 V BoxServiceVerbose(0, "VMInfo/Network: Network is not up yet.\n");956 VGSvcVerbose(0, "VMInfo/Network: Network is not up yet.\n"); 955 957 wsaErr = VINF_SUCCESS; 956 958 } 957 959 else 958 V BoxServiceError("VMInfo/Network: Failed to get a socket: Error %d\n", wsaErr);960 VGSvcError("VMInfo/Network: Failed to get a socket: Error %d\n", wsaErr); 959 961 if (pAdpInfo) 960 962 RTMemFree(pAdpInfo); … … 993 995 == SOCKET_ERROR) 994 996 { 995 V BoxServiceError("VMInfo/Network: Failed to WSAIoctl() on socket: Error: %d\n", WSAGetLastError());997 VGSvcError("VMInfo/Network: Failed to WSAIoctl() on socket: Error: %d\n", WSAGetLastError()); 996 998 if (pAdpInfo) 997 999 RTMemFree(pAdpInfo); … … 1013 1015 RTStrPrintf(szIp, sizeof(szIp), "%s", inet_ntoa(pAddress->sin_addr)); 1014 1016 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/IP", cIfsReported); 1015 V BoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szIp);1017 VGSvcPropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szIp); 1016 1018 1017 1019 pAddress = (sockaddr_in *) & (aInterfaces[i].iiBroadcastAddress); 1018 1020 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Broadcast", cIfsReported); 1019 V BoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));1021 VGSvcPropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr)); 1020 1022 1021 1023 pAddress = (sockaddr_in *)&(aInterfaces[i].iiNetmask); 1022 1024 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Netmask", cIfsReported); 1023 V BoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));1025 VGSvcPropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr)); 1024 1026 1025 1027 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/Status", cIfsReported); 1026 V BoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, nFlags & IFF_UP ? "Up" : "Down");1028 VGSvcPropCacheUpdate(&g_VMInfoPropCache, szPropPath, nFlags & IFF_UP ? "Up" : "Down"); 1027 1029 1028 1030 # ifndef TARGET_NT4 … … 1039 1041 pAdp->Address[0], pAdp->Address[1], pAdp->Address[2], 1040 1042 pAdp->Address[3], pAdp->Address[4], pAdp->Address[5]); 1041 V BoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szMac);1043 VGSvcPropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szMac); 1042 1044 } 1043 1045 else 1044 V BoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, NULL);1046 VGSvcPropCacheUpdate(&g_VMInfoPropCache, szPropPath, NULL); 1045 1047 # endif /* !TARGET_NT4 */ 1046 1048 … … 1064 1066 { 1065 1067 rc = RTErrConvertFromErrno(errno); 1066 V BoxServiceError("VMInfo/Network: Failed to get all interfaces: Error %Rrc\n");1068 VGSvcError("VMInfo/Network: Failed to get all interfaces: Error %Rrc\n"); 1067 1069 return rc; 1068 1070 } … … 1084 1086 szInetAddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); 1085 1087 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/IP", cIfsReported); 1086 V BoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szInetAddr);1088 VGSvcPropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szInetAddr); 1087 1089 1088 1090 memset(szInetAddr, 0, NI_MAXHOST); … … 1090 1092 szInetAddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); 1091 1093 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Broadcast", cIfsReported); 1092 V BoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szInetAddr);1094 VGSvcPropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szInetAddr); 1093 1095 1094 1096 memset(szInetAddr, 0, NI_MAXHOST); … … 1096 1098 szInetAddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); 1097 1099 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Netmask", cIfsReported); 1098 V BoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szInetAddr);1100 VGSvcPropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szInetAddr); 1099 1101 1100 1102 /* Search for the AF_LINK interface of the current AF_INET one and get the mac. */ … … 1113 1115 pu8Mac[0], pu8Mac[1], pu8Mac[2], pu8Mac[3], pu8Mac[4], pu8Mac[5]); 1114 1116 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/MAC", cIfsReported); 1115 V BoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szMac);1117 VGSvcPropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szMac); 1116 1118 break; 1117 1119 } … … 1119 1121 1120 1122 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/Status", cIfsReported); 1121 V BoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, pIfCurr->ifa_flags & IFF_UP ? "Up" : "Down");1123 VGSvcPropCacheUpdate(&g_VMInfoPropCache, szPropPath, pIfCurr->ifa_flags & IFF_UP ? "Up" : "Down"); 1122 1124 1123 1125 cIfsReported++; … … 1139 1141 { 1140 1142 rc = RTErrConvertFromErrno(errno); 1141 V BoxServiceError("VMInfo/Network: Failed to get a socket: Error %Rrc\n", rc);1143 VGSvcError("VMInfo/Network: Failed to get a socket: Error %Rrc\n", rc); 1142 1144 return rc; 1143 1145 } … … 1182 1184 close(sd); 1183 1185 RTMemTmpFree(pchBuf); 1184 V BoxServiceError("VMInfo/Network: Error doing SIOCGIFCONF (cbBuf=%d): %Rrc\n", cbBuf, rc);1186 VGSvcError("VMInfo/Network: Error doing SIOCGIFCONF (cbBuf=%d): %Rrc\n", cbBuf, rc); 1185 1187 return rc; 1186 1188 } … … 1237 1239 { 1238 1240 rc = RTErrConvertFromErrno(errno); 1239 V BoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFFLAGS,%s) on socket: Error %Rrc\n", pCur->ifr_name, rc);1241 VGSvcError("VMInfo/Network: Failed to ioctl(SIOCGIFFLAGS,%s) on socket: Error %Rrc\n", pCur->ifr_name, rc); 1240 1242 break; 1241 1243 } … … 1250 1252 sockaddr_in *pAddress = (sockaddr_in *)&pCur->ifr_addr; 1251 1253 strcpy(&szPropPath[offSubProp], "/V4/IP"); 1252 V BoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));1254 VGSvcPropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr)); 1253 1255 1254 1256 /* Get the broadcast address. */ … … 1257 1259 { 1258 1260 rc = RTErrConvertFromErrno(errno); 1259 V BoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFBRDADDR) on socket: Error %Rrc\n", rc);1261 VGSvcError("VMInfo/Network: Failed to ioctl(SIOCGIFBRDADDR) on socket: Error %Rrc\n", rc); 1260 1262 break; 1261 1263 } 1262 1264 pAddress = (sockaddr_in *)&IfReqTmp.ifr_broadaddr; 1263 1265 strcpy(&szPropPath[offSubProp], "/V4/Broadcast"); 1264 V BoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));1266 VGSvcPropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr)); 1265 1267 1266 1268 /* Get the net mask. */ … … 1269 1271 { 1270 1272 rc = RTErrConvertFromErrno(errno); 1271 V BoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFNETMASK) on socket: Error %Rrc\n", rc);1273 VGSvcError("VMInfo/Network: Failed to ioctl(SIOCGIFNETMASK) on socket: Error %Rrc\n", rc); 1272 1274 break; 1273 1275 } … … 1278 1280 # endif 1279 1281 strcpy(&szPropPath[offSubProp], "/V4/Netmask"); 1280 V BoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));1282 VGSvcPropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr)); 1281 1283 1282 1284 # if defined(RT_OS_SOLARIS) … … 1304 1306 { 1305 1307 rc = RTErrConvertFromErrno(errno); 1306 V BoxServiceError("VMInfo/Network: failed to ioctl(SIOCGARP) on socket: Error %Rrc\n", rc);1308 VGSvcError("VMInfo/Network: failed to ioctl(SIOCGARP) on socket: Error %Rrc\n", rc); 1307 1309 break; 1308 1310 } … … 1310 1312 else 1311 1313 { 1312 V BoxServiceVerbose(2, "VMInfo/Network: Interface \"%s\"has no assigned IP address, skipping ...\n", pCur->ifr_name);1314 VGSvcVerbose(2, "VMInfo/Network: Interface '%s' has no assigned IP address, skipping ...\n", pCur->ifr_name); 1313 1315 continue; 1314 1316 } … … 1327 1329 { 1328 1330 rc = RTErrConvertFromErrno(errno); 1329 V BoxServiceError("VMInfo/Network: Failed to ioctl(SIOCGIFHWADDR) on socket: Error %Rrc\n", rc);1331 VGSvcError("VMInfo/Network: Failed to ioctl(SIOCGIFHWADDR) on socket: Error %Rrc\n", rc); 1330 1332 break; 1331 1333 } … … 1333 1335 # endif 1334 1336 strcpy(&szPropPath[offSubProp], "/MAC"); 1335 V BoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%02X%02X%02X%02X%02X%02X",1337 VGSvcPropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%02X%02X%02X%02X%02X%02X", 1336 1338 IfMac.au8[0], IfMac.au8[1], IfMac.au8[2], IfMac.au8[3], IfMac.au8[4], IfMac.au8[5]); 1337 1339 1338 1340 strcpy(&szPropPath[offSubProp], "/Status"); 1339 V BoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, fIfUp ? "Up" : "Down");1341 VGSvcPropCacheUpdate(&g_VMInfoPropCache, szPropPath, fIfUp ? "Up" : "Down"); 1340 1342 1341 1343 /* The name. */ … … 1344 1346 { 1345 1347 strcpy(&szPropPath[offSubProp], "/Name"); 1346 V BoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%.*s", sizeof(pCur->ifr_name), pCur->ifr_name);1348 VGSvcPropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%.*s", sizeof(pCur->ifr_name), pCur->ifr_name); 1347 1349 } 1348 1350 … … 1360 1362 close(sd); 1361 1363 if (RT_FAILURE(rc)) 1362 V BoxServiceError("VMInfo/Network: Network enumeration for interface %RU32 failed with error %Rrc\n", cIfsReported, rc);1364 VGSvcError("VMInfo/Network: Network enumeration for interface %RU32 failed with error %Rrc\n", cIfsReported, rc); 1363 1365 1364 1366 #endif /* !RT_OS_WINDOWS */ … … 1372 1374 /* Get former count. */ 1373 1375 uint32_t cIfsReportedOld; 1374 rc = V BoxServiceReadPropUInt32(g_uVMInfoGuestPropSvcClientID, g_pszPropCacheValNetCount, &cIfsReportedOld,1375 1376 rc = VGSvcReadPropUInt32(g_uVMInfoGuestPropSvcClientID, g_pszPropCacheValNetCount, &cIfsReportedOld, 1377 0 /* Min */, UINT32_MAX /* Max */); 1376 1378 if ( RT_SUCCESS(rc) 1377 1379 && cIfsReportedOld > cIfsReported) /* Are some ifaces not around anymore? */ 1378 1380 { 1379 V BoxServiceVerbose(3, "VMInfo/Network: Stale interface data detected (%RU32 old vs. %RU32 current)\n",1380 1381 VGSvcVerbose(3, "VMInfo/Network: Stale interface data detected (%RU32 old vs. %RU32 current)\n", 1382 cIfsReportedOld, cIfsReported); 1381 1383 1382 1384 uint32_t uIfaceDeleteIdx = cIfsReported; 1383 1385 do 1384 1386 { 1385 V BoxServiceVerbose(3, "VMInfo/Network: Deleting stale data of interface %d ...\n", uIfaceDeleteIdx);1386 rc = V BoxServicePropCacheUpdateByPath(&g_VMInfoPropCache, NULL /* Value, delete */, 0 /* Flags */, "/VirtualBox/GuestInfo/Net/%RU32", uIfaceDeleteIdx++);1387 VGSvcVerbose(3, "VMInfo/Network: Deleting stale data of interface %d ...\n", uIfaceDeleteIdx); 1388 rc = VGSvcPropCacheUpdateByPath(&g_VMInfoPropCache, NULL /* Value, delete */, 0 /* Flags */, "/VirtualBox/GuestInfo/Net/%RU32", uIfaceDeleteIdx++); 1387 1389 } while (RT_SUCCESS(rc)); 1388 1390 } … … 1390 1392 && rc != VERR_NOT_FOUND) 1391 1393 { 1392 V BoxServiceError("VMInfo/Network: Failed retrieving old network interfaces count with error %Rrc\n", rc);1394 VGSvcError("VMInfo/Network: Failed retrieving old network interfaces count with error %Rrc\n", rc); 1393 1395 } 1394 1396 #endif … … 1399 1401 * properties are no longer valid. 1400 1402 */ 1401 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, g_pszPropCacheValNetCount, "%RU32", 1402 cIfsReported); 1403 VGSvcPropCacheUpdate(&g_VMInfoPropCache, g_pszPropCacheValNetCount, "%RU32", cIfsReported); 1403 1404 1404 1405 /* Don't fail here; just report everything we got. */ … … 1407 1408 1408 1409 1409 /** @copydoc VBOXSERVICE::pfnWorker */ 1410 DECLCALLBACK(int) VBoxServiceVMInfoWorker(bool volatile *pfShutdown) 1410 /** 1411 * @interface_method_impl{VBOXSERVICE,pfnWorker} 1412 */ 1413 static DECLCALLBACK(int) vbsvcVMInfoWorker(bool volatile *pfShutdown) 1411 1414 { 1412 1415 int rc; … … 1422 1425 WSADATA wsaData; 1423 1426 if (WSAStartup(MAKEWORD(2, 2), &wsaData)) 1424 V BoxServiceError("VMInfo/Network: WSAStartup failed! Error: %Rrc\n", RTErrConvertFromWin32(WSAGetLastError()));1427 VGSvcError("VMInfo/Network: WSAStartup failed! Error: %Rrc\n", RTErrConvertFromWin32(WSAGetLastError())); 1425 1428 #endif /* RT_OS_WINDOWS */ 1426 1429 … … 1428 1431 * Write the fixed properties first. 1429 1432 */ 1430 v boxserviceVMInfoWriteFixedProperties();1433 vgsvcVMInfoWriteFixedProperties(); 1431 1434 1432 1435 /* … … 1435 1438 for (;;) 1436 1439 { 1437 rc = v boxserviceVMInfoWriteUsers();1440 rc = vgsvcVMInfoWriteUsers(); 1438 1441 if (RT_FAILURE(rc)) 1439 1442 break; 1440 1443 1441 rc = v boxserviceVMInfoWriteNetwork();1444 rc = vgsvcVMInfoWriteNetwork(); 1442 1445 if (RT_FAILURE(rc)) 1443 1446 break; … … 1451 1454 /* Check for new connection. */ 1452 1455 char *pszLAClientID = NULL; 1453 int rc2 = V BoxServiceReadHostProp(g_uVMInfoGuestPropSvcClientID, g_pszLAActiveClient, true /* Read only */,1456 int rc2 = VGSvcReadHostProp(g_uVMInfoGuestPropSvcClientID, g_pszLAActiveClient, true /* Read only */, 1454 1457 &pszLAClientID, NULL /* Flags */, NULL /* Timestamp */); 1455 1458 if (RT_SUCCESS(rc2)) … … 1463 1466 /* Peek at "Attach" value to figure out if hotdesking happened. */ 1464 1467 char *pszAttach = NULL; 1465 rc2 = v boxServiceGetLAClientValue(uLAClientID, "Attach", &pszAttach,1468 rc2 = vgsvcGetLAClientValue(uLAClientID, "Attach", &pszAttach, 1466 1469 &uLAClientAttachedTS); 1467 1470 … … 1470 1473 || (g_LAClientAttachedTS != uLAClientAttachedTS))) 1471 1474 { 1472 v boxServiceFreeLAClientInfo(&g_LAClientInfo);1475 vgsvcFreeLAClientInfo(&g_LAClientInfo); 1473 1476 1474 1477 /* Note: There is a race between setting the guest properties by the host and getting them by 1475 1478 * the guest. */ 1476 rc2 = v boxServiceGetLAClientInfo(uLAClientID, &g_LAClientInfo);1479 rc2 = vgsvcGetLAClientInfo(uLAClientID, &g_LAClientInfo); 1477 1480 if (RT_SUCCESS(rc2)) 1478 1481 { 1479 V BoxServiceVerbose(1, "VRDP: Hotdesk client %s with ID=%RU32, Name=%s, Domain=%s\n",1480 1481 1482 1483 1482 VGSvcVerbose(1, "VRDP: Hotdesk client %s with ID=%RU32, Name=%s, Domain=%s\n", 1483 /* If g_LAClientAttachedTS is 0 this means there already was an active 1484 * hotdesk session when VBoxService started. */ 1485 !g_LAClientAttachedTS ? "already active" : g_LAClientInfo.fAttached ? "connected" : "disconnected", 1486 uLAClientID, g_LAClientInfo.pszName, g_LAClientInfo.pszDomain); 1484 1487 1485 1488 g_LAClientAttachedTS = g_LAClientInfo.uAttachedTS; … … 1495 1498 { 1496 1499 s_iBitchedAboutLAClientInfo++; 1497 V BoxServiceError("Error getting active location awareness client info, rc=%Rrc\n", rc2);1500 VGSvcError("Error getting active location awareness client info, rc=%Rrc\n", rc2); 1498 1501 } 1499 1502 } 1500 1503 } 1501 1504 else if (RT_FAILURE(rc2)) 1502 VBoxServiceError("Error getting attached value of location awareness client %RU32, rc=%Rrc\n", 1503 uLAClientID, rc2); 1505 VGSvcError("Error getting attached value of location awareness client %RU32, rc=%Rrc\n", uLAClientID, rc2); 1504 1506 if (pszAttach) 1505 1507 RTStrFree(pszAttach); … … 1507 1509 else 1508 1510 { 1509 V BoxServiceVerbose(1, "VRDP: UTTSC disconnected from VRDP server\n");1510 v boxServiceFreeLAClientInfo(&g_LAClientInfo);1511 VGSvcVerbose(1, "VRDP: UTTSC disconnected from VRDP server\n"); 1512 vgsvcFreeLAClientInfo(&g_LAClientInfo); 1511 1513 } 1512 1514 … … 1520 1522 { 1521 1523 s_iBitchedAboutLAClient++; 1522 V BoxServiceError("VRDP: Querying connected location awareness client failed with rc=%Rrc\n", rc2);1524 VGSvcError("VRDP: Querying connected location awareness client failed with rc=%Rrc\n", rc2); 1523 1525 } 1524 1526 } 1525 1527 1526 V BoxServiceVerbose(3, "VRDP: Handling location awareness done\n");1528 VGSvcVerbose(3, "VRDP: Handling location awareness done\n"); 1527 1529 1528 1530 /* … … 1533 1535 if (idNewSession != g_idVMInfoSession) 1534 1536 { 1535 V BoxServiceVerbose(3, "The VM session ID changed, flushing all properties\n");1536 v boxserviceVMInfoWriteFixedProperties();1537 V BoxServicePropCacheFlush(&g_VMInfoPropCache);1537 VGSvcVerbose(3, "The VM session ID changed, flushing all properties\n"); 1538 vgsvcVMInfoWriteFixedProperties(); 1539 VGSvcPropCacheFlush(&g_VMInfoPropCache); 1538 1540 g_idVMInfoSession = idNewSession; 1539 1541 } … … 1553 1555 if (rc2 != VERR_TIMEOUT && RT_FAILURE(rc2)) 1554 1556 { 1555 V BoxServiceError("RTSemEventMultiWait failed; rc2=%Rrc\n", rc2);1557 VGSvcError("RTSemEventMultiWait failed; rc2=%Rrc\n", rc2); 1556 1558 rc = rc2; 1557 1559 break; … … 1562 1564 rc2 = RTSemEventMultiReset(g_hVMInfoEvent); 1563 1565 if (RT_FAILURE(rc2)) 1564 rc2 = V BoxServiceError("RTSemEventMultiReset failed; rc2=%Rrc\n", rc2);1566 rc2 = VGSvcError("RTSemEventMultiReset failed; rc2=%Rrc\n", rc2); 1565 1567 } 1566 1568 } … … 1574 1576 1575 1577 1576 /** @copydoc VBOXSERVICE::pfnStop */ 1577 static DECLCALLBACK(void) VBoxServiceVMInfoStop(void) 1578 /** 1579 * @interface_method_impl{VBOXSERVICE,pfnStop} 1580 */ 1581 static DECLCALLBACK(void) vbsvcVMInfoStop(void) 1578 1582 { 1579 1583 RTSemEventMultiSignal(g_hVMInfoEvent); … … 1581 1585 1582 1586 1583 /** @copydoc VBOXSERVICE::pfnTerm */ 1584 static DECLCALLBACK(void) VBoxServiceVMInfoTerm(void) 1587 /** 1588 * @interface_method_impl{VBOXSERVICE,pfnTerm} 1589 */ 1590 static DECLCALLBACK(void) vbsvcVMInfoTerm(void) 1585 1591 { 1586 1592 if (g_hVMInfoEvent != NIL_RTSEMEVENTMULTI) … … 1602 1608 1603 1609 /* Destroy LA client info. */ 1604 v boxServiceFreeLAClientInfo(&g_LAClientInfo);1610 vgsvcFreeLAClientInfo(&g_LAClientInfo); 1605 1611 1606 1612 /* Destroy property cache. */ 1607 V BoxServicePropCacheDestroy(&g_VMInfoPropCache);1613 VGSvcPropCacheDestroy(&g_VMInfoPropCache); 1608 1614 1609 1615 /* Disconnect from guest properties service. */ 1610 1616 rc = VbglR3GuestPropDisconnect(g_uVMInfoGuestPropSvcClientID); 1611 1617 if (RT_FAILURE(rc)) 1612 V BoxServiceError("Failed to disconnect from guest property service! Error: %Rrc\n", rc);1618 VGSvcError("Failed to disconnect from guest property service! Error: %Rrc\n", rc); 1613 1619 g_uVMInfoGuestPropSvcClientID = 0; 1614 1620 … … 1640 1646 , 1641 1647 /* methods */ 1642 VBoxServiceVMInfoPreInit,1643 VBoxServiceVMInfoOption,1644 VBoxServiceVMInfoInit,1645 VBoxServiceVMInfoWorker,1646 VBoxServiceVMInfoStop,1647 VBoxServiceVMInfoTerm1648 vbsvcVMInfoPreInit, 1649 vbsvcVMInfoOption, 1650 vbsvcVMInfoInit, 1651 vbsvcVMInfoWorker, 1652 vbsvcVMInfoStop, 1653 vbsvcVMInfoTerm 1648 1654 }; 1649 1655 -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.h
r56294 r58029 19 19 #define ___VBoxServiceVMInfo_h 20 20 21 //RT_C_DECLS_BEGIN22 21 23 extern int vboxServiceUserUpdateF(PVBOXSERVICEVEPROPCACHE pCache, const char *pszUser, const char *pszDomain,24 22 extern int VGSvcUserUpdateF(PVBOXSERVICEVEPROPCACHE pCache, const char *pszUser, const char *pszDomain, 23 const char *pszKey, const char *pszValueFormat, ...); 25 24 26 //RT_C_DECLS_END27 25 28 26 extern uint32_t g_uVMInfoUserIdleThresholdMS; 29 27 30 #endif /* ___VBoxServiceVMInfo_h */28 #endif 31 29
Note:
See TracChangeset
for help on using the changeset viewer.