MCPcopy Create free account
hub / github.com/Icinga/icinga2 / getServiceStatus

Function getServiceStatus

plugins/check_service.cpp:221–260  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219}
220
221static DWORD getServiceStatus(const printInfoStruct& printInfo)
222{
223 SC_HANDLE hSCM;
224 SC_HANDLE hService;
225 DWORD cbBufSize;
226 DWORD lpResumeHandle = 0;
227 LPBYTE lpBuf = NULL;
228
229 if (l_Debug)
230 std::wcout << L"Opening SC Manager" << '\n';
231
232 hSCM = OpenSCManager(NULL, NULL, GENERIC_READ);
233 if (hSCM == NULL)
234 goto die;
235
236 hService = OpenService(hSCM, printInfo.service.c_str(), SERVICE_QUERY_STATUS);
237 if (hService == NULL)
238 goto die;
239
240 QueryServiceStatusEx(hService, SC_STATUS_PROCESS_INFO, NULL, 0, &cbBufSize);
241 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
242 goto die;
243
244 lpBuf = new BYTE[cbBufSize];
245 if (QueryServiceStatusEx(hService, SC_STATUS_PROCESS_INFO, lpBuf, cbBufSize, &cbBufSize)) {
246 LPSERVICE_STATUS_PROCESS pInfo = (LPSERVICE_STATUS_PROCESS)lpBuf;
247 return pInfo->dwCurrentState;
248 }
249
250die:
251 printErrorInfo();
252 if (hSCM)
253 CloseServiceHandle(hSCM);
254 if (hService)
255 CloseServiceHandle(hService);
256 if (lpBuf)
257 delete [] lpBuf;
258
259 return -1;
260}
261
262int wmain(int argc, WCHAR **argv)
263{

Callers 1

wmainFunction · 0.85

Calls 1

printErrorInfoFunction · 0.85

Tested by

no test coverage detected