mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-27 07:34:15 +02:00
parent
8557293ac4
commit
3d52acfe5d
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "thresholds.h"
|
#include "thresholds.h"
|
||||||
|
|
||||||
#include "boost\program_options.hpp"
|
#include "boost/program_options.hpp"
|
||||||
|
|
||||||
#define VERSION 1.0
|
#define VERSION 1.0
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct&
|
|||||||
L"%s' thresholds work differently, since a service is either running or not\n"
|
L"%s' thresholds work differently, since a service is either running or not\n"
|
||||||
L"all \"-w\" and \"-c\" do is say whether a not running service is a warning\n"
|
L"all \"-w\" and \"-c\" do is say whether a not running service is a warning\n"
|
||||||
L"or critical state respectively.\n"
|
L"or critical state respectively.\n"
|
||||||
, progName);
|
, progName, progName);
|
||||||
cout << endl;
|
cout << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -169,20 +169,16 @@ int ServiceStatus(const printInfoStruct& printInfo)
|
|||||||
if (service_api == NULL)
|
if (service_api == NULL)
|
||||||
goto die;
|
goto die;
|
||||||
|
|
||||||
|
|
||||||
LPBYTE lpServices = NULL;
|
LPBYTE lpServices = NULL;
|
||||||
DWORD cbBufSize = 0;
|
DWORD cbBufSize = 0;
|
||||||
DWORD *pcbBytesNeeded = (LPDWORD)malloc(sizeof(DWORD));
|
DWORD *pcbBytesNeeded = NULL, *lpServicesReturned = NULL, *lpResumeHandle = NULL;
|
||||||
DWORD *lpServicesReturned = (LPDWORD)malloc(sizeof(DWORD));
|
|
||||||
DWORD *lpResumeHandle = (LPDWORD)malloc(sizeof(DWORD));
|
|
||||||
*lpResumeHandle = 0;
|
|
||||||
|
|
||||||
if (!EnumServicesStatusEx(service_api, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL,
|
if (!EnumServicesStatusEx(service_api, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL,
|
||||||
lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, NULL)
|
lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, NULL)
|
||||||
&& GetLastError() != ERROR_MORE_DATA)
|
&& GetLastError() != ERROR_MORE_DATA)
|
||||||
goto die;
|
goto die;
|
||||||
|
|
||||||
lpServices = (LPBYTE)malloc(*pcbBytesNeeded);
|
lpServices = new BYTE[*pcbBytesNeeded];
|
||||||
cbBufSize = *pcbBytesNeeded;
|
cbBufSize = *pcbBytesNeeded;
|
||||||
|
|
||||||
if (!EnumServicesStatusEx(service_api, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL,
|
if (!EnumServicesStatusEx(service_api, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL,
|
||||||
@ -192,11 +188,15 @@ int ServiceStatus(const printInfoStruct& printInfo)
|
|||||||
LPENUM_SERVICE_STATUS_PROCESS pInfo = (LPENUM_SERVICE_STATUS_PROCESS)lpServices;
|
LPENUM_SERVICE_STATUS_PROCESS pInfo = (LPENUM_SERVICE_STATUS_PROCESS)lpServices;
|
||||||
|
|
||||||
for (DWORD i = 0; i< *lpServicesReturned; i++) {
|
for (DWORD i = 0; i< *lpServicesReturned; i++) {
|
||||||
if (!wcscmp(printInfo.service.c_str(), pInfo[i].lpServiceName))
|
if (!wcscmp(printInfo.service.c_str(), pInfo[i].lpServiceName)) {
|
||||||
|
delete lpServices;
|
||||||
return pInfo[i].ServiceStatusProcess.dwCurrentState;
|
return pInfo[i].ServiceStatusProcess.dwCurrentState;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
die:
|
die:
|
||||||
|
if (lpServices)
|
||||||
|
delete lpServices;
|
||||||
wcout << L"Service " << printInfo.service << L" could not be found" << endl;
|
wcout << L"Service " << printInfo.service << L" could not be found" << endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user