VirtualBox

Changeset 88990 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
May 11, 2021 10:56:28 PM (4 years ago)
Author:
vboxsync
Message:

FE/VBoxHeadless: VBOX_WITH_SAVESTATE_ON_SIGNAL - g/c well-intentioned
but overthunk signal handler. The signal will interrupt event queue
processing for us (NB: with VINF_SUCCESS), so just set the flag and
let the event loop see it and terminate. bugref:8161

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp

    r88989 r88990  
    6060#ifdef VBOX_WITH_SAVESTATE_ON_SIGNAL
    6161#include <signal.h>
     62static void HandleSignal(int sig);
    6263#endif
    6364
     
    391392
    392393#ifdef VBOX_WITH_SAVESTATE_ON_SIGNAL
    393 static void SaveState(int sig)
     394static void
     395HandleSignal(int sig)
    394396{
    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;
    448399}
    449400#endif /* VBOX_WITH_SAVESTATE_ON_SIGNAL */
     
    14541405
    14551406#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);
    14581418#endif
    14591419
     
    15231483
    15241484        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()));
    15261491
    15271492        rc = showProgress(pProgress);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette