Changeset 47629 in vbox for trunk/src/VBox/Frontends/VBoxManage
- Timestamp:
- Aug 9, 2013 9:33:08 AM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 87830
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp
r47625 r47629 68 68 69 69 /** Set by the signal handler. */ 70 static volatile bool g_fGuestCtrlCanceled = false; 70 static volatile bool g_fGuestCtrlCanceled = false; 71 /** Our global session object which is also used in the 72 * signal handler to abort operations properly. */ 73 static ComPtr<IGuestSession> g_pGuestSession; 71 74 72 75 typedef struct COPYCONTEXT … … 296 299 #ifndef VBOX_ONLY_DOCS 297 300 301 #ifdef RT_OS_WINDOWS 302 static BOOL WINAPI guestCtrlSignalHandler(DWORD dwCtrlType) 303 { 304 bool fEventHandled = FALSE; 305 switch (dwCtrlType) 306 { 307 /* User pressed CTRL+C or CTRL+BREAK or an external event was sent 308 * via GenerateConsoleCtrlEvent(). */ 309 case CTRL_BREAK_EVENT: 310 case CTRL_CLOSE_EVENT: 311 case CTRL_C_EVENT: 312 ASMAtomicWriteBool(&g_fGuestCtrlCanceled, true); 313 if (!g_pGuestSession.isNull()) 314 g_pGuestSession->Close(); 315 fEventHandled = TRUE; 316 break; 317 default: 318 break; 319 /** @todo Add other events here. */ 320 } 321 322 return fEventHandled; 323 } 324 #else /* !RT_OS_WINDOWS */ 298 325 /** 299 326 * Signal handler that sets g_fGuestCtrlCanceled. … … 307 334 NOREF(iSignal); 308 335 ASMAtomicWriteBool(&g_fGuestCtrlCanceled, true); 309 } 336 if (!g_pGuestSession.isNull()) 337 g_pGuestSession->Close(); 338 } 339 #endif 310 340 311 341 /** 312 342 * Installs a custom signal handler to get notified 313 343 * whenever the user wants to intercept the program. 344 * 345 ** @todo Make this handler available for all VBoxManage modules? 314 346 */ 315 static void ctrlSignalHandlerInstall() 316 { 347 static int ctrlSignalHandlerInstall(void) 348 { 349 int rc = VINF_SUCCESS; 350 #ifdef RT_OS_WINDOWS 351 if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)guestCtrlSignalHandler, TRUE /* Add handler */)) 352 { 353 rc = RTErrConvertFromWin32(GetLastError()); 354 RTMsgError("Unable to install console control handler, rc=%Rrc\n", rc); 355 } 356 #else 317 357 signal(SIGINT, guestCtrlSignalHandler); 318 # ifdef SIGBREAK358 # ifdef SIGBREAK 319 359 signal(SIGBREAK, guestCtrlSignalHandler); 360 # endif 320 361 #endif 362 return rc; 321 363 } 322 364 … … 324 366 * Uninstalls a previously installed signal handler. 325 367 */ 326 static void ctrlSignalHandlerUninstall() 327 { 368 static int ctrlSignalHandlerUninstall(void) 369 { 370 int rc = VINF_SUCCESS; 371 #ifdef RT_OS_WINDOWS 372 if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)NULL, FALSE /* Remove handler */)) 373 { 374 rc = RTErrConvertFromWin32(GetLastError()); 375 RTMsgError("Unable to uninstall console control handler, rc=%Rrc\n", rc); 376 } 377 #else 328 378 signal(SIGINT, SIG_DFL); 329 # ifdef SIGBREAK379 # ifdef SIGBREAK 330 380 signal(SIGBREAK, SIG_DFL); 381 # endif 331 382 #endif 383 return rc; 332 384 } 333 385 … … 835 887 return errorSyntax(USAGE_GUESTCONTROL, "Output conversion not implemented yet!"); 836 888 889 ctrlSignalHandlerInstall(); 890 837 891 /* 838 892 * Start with the real work. … … 848 902 * the session all over the places below again. Later. */ 849 903 850 ComPtr<IGuestSession> pGuestSession;851 904 try 852 905 { … … 860 913 Bstr(strDomain).raw(), 861 914 Bstr(strVBoxManage).raw(), 862 pGuestSession.asOutParam()));915 g_pGuestSession.asOutParam())); 863 916 864 917 /* Adjust process creation flags if we don't want to wait for process termination. */ … … 883 936 aSessionWaitFlags.push_back(GuestSessionWaitForFlag_Start); 884 937 GuestSessionWaitResult_T sessionWaitResult; 885 CHECK_ERROR_BREAK( pGuestSession, WaitForArray(ComSafeArrayAsInParam(aSessionWaitFlags), cMsTimeout, &sessionWaitResult));938 CHECK_ERROR_BREAK(g_pGuestSession, WaitForArray(ComSafeArrayAsInParam(aSessionWaitFlags), cMsTimeout, &sessionWaitResult)); 886 939 ULONG uSessionID; 887 CHECK_ERROR_BREAK( pGuestSession, COMGETTER(Id)(&uSessionID));940 CHECK_ERROR_BREAK(g_pGuestSession, COMGETTER(Id)(&uSessionID)); 888 941 889 942 if ( sessionWaitResult == GuestSessionWaitResult_Start … … 913 966 */ 914 967 ComPtr<IGuestProcess> pProcess; 915 CHECK_ERROR_BREAK( pGuestSession, ProcessCreate(Bstr(strCmd).raw(),968 CHECK_ERROR_BREAK(g_pGuestSession, ProcessCreate(Bstr(strCmd).raw(), 916 969 ComSafeArrayAsInParam(aArgs), 917 970 ComSafeArrayAsInParam(aEnv), … … 990 1043 } 991 1044 992 if ( FAILED(rc))1045 if (g_fGuestCtrlCanceled) 993 1046 break; 994 1047 … … 1009 1062 } 1010 1063 1011 if (RT_FAILURE(vrc)) 1064 if ( RT_FAILURE(vrc) 1065 || g_fGuestCtrlCanceled) 1012 1066 break; 1013 1067 … … 1022 1076 1023 1077 /* Report status back to the user. */ 1024 if (fCompleted) 1078 if ( fCompleted 1079 && !g_fGuestCtrlCanceled) 1025 1080 { 1026 1081 ProcessStatus_T procStatus; … … 1056 1111 } 1057 1112 1113 ctrlSignalHandlerUninstall(); 1114 1058 1115 bool fCloseSession = false; 1059 1116 if (SUCCEEDED(rc)) … … 1070 1127 1071 1128 if ( fCloseSession 1072 && ! pGuestSession.isNull())1129 && !g_pGuestSession.isNull()) 1073 1130 { 1074 1131 if (fVerbose) 1075 1132 RTPrintf("Closing guest session ...\n"); 1076 rc = pGuestSession->Close();1133 rc = g_pGuestSession->Close(); 1077 1134 } 1078 1135 else if (!fCloseSession && fVerbose)
Note:
See TracChangeset
for help on using the changeset viewer.