diff options
-rwxr-xr-x | build/win32/include/config.h | 12 | ||||
-rwxr-xr-x | build/win32/project/zabbix_agentd.dsp | 8 | ||||
-rwxr-xr-x | include/daemon.h | 2 | ||||
-rwxr-xr-x | include/service.h | 3 | ||||
-rwxr-xr-x | include/symbols.h | 38 | ||||
-rw-r--r-- | src/libs/zbxlog/log.c | 2 | ||||
-rwxr-xr-x | src/libs/zbxsys/mutexs.c | 2 | ||||
-rwxr-xr-x | src/libs/zbxsys/symbols.c | 73 | ||||
-rw-r--r-- | src/libs/zbxsysinfo/common/common.c | 8 | ||||
-rwxr-xr-x | src/libs/zbxsysinfo/win32/memory.c | 82 | ||||
-rwxr-xr-x | src/libs/zbxsysinfo/win32/pdhmon.c | 91 | ||||
-rwxr-xr-x | src/libs/zbxsysinfo/win32/proc.c | 35 | ||||
-rwxr-xr-x | src/libs/zbxsysinfo/win32/services.c | 92 | ||||
-rwxr-xr-x | src/libs/zbxsysinfo/win32/swap.c | 71 | ||||
-rw-r--r-- | src/zabbix_agent/zabbix_agentd.c | 25 |
15 files changed, 418 insertions, 126 deletions
diff --git a/build/win32/include/config.h b/build/win32/include/config.h index ef2f9e56..607a8103 100755 --- a/build/win32/include/config.h +++ b/build/win32/include/config.h @@ -273,18 +273,6 @@ /* Define to 1 if you have the <sys/pstat.h> header file. */ /* #undef HAVE_SYS_PSTAT_H */ -/* Define to 1 if function 'GetPerformanceInfo' exist. Supported on 2000,2003,XP,Vista,Longhorn*/ -#define HAVE_GETPERFORMANCEINFO 1 - -/* Define to 1 if function 'GlobalMemoryStatusEx' exist. Supported on 2000,2003,XP,Vista,Longhorn*/ -#define HAVE_GLOBALMEMORYSTATUSEX 1 - -/* Define to 1 if function 'GetGuiResources' exist. Supported on 2000,2003,XP,Vista,Longhorn*/ -#define HAVE_GETGUIRESOURCES 1 - -/* Define to 1 if function 'GetProcessIoCounters' exist. Supported on 2000,2003,XP,Vista,Longhorn*/ -#define HAVE_GETPROCESSIOCOUNTERS 1 - /* Define to 1 if function 'setpriority' exist. */ //#define HAVE_SYS_RESOURCE_SETPRIORITY 1 diff --git a/build/win32/project/zabbix_agentd.dsp b/build/win32/project/zabbix_agentd.dsp index 06bc0361..07d1bdf0 100755 --- a/build/win32/project/zabbix_agentd.dsp +++ b/build/win32/project/zabbix_agentd.dsp @@ -1052,6 +1052,10 @@ SOURCE=..\..\..\src\libs\zbxsys\mutexs.c # End Source File # Begin Source File +SOURCE=..\..\..\src\libs\zbxsys\symbols.c +# End Source File +# Begin Source File + SOURCE=..\..\..\src\libs\zbxsys\threads.c # End Source File # End Group @@ -1202,6 +1206,10 @@ SOURCE=..\..\..\include\sms.h # End Source File # Begin Source File +SOURCE=..\..\..\include\symbols.h +# End Source File +# Begin Source File + SOURCE=..\..\..\include\sysinc.h # End Source File # Begin Source File diff --git a/include/daemon.h b/include/daemon.h index ed961c66..5afea932 100755 --- a/include/daemon.h +++ b/include/daemon.h @@ -46,4 +46,6 @@ void init_main_process(void); /* tall all threads what application must be closed - NOT needed for linux forks */ #define ZBX_DO_EXIT() +#define START_MAIN_ZABBIX_ENTRY(a) daemon_start(a) + #endif /* ZABBIX_DAEMON_H */ diff --git a/include/service.h b/include/service.h index 7b0225f6..29af770b 100755 --- a/include/service.h +++ b/include/service.h @@ -38,6 +38,7 @@ int ZabbixRemoveService(void); int ZabbixStartService(void); int ZabbixStopService(void); +#define init_main_process() /* APPLICATION running status */ /* requred for closing application from service */ @@ -52,4 +53,6 @@ extern int application_is_runned; /* ask for application closing status */ #define ZBX_DO_EXIT() (application_is_runned = ZBX_APP_STOPPED) +#define START_MAIN_ZABBIX_ENTRY(a) service_start() + #endif /* ZABBIX_SERVICE_H */ diff --git a/include/symbols.h b/include/symbols.h new file mode 100755 index 00000000..8fb83c2e --- /dev/null +++ b/include/symbols.h @@ -0,0 +1,38 @@ +/* +** ZABBIX +** Copyright (C) 2000-2005 SIA Zabbix +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ + +#ifndef ZABBIX_SYMBOLS_H +#define ZABBIX_SYMBOLS_H + +#if defined (WIN32) + +DWORD (__stdcall *zbx_GetGuiResources)(HANDLE,DWORD); +BOOL (__stdcall *zbx_GetProcessIoCounters)(HANDLE,PIO_COUNTERS); +BOOL (__stdcall *zbx_GetPerformanceInfo)(PPERFORMANCE_INFORMATION,DWORD); +BOOL (__stdcall *zbx_GlobalMemoryStatusEx)(LPMEMORYSTATUSEX); + +void import_symbols(void); + +#else /* not WIN32 */ + +# define import_symbols() + +#endif /* WIN32 */ + +#endif /* ZABBIX_SYMBOLS_H */ diff --git a/src/libs/zbxlog/log.c b/src/libs/zbxlog/log.c index 1cbf1de3..730677ac 100644 --- a/src/libs/zbxlog/log.c +++ b/src/libs/zbxlog/log.c @@ -106,7 +106,7 @@ zbx_error("Loging to file '%s'",filename); zbx_error("Loging to STDERR",filename); /* Not supported logging type */ - if(ZBX_MUTEX_ERROR == zbx_mutex_create(&log_file_access, "/tmp/zbxlmtx")) + if(ZBX_MUTEX_ERROR == zbx_mutex_create(&log_file_access, "log")) { zbx_error("Unable to create mutex for log file"); return FAIL; diff --git a/src/libs/zbxsys/mutexs.c b/src/libs/zbxsys/mutexs.c index 56a3e676..67d37db6 100755 --- a/src/libs/zbxsys/mutexs.c +++ b/src/libs/zbxsys/mutexs.c @@ -59,6 +59,7 @@ int zbx_mutex_create(ZBX_MUTEX *mutex, char *name) { #if defined(WIN32) + /* ignore "name" */ if(NULL == ((*mutex) = CreateMutex(NULL, FALSE, NULL))) { zbx_error("Error on mutex creating. [%s]", strerror_from_system(GetLastError())); @@ -71,6 +72,7 @@ int zbx_mutex_create(ZBX_MUTEX *mutex, char *name) int sem_id; union semun semopts; + /* !!! ignore "name" !!! */ if( -1 == (sem_key = ftok(CONFIG_FILE, (int)'z') )) { zbx_error("Can not create IPC key for path '%s', try to create for path '.' [%s]", CONFIG_FILE, strerror(errno)); diff --git a/src/libs/zbxsys/symbols.c b/src/libs/zbxsys/symbols.c new file mode 100755 index 00000000..f6b2c204 --- /dev/null +++ b/src/libs/zbxsys/symbols.c @@ -0,0 +1,73 @@ +/* +** ZABBIX +** Copyright (C) 2000-2005 SIA Zabbix +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ + +#include "common.h" +#include "symbols.h" + +#include "log.h" + +DWORD (__stdcall *zbx_GetGuiResources)(HANDLE,DWORD) = NULL; +BOOL (__stdcall *zbx_GetProcessIoCounters)(HANDLE,PIO_COUNTERS) = NULL; +BOOL (__stdcall *zbx_GetPerformanceInfo)(PPERFORMANCE_INFORMATION,DWORD) = NULL; +BOOL (__stdcall *zbx_GlobalMemoryStatusEx)(LPMEMORYSTATUSEX) = NULL; + + +static FARPROC GetProcAddressAndLog(HMODULE hModule,LPCSTR procName) +{ + FARPROC ptr; + + ptr=GetProcAddress(hModule,procName); + if ( NULL == ptr ) + zbx_error("Unable to resolve symbol '%s'", procName); + + return ptr; +} + +void import_symbols(void) +{ + HMODULE hModule; + + if(NULL != (hModule = GetModuleHandle("USER32.DLL")) ) + { + zbx_GetGuiResources = (DWORD (__stdcall *)(HANDLE,DWORD))GetProcAddressAndLog(hModule,"GetGuiResources"); + } + else + { + zbx_error("Unable to get handle to USER32.DLL"); + } + + if(NULL != (hModule=GetModuleHandle("KERNEL32.DLL")) ) + { + zbx_GetProcessIoCounters = (BOOL (__stdcall *)(HANDLE,PIO_COUNTERS))GetProcAddressAndLog(hModule,"GetProcessIoCounters"); + zbx_GlobalMemoryStatusEx = (BOOL (__stdcall *)(LPMEMORYSTATUSEX))GetProcAddressAndLog(hModule,"GlobalMemoryStatusEx"); + } + else + { + zbx_error("Unable to get handle to KERNEL32.DLL"); + } + + if(NULL != (hModule=GetModuleHandle("PSAPI.DLL")) ) + { + zbx_GetPerformanceInfo = (BOOL (__stdcall *)(PPERFORMANCE_INFORMATION,DWORD))GetProcAddressAndLog(hModule,"GetPerformanceInfo"); + } + else + { + zbx_error("Unable to get handle to PSAPI.DLL"); + } +} diff --git a/src/libs/zbxsysinfo/common/common.c b/src/libs/zbxsysinfo/common/common.c index c106b315..29f4c7ce 100644 --- a/src/libs/zbxsysinfo/common/common.c +++ b/src/libs/zbxsysinfo/common/common.c @@ -2086,18 +2086,10 @@ int CHECK_DNS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT * # define C_IN ns_c_in #endif /* C_IN */ -#if !defined(ns_c_in) -# define ns_c_in 1 -#endif /* ns_c_in */ - #if !defined(T_SOA) # define T_SOA ns_t_soa #endif /* T_SOA */ -#if !defined(ns_t_soa) -# define ns_t_soa 6 -#endif /* ns_t_soa */ - int res; char ip[MAX_STRING_LEN]; diff --git a/src/libs/zbxsysinfo/win32/memory.c b/src/libs/zbxsysinfo/win32/memory.c index f8ab5a3a..40872581 100755 --- a/src/libs/zbxsysinfo/win32/memory.c +++ b/src/libs/zbxsysinfo/win32/memory.c @@ -22,18 +22,14 @@ #include "common.h" #include "sysinfo.h" +#include "symbols.h" + int VM_MEMORY_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { - -#if defined(HAVE_GETPERFORMANCEINFO) PERFORMANCE_INFORMATION pfi; -#endif /* HAVE_GETPERFORMANCEINFO */ + MEMORYSTATUSEX ms_ex; + MEMORYSTATUS ms; -#if defined(HAVE_GLOBALMEMORYSTATUSEX) - MEMORYSTATUSEX ms; -#else /* HAVE_GLOBALMEMORYSTATUSEX */ - MEMORYSTATUS ms; -#endif char mode[10]; if(num_param(param) > 1) @@ -51,57 +47,55 @@ int VM_MEMORY_SIZE(const char *cmd, const char *param, unsigned flags, AGENT zbx_snprintf(mode, sizeof(mode), "total"); } -#if defined(HAVE_GETPERFORMANCEINFO) - if (strcmp(mode,"cached") == 0) { + if(NULL == zbx_GetPerformanceInfo) + return SYSINFO_RET_FAIL; - GetPerformanceInfo(&pfi,sizeof(PERFORMANCE_INFORMATION)); + zbx_GetPerformanceInfo(&pfi,sizeof(PERFORMANCE_INFORMATION)); SET_UI64_RESULT(result, (zbx_uint64_t)pfi.SystemCache * (zbx_uint64_t)pfi.PageSize); return SYSINFO_RET_OK; } -#endif /* HAVE_GETPERFORMANCEINFO */ - -#if defined(HAVE_GLOBALMEMORYSTATUSEX) - - ms.dwLength = sizeof(MEMORYSTATUSEX); - - GlobalMemoryStatusEx(&ms); - - if (strcmp(mode, "total") == 0) + if(NULL != zbx_GlobalMemoryStatusEx) { - SET_UI64_RESULT(result, ms.ullTotalPhys); - return SYSINFO_RET_OK; - } - else if (strcmp(mode, "free") == 0) - { - SET_UI64_RESULT(result, ms.ullAvailPhys); - return SYSINFO_RET_OK; + ms_ex.dwLength = sizeof(MEMORYSTATUSEX); + + zbx_GlobalMemoryStatusEx(&ms_ex); + + if (strcmp(mode, "total") == 0) + { + SET_UI64_RESULT(result, ms_ex.ullTotalPhys); + return SYSINFO_RET_OK; + } + else if (strcmp(mode, "free") == 0) + { + SET_UI64_RESULT(result, ms_ex.ullAvailPhys); + return SYSINFO_RET_OK; + } + else + { + return SYSINFO_RET_FAIL; + } } else { - return SYSINFO_RET_FAIL; - } - -#else /* not HAVE_GLOBALMEMORYSTATUSEX */ - GlobalMemoryStatus(&ms); - - if (strcmp(mode,"total") == 0) - { - SET_UI64_RESULT(result, ms.dwTotalPhys); - return SYSINFO_RET_OK; + GlobalMemoryStatus(&ms); + + if (strcmp(mode,"total") == 0) + { + SET_UI64_RESULT(result, ms.dwTotalPhys); + return SYSINFO_RET_OK; + } + else if (strcmp(mode,"free") == 0) + { + SET_UI64_RESULT(result, ms.dwAvailPhys); + return SYSINFO_RET_OK; + } } - else if (strcmp(mode,"free") == 0) - { - SET_UI64_RESULT(result, ms.dwAvailPhys); - return SYSINFO_RET_OK; - } - -#endif /* HAVE_GLOBALMEMORYSTATUSEX */ return SYSINFO_RET_FAIL; diff --git a/src/libs/zbxsysinfo/win32/pdhmon.c b/src/libs/zbxsysinfo/win32/pdhmon.c new file mode 100755 index 00000000..b6f9038e --- /dev/null +++ b/src/libs/zbxsysinfo/win32/pdhmon.c @@ -0,0 +1,91 @@ +/* +** ZABBIX +** Copyright (C) 2000-2005 SIA Zabbix +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ + +#include "config.h" + +#include "common.h" +#include "sysinfo.h" + +#include "log.h" + + +int PERF_MONITOR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) +{ + HQUERY query; + HCOUNTER counter; + PDH_STATUS status; + + PDH_RAW_COUNTER rawData; + PDH_FMT_COUNTERVALUE counterValue; + + char counter_name[MAX_STRING_LEN]; + + int ret = SYSINFO_RET_FAIL; + + if(num_param(param) > 1) + { + return SYSINFO_RET_FAIL; + } + + if(get_param(param, 1, counter_name, sizeof(counter_name)) != 0) + { + counter_name[0] = '\0'; + } + if(counter_name[0] == '\0') + { + return SYSINFO_RET_FAIL; + } + + if (ERROR_SUCCESS == PdhOpenQuery(NULL,0,&query)) + { + if (ERROR_SUCCESS == (status = PdhAddCounter(query,counter_name,0,&counter))) + { + if (ERROR_SUCCESS == PdhCollectQueryData(query)) + { + if(ERROR_SUCCESS == PdhGetRawCounterValue(counter, NULL, &rawData)) + { + if( ERROR_SUCCESS == PdhCalculateCounterFromRawValue( + counter, + PDH_FMT_DOUBLE, + &rawData, + NULL, + &counterValue + ) ) + { + SET_DBL_RESULT(result, counterValue.doubleValue); + ret = SYSINFO_RET_OK; + } + else + { + zabbix_log(LOG_LEVEL_DEBUG, "Can't format counter value [%s] [%s]", counter_name, "Rate counter is used."); + } + } + else + { + zabbix_log(LOG_LEVEL_DEBUG, "Can't get counter value [%s] [%s]", counter_name, strerror_from_system(GetLastError())); + } + } + PdhRemoveCounter(&counter); + } + + PdhCloseQuery(query); + } + + return ret; +} diff --git a/src/libs/zbxsysinfo/win32/proc.c b/src/libs/zbxsysinfo/win32/proc.c index e529e10c..b071d98e 100755 --- a/src/libs/zbxsysinfo/win32/proc.c +++ b/src/libs/zbxsysinfo/win32/proc.c @@ -22,6 +22,8 @@ #include "common.h" #include "sysinfo.h" +#include "symbols.h" + #define MAX_PROCESSES 4096 #define MAX_MODULES 512 @@ -207,42 +209,59 @@ static double GetProcessAttribute(HANDLE hProcess,int attr,int type,int count,do case 3: /* ktime */ case 4: /* utime */ GetProcessTimes(hProcess,&ftCreate,&ftExit,&ftKernel,&ftUser); - value=ConvertProcessTime(attr==3 ? &ftKernel : &ftUser); + value = ConvertProcessTime(attr==3 ? &ftKernel : &ftUser); break; - case 5: /* gdiobj */ -#if defined(HAVE_GETGUIRESOURCES) + case 5: /* gdiobj */ case 6: /* userobj */ - value=(double)GetGuiResources(hProcess,attr==5 ? 0 : 1); + if(NULL == zbx_GetGuiResources) + return SYSINFO_RET_FAIL; + + value = (double)zbx_GetGuiResources(hProcess,attr==5 ? 0 : 1); break; -#endif /* HAVE_GETGUIRESOURCES */ -#if defined(HAVE_GETPROCESSIOCOUNTERS) case 7: /* io_read_b */ - GetProcessIoCounters(hProcess,&ioCounters); + if(NULL == zbx_GetProcessIoCounters) + return SYSINFO_RET_FAIL; + + zbx_GetProcessIoCounters(hProcess,&ioCounters); value=(double)((__int64)ioCounters.ReadTransferCount); break; case 8: /* io_read_op */ + if(NULL == zbx_GetProcessIoCounters) + return SYSINFO_RET_FAIL; + GetProcessIoCounters(hProcess,&ioCounters); value=(double)((__int64)ioCounters.ReadOperationCount); break; case 9: /* io_write_b */ + if(NULL == zbx_GetProcessIoCounters) + return SYSINFO_RET_FAIL; + GetProcessIoCounters(hProcess,&ioCounters); value=(double)((__int64)ioCounters.WriteTransferCount); break; case 10: /* io_write_op */ + if(NULL == zbx_GetProcessIoCounters) + return SYSINFO_RET_FAIL; + GetProcessIoCounters(hProcess,&ioCounters); value=(double)((__int64)ioCounters.WriteOperationCount); break; case 11: /* io_other_b */ + if(NULL == zbx_GetProcessIoCounters) + return SYSINFO_RET_FAIL; + GetProcessIoCounters(hProcess,&ioCounters); value=(double)((__int64)ioCounters.OtherTransferCount); break; case 12: /* io_other_op */ + if(NULL == zbx_GetProcessIoCounters) + return SYSINFO_RET_FAIL; + GetProcessIoCounters(hProcess,&ioCounters); value=(double)((__int64)ioCounters.OtherOperationCount); break; -#endif /* HAVE_GETPROCESSIOCOUNTERS */ default: /* Unknown attribute */ return SYSINFO_RET_FAIL; diff --git a/src/libs/zbxsysinfo/win32/services.c b/src/libs/zbxsysinfo/win32/services.c new file mode 100755 index 00000000..39288b63 --- /dev/null +++ b/src/libs/zbxsysinfo/win32/services.c @@ -0,0 +1,92 @@ +/* +** ZABBIX +** Copyright (C) 2000-2005 SIA Zabbix +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +**/ + +#include "config.h" + +#include "common.h" +#include "sysinfo.h" + +int SERVICE_STATE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) +{ + SC_HANDLE + mgr, + service; + + char service_name[MAX_STRING_LEN]; + + int ret = SYSINFO_RET_FAIL; + int i; + + if(num_param(param) > 1) + { + return SYSINFO_RET_FAIL; + } + + if(get_param(param, 1, service_name, sizeof(service_name)) != 0) + { + service_name[0] = '\0'; + } + if(service_name[0] == '\0') + { + return SYSINFO_RET_FAIL; + } + + if(NULL == (mgr = OpenSCManager(NULL,NULL,GENERIC_READ)) ) + { + SET_UI64_RESULT(result, 255); + return SYSINFO_RET_OK; + } + + if(NULL != (service = OpenService(mgr,service_name,SERVICE_QUERY_STATUS)) ) + { + SERVICE_STATUS status; + + if (QueryServiceStatus(service, &status)) + { + static DWORD states[7] = + { + SERVICE_RUNNING, + SERVICE_PAUSED, + SERVICE_START_PENDING, + SERVICE_PAUSE_PENDING, + SERVICE_CONTINUE_PENDING, + SERVICE_STOP_PENDING, + SERVICE_STOPPED + }; + + for(i=0; i < 7 && status.dwCurrentState != states[i]; i++); + + SET_UI64_RESULT(result, i); + } + else + { + SET_UI64_RESULT(result, 255); + } + + CloseServiceHandle(service); + } + else + { + SET_UI64_RESULT(result, 255); + } + + CloseServiceHandle(mgr); + + return SYSINFO_RET_OK; +} diff --git a/src/libs/zbxsysinfo/win32/swap.c b/src/libs/zbxsysinfo/win32/swap.c index b4f07409..5a72668d 100755 --- a/src/libs/zbxsysinfo/win32/swap.c +++ b/src/libs/zbxsysinfo/win32/swap.c @@ -21,17 +21,15 @@ #include "common.h" #include "sysinfo.h" +#include "symbols.h" #include "md5.h" int SYSTEM_SWAP_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { -#if defined(HAVE_GLOBALMEMORYSTATUSEX) - MEMORYSTATUSEX ms; -#else /* HAVE_GLOBALMEMORYSTATUSEX */ - MEMORYSTATUS ms; -#endif + MEMORYSTATUSEX ms_ex; + MEMORYSTATUS ms; char swapdev[10]; char mode[10]; @@ -65,43 +63,42 @@ int SYSTEM_SWAP_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_R zbx_snprintf(mode, sizeof(mode), "total"); } -#if defined(HAVE_GLOBALMEMORYSTATUSEX) - - ms.dwLength = sizeof(MEMORYSTATUSEX); - - GlobalMemoryStatusEx(&ms); - - if (strcmp(mode, "total") == 0) + if(NULL != zbx_GlobalMemoryStatusEx) { - SET_UI64_RESULT(result, ms.ullTotalPageFile); - return SYSINFO_RET_OK; - } - else if (strcmp(mode, "free") == 0) - { - SET_UI64_RESULT(result, ms.ullAvailPageFile); - return SYSINFO_RET_OK; + ms_ex.dwLength = sizeof(MEMORYSTATUSEX); + + zbx_GlobalMemoryStatusEx(&ms_ex); + + if (strcmp(mode, "total") == 0) + { + SET_UI64_RESULT(result, ms_ex.ullTotalPageFile); + return SYSINFO_RET_OK; + } + else if (strcmp(mode, "free") == 0) + { + SET_UI64_RESULT(result, ms_ex.ullAvailPageFile); + return SYSINFO_RET_OK; + } + else + { + return SYSINFO_RET_FAIL; + } } else { - return SYSINFO_RET_FAIL; - } - -#else /* not HAVE_GLOBALMEMORYSTATUSEX */ - - GlobalMemoryStatus(&ms); - - if (strcmp(mode,"total") == 0) - { - SET_UI64_RESULT(result, ms.dwTotalPageFile); - return SYSINFO_RET_OK; + GlobalMemoryStatus(&ms); + + if (strcmp(mode,"total") == 0) + { + SET_UI64_RESULT(result, ms.dwTotalPageFile); + return SYSINFO_RET_OK; + } + else if (strcmp(mode,"free") == 0) + { + SET_UI64_RESULT(result, ms.dwAvailPageFile); + return SYSINFO_RET_OK; + } } - else if (strcmp(mode,"free") == 0) - { - SET_UI64_RESULT(result, ms.dwAvailPageFile); - return SYSINFO_RET_OK; - } - -#endif /* HAVE_GLOBALMEMORYSTATUSEX */ return SYSINFO_RET_OK; } diff --git a/src/zabbix_agent/zabbix_agentd.c b/src/zabbix_agent/zabbix_agentd.c index 41241683..b56213da 100644 --- a/src/zabbix_agent/zabbix_agentd.c +++ b/src/zabbix_agent/zabbix_agentd.c @@ -35,6 +35,8 @@ #include "active.h" #include "listener.h" +#include "symbols.h" + #if defined(ZABBIX_SERVICE) # include "service.h" #elif defined(ZABBIX_DAEMON) /* ZABBIX_SERVICE */ @@ -63,7 +65,7 @@ char title_message[] = "ZABBIX Agent" char usage_message[] = "[-vhp]" #if defined(WIN32) - " [-iusx]" + " [-idsx]" #endif /* WIN32 */ " [-c <file>] [-t <metric>]"; @@ -118,7 +120,7 @@ static struct zbx_option longopts[] = #if defined (WIN32) {"install", 0, 0, 'i'}, - {"uninstall", 0, 0, 'u'}, + {"uninstall", 0, 0, 'd'}, {"start", 0, 0, 's'}, {"stop", 0, 0, 'x'}, @@ -133,7 +135,7 @@ static struct zbx_option longopts[] = static char shortopts[] = "c:hvpt:" #if defined (WIN32) - "iusx" + "idsx" #endif /* WIN32 */ ; @@ -181,7 +183,7 @@ static int parse_commandline(int argc, char **argv) case 'i': task = ZBX_TASK_INSTALL_SERVICE; break; - case 'u': + case 'd': task = ZBX_TASK_UNINSTALL_SERVICE; break; case 's': @@ -295,12 +297,9 @@ int MAIN_ZABBIX_ENTRY(void) threads[i] = zbx_thread_start(active_checks_thread, &activechk_args); } -#if !defined(WIN32) /* Must be called after all child processes loading. */ init_main_process(); -#endif - /* wait for all threads exiting */ for(i = 0; i < CONFIG_ZABBIX_FORKS; i++) { @@ -380,6 +379,8 @@ int main(int argc, char **argv) task = parse_commandline(argc, argv); + import_symbols(); + init_metrics(); /* Must be before load_config(). load_config - use metrics!!! */ load_config(task == 0); @@ -421,15 +422,7 @@ int main(int argc, char **argv) break; } -#if defined(WIN32) - - service_start(); - -#else /* not WIN32 */ - - daemon_start(CONFIG_ALLOW_ROOT_PERMISSION); - -#endif /* WIN32 */ + START_MAIN_ZABBIX_ENTRY(CONFIG_ALLOW_ROOT_PERMISSION); exit(SUCCEED); } |