Example #1
0
static
DWORD
LwSmStartOnly(
    int argc,
    char** pArgv
    )
{
    DWORD dwError = 0;
    PWSTR pwszServiceName = NULL;
    LW_SERVICE_HANDLE hHandle = NULL;
    
    dwError = LwMbsToWc16s(pArgv[1], &pwszServiceName);
    BAIL_ON_ERROR(dwError);
    
    dwError = LwSmAcquireServiceHandle(pwszServiceName, &hHandle);
    BAIL_ON_ERROR(dwError);
    
    if (!gState.bQuiet)
    {
        printf("Starting service: %s\n", pArgv[1]);
    }

    dwError = LwSmStartService(hHandle);
    BAIL_ON_ERROR(dwError);
    
cleanup:
    
    LW_SAFE_FREE_MEMORY(pwszServiceName);

    if (hHandle)
    {
        LwSmReleaseServiceHandle(hHandle);
    }

    return dwError;

error:

    goto cleanup;
}
Example #2
0
DWORD
VmwDeployStartService(
    PCSTR pszName
    )
{
    DWORD dwError = 0;
    PWSTR pwszName = NULL;
    LW_SERVICE_HANDLE hService = NULL;

    dwError = VmwDeployAllocateStringWFromA(
                    pszName,
                    &pwszName);
    BAIL_ON_DEPLOY_ERROR(dwError);

    dwError = LwSmAcquireServiceHandle(
                  pwszName,
                  &hService);
    BAIL_ON_DEPLOY_ERROR(dwError);

    dwError = LwSmStartService(hService);
    BAIL_ON_DEPLOY_ERROR(dwError);

cleanup:

    if (hService)
    {
        LwSmReleaseServiceHandle(hService);
    }
    if (pwszName)
    {
        VmwDeployFreeMemory(pwszName);
    }

    return dwError;

error:

    goto cleanup;
}
Example #3
0
static
DWORD
LwSmRestart(
    int argc,
    char** pArgv
    )
{
    DWORD dwError = 0;
    PWSTR pwszServiceName = NULL;
    LW_SERVICE_HANDLE hHandle = NULL;
    PWSTR* ppwszReverseDeps = NULL;
    PLW_SERVICE_STATUS pStatus = NULL;
    PLW_SERVICE_HANDLE phDepHandles = NULL;
    PWSTR* ppwszDependencies = NULL;
    LW_SERVICE_HANDLE hDepHandle = NULL;
    LW_SERVICE_STATUS status;
    PSTR pszTemp = NULL;
    size_t count = 0;
    size_t i = 0;

    dwError = LwMbsToWc16s(pArgv[1], &pwszServiceName);
    BAIL_ON_ERROR(dwError);

    dwError = LwSmAcquireServiceHandle(pwszServiceName, &hHandle);
    BAIL_ON_ERROR(dwError); 

    dwError = LwSmQueryServiceReverseDependencyClosure(hHandle, &ppwszReverseDeps);
    BAIL_ON_ERROR(dwError);
 
    count = LwSmStringListLength(ppwszReverseDeps);

    dwError = LwAllocateMemory(sizeof(*pStatus) * count, OUT_PPVOID(&pStatus));
    BAIL_ON_ERROR(dwError);

    dwError = LwAllocateMemory(sizeof(*phDepHandles) * count, OUT_PPVOID(&phDepHandles));
    BAIL_ON_ERROR(dwError);

    for (i = 0; i < count; i++)
    {
        dwError = LwSmAcquireServiceHandle(ppwszReverseDeps[i], &phDepHandles[i]);
        BAIL_ON_ERROR(dwError);

        dwError = LwSmQueryServiceStatus(phDepHandles[i], &pStatus[i]);
        BAIL_ON_ERROR(dwError);

        if (pStatus[i].state != LW_SERVICE_STATE_STOPPED)
        {
            if (!gState.bQuiet)
            {
                dwError = LwWc16sToMbs(ppwszReverseDeps[i], &pszTemp);
                BAIL_ON_ERROR(dwError);
                printf("Stopping service reverse dependency: %s\n", pszTemp);
                LW_SAFE_FREE_MEMORY(pszTemp);
            }
            dwError = LwSmStopService(phDepHandles[i]);
            BAIL_ON_ERROR(dwError);
        }
    }

    if (!gState.bQuiet)
    {
        printf("Stopping service: %s\n", pArgv[1]);
    }

    dwError = LwSmStopService(hHandle);
    BAIL_ON_ERROR(dwError);

    dwError = LwSmQueryServiceDependencyClosure(hHandle, &ppwszDependencies);
    BAIL_ON_ERROR(dwError);

    for (i = 0; ppwszDependencies[i]; i++)
    {
        dwError = LwSmAcquireServiceHandle(ppwszDependencies[i], &hDepHandle);
        BAIL_ON_ERROR(dwError);

        dwError = LwSmQueryServiceStatus(hDepHandle, &status);
        BAIL_ON_ERROR(dwError);

        if (status.state != LW_SERVICE_STATE_RUNNING)
        {
            if (!gState.bQuiet)
            {
                dwError = LwWc16sToMbs(ppwszDependencies[i], &pszTemp);
                BAIL_ON_ERROR(dwError);
                
                printf("Starting service dependency: %s\n", pszTemp);
                LW_SAFE_FREE_MEMORY(pszTemp);
            }

            dwError = LwSmStartService(hDepHandle);
            BAIL_ON_ERROR(dwError);
        }

        dwError = LwSmReleaseServiceHandle(hDepHandle);
        hDepHandle = NULL;
        BAIL_ON_ERROR(dwError);
    }

    if (!gState.bQuiet)
    {
        printf("Starting service: %s\n", pArgv[1]);
    }

    dwError = LwSmStartService(hHandle);
    BAIL_ON_ERROR(dwError);

    for (i = 0; i < count; i++)
    {
        if (pStatus[count - 1 - i].state == LW_SERVICE_STATE_RUNNING)
        {
            if (!gState.bQuiet)
            {
                dwError = LwWc16sToMbs(ppwszReverseDeps[count - 1 - i], &pszTemp);
                BAIL_ON_ERROR(dwError);
                printf("Starting service reverse dependency: %s\n", pszTemp);
                LW_SAFE_FREE_MEMORY(pszTemp);
            }
            dwError = LwSmStartService(phDepHandles[count - 1 - i]);
            BAIL_ON_ERROR(dwError);
        }
    }

cleanup:

    LW_SAFE_FREE_MEMORY(pwszServiceName);
    LW_SAFE_FREE_MEMORY(pStatus);

    if (hHandle)
    {
        LwSmReleaseServiceHandle(hHandle);
    }

    if (phDepHandles)
    {
        for (i = 0; i < count; i++)
        {
            if (phDepHandles[i])
            {
                LwSmReleaseServiceHandle(phDepHandles[i]);
            }
        }

        LW_SAFE_FREE_MEMORY(phDepHandles);
    }
    if (ppwszReverseDeps)
    {
        LwSmFreeServiceNameList(ppwszReverseDeps);
        ppwszReverseDeps = NULL;
    }

    if (hDepHandle)
    {
        LwSmReleaseServiceHandle(hDepHandle);
        hDepHandle = NULL;
    }
    if (ppwszDependencies)
    {
        LwSmFreeServiceNameList(ppwszDependencies);
        ppwszDependencies = NULL;
    }

    return dwError;

error:

    goto cleanup;
}
Example #4
0
static
DWORD
LwSmStart(
    int argc,
    char** pArgv
    )
{
    DWORD dwError = 0;
    PWSTR pwszServiceName = NULL;
    LW_SERVICE_HANDLE hHandle = NULL;
    LW_SERVICE_HANDLE hDepHandle = NULL;
    LW_SERVICE_STATUS status = {0};
    PWSTR* ppwszDependencies = NULL;
    PSTR pszTemp = NULL;
    size_t i = 0;

    dwError = LwMbsToWc16s(pArgv[1], &pwszServiceName);
    BAIL_ON_ERROR(dwError);
    
    dwError = LwSmAcquireServiceHandle(pwszServiceName, &hHandle);
    BAIL_ON_ERROR(dwError);
    
    dwError = LwSmQueryServiceDependencyClosure(hHandle, &ppwszDependencies);
    BAIL_ON_ERROR(dwError);

    for (i = 0; ppwszDependencies[i]; i++)
    {
        dwError = LwSmAcquireServiceHandle(ppwszDependencies[i], &hDepHandle);
        BAIL_ON_ERROR(dwError);

        dwError = LwSmQueryServiceStatus(hDepHandle, &status);
        BAIL_ON_ERROR(dwError);

        if (status.state != LW_SERVICE_STATE_RUNNING)
        {
            if (!gState.bQuiet)
            {
                dwError = LwWc16sToMbs(ppwszDependencies[i], &pszTemp);
                BAIL_ON_ERROR(dwError);
                
                printf("Starting service dependency: %s\n", pszTemp);
                LW_SAFE_FREE_MEMORY(pszTemp);
            }

            dwError = LwSmStartService(hDepHandle);
            BAIL_ON_ERROR(dwError);
        }

        dwError = LwSmReleaseServiceHandle(hDepHandle);
        hDepHandle = NULL;
        BAIL_ON_ERROR(dwError);
    }

    if (!gState.bQuiet)
    {
        printf("Starting service: %s\n", pArgv[1]);
    }

    dwError = LwSmStartService(hHandle);
    BAIL_ON_ERROR(dwError);
    
cleanup:
    
    LW_SAFE_FREE_MEMORY(pwszServiceName);
    LW_SAFE_FREE_MEMORY(pszTemp);

    if (ppwszDependencies)
    {
        LwSmFreeServiceNameList(ppwszDependencies);
    }

    if (hHandle)
    {
        LwSmReleaseServiceHandle(hHandle);
    }

    if (hDepHandle)
    {
        LwSmReleaseServiceHandle(hDepHandle);
    }

    return dwError;

error:

    goto cleanup;
}
Example #5
0
static
DWORD
LwSmAutostart(
    int argc,
    char** pArgv
    )
{
    DWORD dwError = 0;
    PWSTR *ppwszAllServices = NULL;
    LW_SERVICE_HANDLE hHandle = NULL;
    PLW_SERVICE_INFO pInfo = NULL;
    size_t i = 0;
    PWSTR *ppwszDependencies = NULL;
    LW_SERVICE_HANDLE hDepHandle = NULL;
    LW_SERVICE_STATUS status = {0};
    PSTR pszTemp = NULL;
    size_t j = 0;

    dwError = LwSmEnumerateServices(&ppwszAllServices);
    BAIL_ON_ERROR(dwError);

    for (i = 0; ppwszAllServices[i]; i++)
    {
        dwError = LwSmAcquireServiceHandle(ppwszAllServices[i], &hHandle);
        BAIL_ON_ERROR(dwError);

        dwError = LwSmQueryServiceInfo(hHandle, &pInfo);
        BAIL_ON_ERROR(dwError);

        if (pInfo->bAutostart)
        {
            dwError = LwSmQueryServiceDependencyClosure(
                            hHandle,
                            &ppwszDependencies);
            BAIL_ON_ERROR(dwError);

            for (j = 0; ppwszDependencies[j]; j++)
            {
                dwError = LwSmAcquireServiceHandle(
                                ppwszDependencies[j],
                                &hDepHandle);
                BAIL_ON_ERROR(dwError);

                dwError = LwSmQueryServiceStatus(hDepHandle, &status);
                BAIL_ON_ERROR(dwError);

                if (status.state != LW_SERVICE_STATE_RUNNING)
                {
                    if (!gState.bQuiet)
                    {
                        dwError = LwWc16sToMbs(ppwszDependencies[j], &pszTemp);
                        BAIL_ON_ERROR(dwError);

                        printf("Starting service dependency: %s\n", pszTemp);
                        LW_SAFE_FREE_MEMORY(pszTemp);
                    }

                    dwError = LwSmStartService(hDepHandle);
                    BAIL_ON_ERROR(dwError);
                }

                dwError = LwSmReleaseServiceHandle(hDepHandle);
                hDepHandle = NULL;
                BAIL_ON_ERROR(dwError);
            }

            if (ppwszDependencies)
            {
                LwSmFreeServiceNameList(ppwszDependencies);
                ppwszDependencies = NULL;
            }

            if (!gState.bQuiet)
            {
                dwError = LwWc16sToMbs(ppwszAllServices[i], &pszTemp);
                BAIL_ON_ERROR(dwError);

                printf("Starting service: %s\n", pszTemp);
                LW_SAFE_FREE_MEMORY(pszTemp);
            }

            dwError = LwSmStartService(hHandle);
            BAIL_ON_ERROR(dwError);
        }

        dwError = LwSmReleaseServiceHandle(hHandle);
        hHandle = NULL;
        BAIL_ON_ERROR(dwError);
    }

cleanup:

    if (hHandle)
    {
        LwSmReleaseServiceHandle(hHandle);
        hHandle = NULL;
    }

    if (ppwszAllServices)
    {
        LwSmFreeStringList(ppwszAllServices);
        ppwszAllServices = NULL;
    }

    if (ppwszDependencies)
    {
        LwSmFreeServiceNameList(ppwszDependencies);
        ppwszDependencies = NULL;
    }

    if (hDepHandle)
    {
        LwSmReleaseServiceHandle(hDepHandle);
        hDepHandle = NULL;
    }

    LW_SAFE_FREE_MEMORY(pszTemp);

    return dwError;

error:

    goto cleanup;
}