VirtualBox

Changeset 36182 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 7, 2011 10:35:35 AM (14 years ago)
Author:
vboxsync
Message:

VBoxService: Fixed Windows mutex checking/creation.

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

Legend:

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

    r35907 r36182  
    55
    66/*
    7  * Copyright (C) 2007-2010 Oracle Corporation
     7 * Copyright (C) 2007-2011 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    591591        }
    592592    }
    593 #ifdef RT_OS_WINDOWS
    594     /*
    595      * Make sure only one instance of VBoxService runs at a time.  Create a
    596      * global mutex for that.  Do not use a global namespace ("Global\\") for
    597      * mutex name here, will blow up NT4 compatibility!
    598      */
    599     /** @todo r=bird: Use Global\\ prefix or this serves no purpose on terminal servers. */
    600     HANDLE hMutexAppRunning = CreateMutex(NULL, FALSE, VBOXSERVICE_NAME);
    601     if (   hMutexAppRunning != NULL
    602         && GetLastError() == ERROR_ALREADY_EXISTS)
    603     {
    604         VBoxServiceError("%s is already running! Terminating.", g_pszProgName);
    605 
    606         /* Close the mutex for this application instance. */
    607         CloseHandle(hMutexAppRunning);
    608         hMutexAppRunning = NULL;
    609 
    610         /** @todo r=bird: How does this cause us to terminate?  Btw. Why do
    611          *        we do this before parsing parameters?  'VBoxService --help'
    612          *        and 'VBoxService --version' won't work now when the service
    613          *        is running... */
    614     }
    615 #endif
    616593
    617594    /*
     
    736713        } while (psz && *++psz);
    737714    }
     715
     716#ifdef RT_OS_WINDOWS
     717    /*
     718     * Make sure only one instance of VBoxService runs at a time.  Create a
     719     * global mutex for that.
     720     */
     721    OSVERSIONINFOEX OSInfoEx;
     722    RT_ZERO(OSInfoEx);
     723    OSInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
     724
     725    HANDLE hMutexAppRunning;
     726    if (    GetVersionEx((LPOSVERSIONINFO) &OSInfoEx)
     727        &&  OSInfoEx.dwPlatformId == VER_PLATFORM_WIN32_NT
     728        &&  OSInfoEx.dwMajorVersion >= 5 /* NT 5.0 a.k.a W2K */)
     729    {
     730        hMutexAppRunning = CreateMutex(NULL, FALSE, VBOXSERVICE_NAME_GLOBAL);
     731    }
     732    else
     733    {
     734        /* On older Windows OSes (like NT4) don't use the global namespace
     735         * needed for terminal servers on Win2K+. */
     736        hMutexAppRunning = CreateMutex(NULL, FALSE, VBOXSERVICE_NAME);
     737    }
     738    if (   hMutexAppRunning != NULL
     739        && GetLastError() == ERROR_ALREADY_EXISTS)
     740    {
     741        VBoxServiceError("%s is already running! Terminating.", g_pszProgName);
     742
     743        /* Close the mutex for this application instance. */
     744        CloseHandle(hMutexAppRunning);
     745        hMutexAppRunning = NULL;
     746
     747        return RTEXITCODE_FAILURE;
     748    }
     749#else /* !RT_OS_WINDOWS */
     750    /** @todo Add PID file creation here. */
     751#endif /* RT_OS_WINDOWS */
     752
    738753    /*
    739754     * Check that at least one service is enabled.
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h

    r35954 r36182  
    9494/** The service name (needed for mutex creation on Windows). */
    9595#define VBOXSERVICE_NAME            "VBoxService"
     96#define VBOXSERVICE_NAME_GLOBAL     "Global\\VBoxService"
    9697
    9798#ifdef RT_OS_WINDOWS
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