static DWORD LwSmStopOnly( 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("Stopping service: %s\n", pArgv[1]); } dwError = LwSmStopService(hHandle); BAIL_ON_ERROR(dwError); cleanup: LW_SAFE_FREE_MEMORY(pwszServiceName); if (hHandle) { LwSmReleaseServiceHandle(hHandle); } return dwError; error: goto cleanup; }
DWORD VmwDeployStopService( 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 = LwSmStopService(hService); BAIL_ON_DEPLOY_ERROR(dwError); cleanup: if (hService) { LwSmReleaseServiceHandle(hService); } if (pwszName) { VmwDeployFreeMemory(pwszName); } return dwError; error: goto cleanup; }
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; }
static DWORD LwSmStop( 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 = LwSmQueryServiceReverseDependencyClosure(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_STOPPED) { if (!gState.bQuiet) { dwError = LwWc16sToMbs(ppwszDependencies[i], &pszTemp); BAIL_ON_ERROR(dwError); printf("Stopping service reverse dependency: %s\n", pszTemp); LW_SAFE_FREE_MEMORY(pszTemp); } dwError = LwSmStopService(hDepHandle); BAIL_ON_ERROR(dwError); } dwError = LwSmReleaseServiceHandle(hDepHandle); hDepHandle = NULL; BAIL_ON_ERROR(dwError); } if (!gState.bQuiet) { printf("Stopping service: %s\n", pArgv[1]); } dwError = LwSmStopService(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; }