VirtualBox

Changeset 12723 in vbox for trunk/src


Ignore:
Timestamp:
Sep 25, 2008 12:10:33 PM (16 years ago)
Author:
vboxsync
Message:

VBoxService: Added some Assert(), fixed return value of service control handler, cosmetics.

Location:
trunk/src/VBox/Additions/WINNT/VBoxService
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/VBoxService/VBoxService.cpp

    r11982 r12723  
    137137    Log(("VBoxService: Starting services ...\n"));
    138138
     139    Assert(pEnv);
    139140    pEnv->hStopEvent = CreateEvent (NULL, TRUE, FALSE, NULL);
    140141
     
    211212{
    212213    /* Signal to all threads. */
     214    Assert(pEnv);
     215    Assert(pTable);
    213216    if (bAlert && (NULL != pEnv->hStopEvent))
    214217    {
     
    278281
    279282    /* Start service threads. */
    280     /*gServiceEnv.hInstance = gInstance;
    281     gServiceEnv.hDriver   = gVBoxDriver;*/
    282 
    283     int rc = vboxStartServices (&gServiceEnv, vboxServiceTable);
     283    int rc = vboxStartServices(&gServiceEnv, vboxServiceTable);
    284284
    285285    /** @todo Add error handling. */
     
    293293                                 LPVOID lpContext)
    294294{
     295    DWORD rc = NO_ERROR;
     296
    295297    switch (dwControl)
    296298    {
    297299
    298300    case SERVICE_CONTROL_INTERROGATE:
    299         SetStatus (gvboxServiceStatusCode);
     301        SetStatus(gvboxServiceStatusCode);
    300302        break;
    301303
     
    303305    case SERVICE_CONTROL_SHUTDOWN:
    304306        {
    305             SetStatus (SERVICE_STOP_PENDING);
    306 
    307             vboxStopServices (TRUE, &gServiceEnv, vboxServiceTable);
    308 
    309             /*CloseHandle(gvboxDriver);*/
     307            SetStatus(SERVICE_STOP_PENDING);
     308
     309            vboxStopServices(TRUE, &gServiceEnv, vboxServiceTable);
     310
     311            /* Don't close VBox driver here - the service might be
     312             * started again. */
    310313            CloseHandle(gStopSem);
    311314
    312             SetStatus (SERVICE_STOPPED);
     315            SetStatus(SERVICE_STOPPED);
    313316        }
    314317        break;
     
    330333
    331334    default:
    332         /** @todo r=bird: Andy, you should probably return ERROR_CALL_NOT_IMPLEMENTED here.
    333          * Whoever omitted the DWORD return here and WINAPI bit here has been very sloppy :-| */
     335
     336        Log(("VBoxService: Service control function not implemented: %ld\n", dwControl));
     337        rc = ERROR_CALL_NOT_IMPLEMENTED;
    334338        break;
    335339    }
    336     return NO_ERROR;
     340    return rc;
    337341}
    338342
     
    355359            break;
    356360        default:
    357             writeLog("VBoxService: Could not register service control handle! Error: %d\n", dwErr);
     361            writeLog("VBoxService: Could not register service control handle! Error: %ld\n", dwErr);
    358362            break;
    359363        }
     
    363367        vboxServiceStart();
    364368
    365         while( 1) {
    366             Sleep( 100 );       /** @todo */
     369        while (1) {
     370            Sleep (100);       /** @todo */
    367371        }
    368372    }
     
    387391                                VBOXSERVICE_NAME, VBOXSERVICE_FRIENDLY_NAME,
    388392                                SERVICE_ALL_ACCESS,
    389                                 SERVICE_WIN32_OWN_PROCESS|SERVICE_INTERACTIVE_PROCESS,
     393                                SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,
    390394                                SERVICE_DEMAND_START,SERVICE_ERROR_NORMAL,
    391395                                imagePath, NULL, NULL, NULL, NULL, NULL);
     
    393397    if (NULL == hService) {
    394398        writeLog("VBoxService: Could not create service! Error: %d\n", GetLastError());
    395         CloseServiceHandle (hSCManager);
     399        CloseServiceHandle(hSCManager);
    396400        return 1;
    397401    }
     
    401405    }
    402406
    403     CloseServiceHandle (hService);
    404     CloseServiceHandle (hSCManager);
     407    CloseServiceHandle(hService);
     408    CloseServiceHandle(hSCManager);
    405409
    406410    return 0;
     
    410414{
    411415    SC_HANDLE hService, hSCManager;
    412     hSCManager = OpenSCManager (NULL,NULL,SC_MANAGER_ALL_ACCESS);
     416    hSCManager = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
    413417
    414418    writeLog("VBoxService: Uninstalling service ...\n");
     
    435439    else
    436440    {
    437         HKEY hKey;
    438         if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\EventLog\\System"), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) {
    439             RegDeleteKey (hKey, VBOXSERVICE_NAME);
    440             RegCloseKey (hKey);
     441        HKEY hKey = NULL;
     442        if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\EventLog\\System"), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) {
     443            RegDeleteKey(hKey, VBOXSERVICE_NAME);
     444            RegCloseKey(hKey);
    441445        }
    442446
     
    444448    }
    445449
    446     CloseServiceHandle (hService);
    447     CloseServiceHandle (hSCManager);
     450    CloseServiceHandle(hService);
     451    CloseServiceHandle(hSCManager);
    448452
    449453    return 0;
     
    453457{
    454458    char szBuffer[1024] = { 0 };
     459
     460    Assert(a_pszText);
    455461
    456462    va_list va;
     
    466472void printHelp (_TCHAR* a_pszName)
    467473{
     474    Assert(a_pszName);
    468475    _tprintf(_T("VBoxService - Guest Additions Helper Service for Windows XP/2K/Vista\n"));
    469476    _tprintf(_T("Version: %d.%d.%d.%d\n\n"), VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV);
     
    505512    static SERVICE_TABLE_ENTRY const s_serviceTable[]=
    506513    {
    507         { VBOXSERVICE_NAME, ServiceMain },
     514        {VBOXSERVICE_NAME, ServiceMain},
    508515        {NULL,NULL}
    509516    };
     
    527534
    528535        else {
    529             _tprintf (_T("Invalid command line argument: %ws\n"), argv[1]);
    530             _tprintf (_T("Type %s /h to display help.\n"), argv[0]);
     536            _tprintf(_T("Invalid command line argument: %ws\n"), argv[1]);
     537            _tprintf(_T("Type %s /h to display help.\n"), argv[0]);
    531538        }
    532539    }
  • trunk/src/VBox/Additions/WINNT/VBoxService/VBoxService.h

    r11982 r12723  
    2424
    2525#include <iprt/alloc.h>
     26#include <iprt/assert.h>
    2627#include <iprt/initterm.h>
    2728#include <iprt/string.h>
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