]> granicus.if.org Git - icinga2/commitdiff
Fix major bugs in windows plugins check_load and check_service
authorJean Flach <jean-marcel.flach@netways.de>
Tue, 9 Dec 2014 14:38:23 +0000 (15:38 +0100)
committerJean Flach <jean-marcel.flach@netways.de>
Tue, 9 Dec 2014 14:38:23 +0000 (15:38 +0100)
fixes #7881 #7992

plugins/check_load.cpp
plugins/check_service.cpp

index 4f69872b0a9d6751e0d801702b4a1bb7df498b14..8adaceaabae7cddb85bea77dfa82f7140fa054d0 100644 (file)
@@ -56,8 +56,7 @@ int wmain(int argc, wchar_t **argv)
        if (ret != -1)
                return ret;
 
-       printOutput(printInfo);
-       return 1;
+       return printOutput(printInfo);
 }
 
 int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct& printInfo) {
@@ -110,8 +109,7 @@ int parseArguments(int ac, wchar_t **av, po::variables_map& vm, printInfoStruct&
                        L"and \"67%%\" is the returned value.\n"
                        L"The performance data is found behind the \"|\", in order:\n"
                        L"returned value, warning threshold, critical threshold, minimal value and,\n"
-                       L"if applicable, the maximal value. Performance data will only be displayed when\n"
-                       L"you set at least one threshold\n\n"
+                       L"if applicable, the maximal value.\n\n"
                        L"%s' exit codes denote the following:\n"
                        L" 0\tOK,\n\tNo Thresholds were broken or the programs check part was not executed\n"
                        L" 1\tWARNING,\n\tThe warning, but not the critical threshold was broken\n"
index b55045420bf38ad6269f58c962ed4c8eade51310..ccfd19677d0c826bb2b6f01ebffbbf8ba43a8b63 100644 (file)
@@ -171,32 +171,36 @@ int ServiceStatus(const printInfoStruct& printInfo)
 
        LPBYTE lpServices = NULL;
        DWORD cbBufSize = 0;
-       DWORD *pcbBytesNeeded = NULL, *lpServicesReturned = NULL, *lpResumeHandle = NULL;
+       DWORD pcbBytesNeeded = NULL, ServicesReturned = NULL, ResumeHandle = NULL;
 
        if (!EnumServicesStatusEx(service_api, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL,
-               lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, NULL)
+               lpServices, cbBufSize, &pcbBytesNeeded, &ServicesReturned, &ResumeHandle, NULL)
                && GetLastError() != ERROR_MORE_DATA) 
                goto die;
 
-       lpServices = reinterpret_cast<LPBYTE>(new BYTE[*pcbBytesNeeded]);
-       cbBufSize = *pcbBytesNeeded;
+       lpServices = reinterpret_cast<LPBYTE>(new BYTE[pcbBytesNeeded]);
+       cbBufSize = pcbBytesNeeded;
 
        if (!EnumServicesStatusEx(service_api, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL,
-               lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, NULL))
+               lpServices, cbBufSize, &pcbBytesNeeded, &ServicesReturned, &ResumeHandle, NULL))
                goto die;
 
        LPENUM_SERVICE_STATUS_PROCESS pInfo = (LPENUM_SERVICE_STATUS_PROCESS)lpServices;
     
-       for (DWORD i = 0; i< *lpServicesReturned; i++) {
+       for (DWORD i = 0; i < ServicesReturned; i++) {
                if (!wcscmp(printInfo.service.c_str(), pInfo[i].lpServiceName)) {
+                       int state = pInfo[i].ServiceStatusProcess.dwCurrentState;
                        delete lpServices;
-                       return pInfo[i].ServiceStatusProcess.dwCurrentState;
+                       return state;
                }
        }
+       wcout << L"Service " << printInfo.service << L" could not be found\n";
+       delete[] reinterpret_cast<LPBYTE>(lpServices);
+       return -1;
 
 die:
+       die();
        if (lpServices)
                delete[] reinterpret_cast<LPBYTE>(lpServices);
-       wcout << L"Service " << printInfo.service << L" could not be found" << endl;
        return -1;
 }