Changeset 88990 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- May 11, 2021 10:56:28 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp
r88989 r88990 60 60 #ifdef VBOX_WITH_SAVESTATE_ON_SIGNAL 61 61 #include <signal.h> 62 static void HandleSignal(int sig); 62 63 #endif 63 64 … … 391 392 392 393 #ifdef VBOX_WITH_SAVESTATE_ON_SIGNAL 393 static void SaveState(int sig) 394 static void 395 HandleSignal(int sig) 394 396 { 395 ComPtr <IProgress> progress = NULL; 396 397 /** @todo Deal with nested signals, multithreaded signal dispatching (esp. on windows), 398 * and multiple signals (both SIGINT and SIGTERM in some order). 399 * Consider processing the signal request asynchronously since there are lots of things 400 * which aren't safe (like RTPrintf and printf IIRC) in a signal context. */ 401 402 RTPrintf("Signal received, saving state.\n"); 403 404 HRESULT rc = gConsole->SaveState(progress.asOutParam()); 405 if (FAILED(rc)) 406 { 407 RTPrintf("Error saving state! rc = 0x%x\n", rc); 408 return; 409 } 410 Assert(progress); 411 LONG cPercent = 0; 412 413 RTPrintf("0%%"); 414 RTStrmFlush(g_pStdOut); 415 for (;;) 416 { 417 BOOL fCompleted = false; 418 rc = progress->COMGETTER(Completed)(&fCompleted); 419 if (FAILED(rc) || fCompleted) 420 break; 421 ULONG cPercentNow; 422 rc = progress->COMGETTER(Percent)(&cPercentNow); 423 if (FAILED(rc)) 424 break; 425 if ((cPercentNow / 10) != (cPercent / 10)) 426 { 427 cPercent = cPercentNow; 428 RTPrintf("...%d%%", cPercentNow); 429 RTStrmFlush(g_pStdOut); 430 } 431 432 /* wait */ 433 rc = progress->WaitForCompletion(100); 434 } 435 436 HRESULT lrc; 437 rc = progress->COMGETTER(ResultCode)(&lrc); 438 if (FAILED(rc)) 439 lrc = ~0; 440 if (!lrc) 441 { 442 RTPrintf(" -- Saved the state successfully.\n"); 443 RTThreadYield(); 444 } 445 else 446 RTPrintf("-- Error saving state, lrc=%d (%#x)\n", lrc, lrc); 447 397 RT_NOREF(sig); 398 g_fTerminateFE = true; 448 399 } 449 400 #endif /* VBOX_WITH_SAVESTATE_ON_SIGNAL */ … … 1454 1405 1455 1406 #ifdef VBOX_WITH_SAVESTATE_ON_SIGNAL 1456 signal(SIGINT, SaveState); 1457 signal(SIGTERM, SaveState); 1407 signal(SIGPIPE, SIG_IGN); 1408 signal(SIGTTOU, SIG_IGN); 1409 1410 struct sigaction sa; 1411 RT_ZERO(sa); 1412 sa.sa_handler = HandleSignal; 1413 sigaction(SIGHUP, &sa, NULL); 1414 sigaction(SIGINT, &sa, NULL); 1415 sigaction(SIGTERM, &sa, NULL); 1416 sigaction(SIGUSR1, &sa, NULL); 1417 sigaction(SIGUSR2, &sa, NULL); 1458 1418 #endif 1459 1419 … … 1523 1483 1524 1484 ComPtr<IProgress> pProgress; 1525 CHECK_ERROR_BREAK(gConsole, PowerDown(pProgress.asOutParam())); 1485 #ifdef VBOX_WITH_SAVESTATE_ON_SIGNAL 1486 if (!machine.isNull()) 1487 CHECK_ERROR_BREAK(machine, SaveState(pProgress.asOutParam())); 1488 else 1489 #endif 1490 CHECK_ERROR_BREAK(gConsole, PowerDown(pProgress.asOutParam())); 1526 1491 1527 1492 rc = showProgress(pProgress);
Note:
See TracChangeset
for help on using the changeset viewer.