VirtualBox

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


Ignore:
Timestamp:
Jun 8, 2021 5:34:49 PM (4 years ago)
Author:
vboxsync
Message:

Main: bugref:9341: Fixed com initialization in the autostart service. Autostart service stops after VM started.

Location:
trunk/src/VBox/Frontends/VBoxAutostart
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostart-win.cpp

    r89359 r89571  
    4545#include <iprt/initterm.h>
    4646#include <iprt/mem.h>
     47#include <iprt/message.h>
    4748#include <iprt/process.h>
    4849#include <iprt/path.h>
     
    940941                {
    941942                    LogFlow(("autostartSvcWinServiceMain: calling autostartStartVMs\n"));
    942                     RTEXITCODE ec = autostartStartVMs();
    943                     if (ec == RTEXITCODE_SUCCESS)
     943
     944                    /* check if we should stopped already, e.g. windows shutdown */
     945                    rc = RTSemEventMultiWait(g_hSupSvcWinEvent, 1);
     946                    if (RT_FAILURE(rc))
    944947                    {
    945                         LogFlow(("autostartSvcWinServiceMain: done string VMs\n"));
    946                         err = NO_ERROR;
    947                         rc = RTSemEventMultiWait(g_hSupSvcWinEvent, RT_INDEFINITE_WAIT);
    948                         if (RT_SUCCESS(rc))
     948                        /* No one signaled us to stop */
     949                        RTEXITCODE ec = autostartStartVMs();
     950                        if (ec == RTEXITCODE_SUCCESS)
    949951                        {
    950                             LogFlow(("autostartSvcWinServiceMain: woke up\n"));
    951                             /** @todo Autostop part. */
     952                            LogFlow(("autostartSvcWinServiceMain: done starting VMs\n"));
    952953                            err = NO_ERROR;
    953954                        }
    954                         else
    955                             autostartSvcLogError("RTSemEventWait failed, rc=%Rrc", rc);
     955                        /* No reason to keep started. Shutdown the service*/
    956956                    }
    957 
    958957                    autostartShutdown();
    959958                }
     
    10431042    } while (0);
    10441043
    1045 
     1044    /*
     1045     * Init com here for first main thread initialization.
     1046     * Service main function called in another thread
     1047     * created by service manager.
     1048     */
     1049    HRESULT hrc = com::Initialize();
     1050# ifdef VBOX_WITH_XPCOM
     1051    if (hrc == NS_ERROR_FILE_ACCESS_DENIED)
     1052    {
     1053        char szHome[RTPATH_MAX] = "";
     1054        com::GetVBoxUserHomeDirectory(szHome, sizeof(szHome));
     1055        return RTMsgErrorExit(RTEXITCODE_FAILURE,
     1056               "Failed to initialize COM because the global settings directory '%s' is not accessible!", szHome);
     1057    }
     1058# endif
     1059    if (FAILED(hrc))
     1060        return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to initialize COM (%Rhrc)!", hrc);
    10461061
    10471062    /*
     
    11171132            break;
    11181133    }
     1134
     1135    com::Shutdown();
     1136
    11191137    return RTEXITCODE_FAILURE;
    11201138}
  • trunk/src/VBox/Frontends/VBoxAutostart/VBoxAutostartStart.cpp

    r89360 r89571  
    175175                    }
    176176                }
    177                 g_pSession->UnlockMachine();
     177                SessionState_T enmSessionState;
     178                CHECK_ERROR(g_pSession, COMGETTER(State)(&enmSessionState));
     179                if (SUCCEEDED(rc) && enmSessionState == SessionState_Locked)
     180                    g_pSession->UnlockMachine();
    178181            }
    179182        }
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