summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--include/common.h5
-rw-r--r--src/libs/zbxsysinfo/common/common.c143
-rw-r--r--src/libs/zbxsysinfo/common/file.c14
-rw-r--r--src/libs/zbxsysinfo/common/system.c2
-rw-r--r--src/libs/zbxsysinfo/linux/cpu.c34
-rw-r--r--src/libs/zbxsysinfo/linux/diskio.c6
-rw-r--r--src/libs/zbxsysinfo/linux/diskspace.c323
-rw-r--r--src/libs/zbxsysinfo/linux/inodes.c200
-rw-r--r--src/libs/zbxsysinfo/linux/memory.c38
-rw-r--r--src/libs/zbxsysinfo/linux/net.c4
-rw-r--r--src/libs/zbxsysinfo/linux/proc.c4
-rw-r--r--src/libs/zbxsysinfo/linux/sensors.c8
-rw-r--r--src/libs/zbxsysinfo/linux/swap.c16
-rw-r--r--src/libs/zbxsysinfo/linux/uptime.c8
15 files changed, 328 insertions, 478 deletions
diff --git a/ChangeLog b/ChangeLog
index f5c50590..b84a1cca 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
Changes for 1.1beta3:
+ - optimized sysinfo functions for linux system (Eugene)
- grouped commands in to the new command with parameters for linux (Eugene)
- developed new interface for test functions. Result returns with srtuct (Eugene)
- recreated process() function. (Eugene)
diff --git a/include/common.h b/include/common.h
index 7a207be3..42340a67 100644
--- a/include/common.h
+++ b/include/common.h
@@ -216,7 +216,10 @@ AGENT_RESULT {
#define AR_MESSAGE 4
#define AR_LIST 8
-
+int copy_list(LIST *src, LIST *dist);
+void free_list(LIST *list);
+void clean_result(AGENT_RESULT *result);
+int copy_result(AGENT_RESULT *src, AGENT_RESULT *dist);
void free_result(AGENT_RESULT *result);
char *string_replace(char *str, const char *sub_str1, const char *sub_str2);
diff --git a/src/libs/zbxsysinfo/common/common.c b/src/libs/zbxsysinfo/common/common.c
index 8c4b2087..2d885349 100644
--- a/src/libs/zbxsysinfo/common/common.c
+++ b/src/libs/zbxsysinfo/common/common.c
@@ -89,13 +89,17 @@ void add_user_parameter(char *key,char *command)
if(parse_command(key, usr_cmd, MAX_STRING_LEN, usr_param, MAX_STRING_LEN))
{
- zabbix_log( LOG_LEVEL_WARNING, "Can't add user specifed key [%s]. Incorrect key!", key);
+ zabbix_log( LOG_LEVEL_WARNING, "Can't add user specifed key \"%s\". Incorrect key!", key);
return;
}
if(strncmp(usr_param, "*", MAX_STRING_LEN) == 0)
+ {
flag |= CF_USEUPARAM;
- else if(usr_param[0] != 0)
- zabbix_log( LOG_LEVEL_WARNING, "Can't add user specifed key [%s]. Incorrect key!", key);
+ }
+ else if(usr_param[0] != 0){
+ zabbix_log( LOG_LEVEL_WARNING, "Can't add user specifed key \"%s\". Incorrect key!", key);
+ return;
+ }
for(i=0;;i++)
{
@@ -117,7 +121,8 @@ void add_user_parameter(char *key,char *command)
/* Replace existing parameters */
if(strcmp(commands[i].key, key) == 0)
{
- free(commands[i].key);
+ if(commands[i].key)
+ free(commands[i].key);
if(commands[i].main_param)
free(commands[i].main_param);
if(commands[i].test_param)
@@ -182,6 +187,40 @@ void escape_string(char *from, char *to, int maxlen)
to[maxlen-1]=0;
}
+void free_list(LIST *list)
+{
+ /* nothin to do */
+}
+
+int copy_list(LIST *src, LIST *dist)
+{
+ /* nothin to do */
+ return 0;
+}
+
+int copy_result(AGENT_RESULT *src, AGENT_RESULT *dist)
+{
+ assert(src);
+ assert(dist);
+
+ free_result(dist);
+ dist->type = src->type;
+ dist->dbl = src->dbl;
+ if(src->str)
+ {
+ dist->str = strdup(src->str);
+ if(!dist->str)
+ return 1;
+ }
+ if(src->msg)
+ {
+ dist->msg = strdup(src->msg);
+ if(!dist->msg)
+ return 1;
+ }
+ return copy_list(&(src->list), &(dist->list));
+}
+
void free_result(AGENT_RESULT *result)
{
@@ -195,13 +234,14 @@ void free_result(AGENT_RESULT *result)
free(result->msg);
result->msg = NULL;
}
- if(result->type & AR_LIST)
- {
- /*
- * write code to free memory
- * for result->list
- */
- }
+ free_list(&(result->list));
+}
+
+void clean_result(AGENT_RESULT *result)
+{
+ free_result(result);
+ result->type = 0;
+ result->dbl = 0;
}
int parse_command(
@@ -253,7 +293,6 @@ void test_parameters(void)
for(i=0; 0 != commands[i].key; i++)
{
process(commands[i].key, PF_TEST, &result);
-
if(result.type & AR_DOUBLE)
{
printf(" [d|%lf]", result.dbl);
@@ -291,8 +330,7 @@ int process(const char *in_command, unsigned flags, AGENT_RESULT *result)
assert(result);
-
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
strncpy(usr_command, in_command, MAX_STRING_LEN);
usr_command_len = strlen(usr_command);
@@ -336,7 +374,6 @@ int process(const char *in_command, unsigned flags, AGENT_RESULT *result)
((flags & PF_TEST) && commands[i].test_param) ? commands[i].test_param : usr_param
);
}
-
err = function(usr_command, param, flags, result);
if(err == SYSINFO_RET_FAIL)
@@ -351,14 +388,18 @@ int process(const char *in_command, unsigned flags, AGENT_RESULT *result)
if(flags & PF_TEST)
{
+ printf("%s", usr_cmd);
if(commands[i].flags & CF_USEUPARAM)
{
- strncat(usr_command, "[", MAX_STRING_LEN);
- strncat(usr_command, param, MAX_STRING_LEN);
- strncat(usr_command, "]", MAX_STRING_LEN);
- }
+ printf("[%s]", param);
+ i = strlen(param)+2;
+ } else i = 0;
+ i += strlen(usr_cmd);
- printf("%-35s", usr_command);
+#define COLUMN_2_X 45
+ i = i > COLUMN_2_X ? 1 : (COLUMN_2_X - i);
+
+ printf("%-*.*s", i, i, " ");
}
if(err == NOTSUPPORTED)
@@ -401,7 +442,7 @@ int VFS_FILE_MD5SUM(const char *cmd, const char *param, unsigned flags, AGENT_RE
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 1)
{
@@ -530,7 +571,7 @@ int VFS_FILE_CKSUM(const char *cmd, const char *param, unsigned flags, AGENT_RES
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 1)
{
@@ -609,7 +650,7 @@ int get_stat(const char *key, unsigned flags, AGENT_RESULT *result)
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
f=fopen("/tmp/zabbix_agentd.tmp","r");
if(f==NULL)
@@ -698,7 +739,7 @@ int TCP_LISTEN(const char *cmd, const char *param, unsigned flags, AGENT_RESULT
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 1)
{
@@ -750,7 +791,7 @@ int getPROC(char *file, int lineno, int fieldno, unsigned flags, AGENT_RESULT *r
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
f=fopen(file,"r");
if(NULL == f)
@@ -786,7 +827,7 @@ int KERNEL_MAXFILES(const char *cmd, const char *param, unsigned flags, AGENT_RE
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
len=sizeof(maxfiles);
@@ -814,7 +855,7 @@ int KERNEL_MAXPROC(const char *cmd, const char *param, unsigned flags, AGENT_RES
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
len=sizeof(maxproc);
@@ -839,7 +880,7 @@ int OLD_KERNEL(const char *cmd, const char *param, unsigned flags, AGENT_RES
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 1)
{
@@ -871,7 +912,7 @@ int AGENT_PING(const char *cmd, const char *param, unsigned flags, AGENT_RESULT
{
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
result->type |= AR_DOUBLE;
result->dbl = 1;
@@ -885,7 +926,7 @@ int PROCCOUNT(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if( 0 == sysinfo(&info))
{
@@ -911,7 +952,7 @@ int PROCCOUNT(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *
int proccount=0;
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
dir=opendir("/proc");
if(NULL == dir)
@@ -967,7 +1008,7 @@ int PROCCOUNT(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
dir=opendir("/proc");
if(NULL == dir)
@@ -1015,7 +1056,7 @@ int AGENT_VERSION(const char *cmd, const char *param, unsigned flags, AGENT_RESU
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
result->type |= AR_STRING;
result->str = strdup(version);
@@ -1030,7 +1071,7 @@ int OLD_VERSION(const char *cmd, const char *param, unsigned flags, AGENT_RE
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 1)
{
@@ -1059,10 +1100,11 @@ int EXECUTE_STR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT
FILE *f;
char c[MAX_STRING_LEN];
char command[MAX_STRING_LEN];
+ int i;
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
strncpy(command, param, MAX_STRING_LEN);
@@ -1110,7 +1152,16 @@ int EXECUTE_STR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT
{
return SYSINFO_RET_FAIL;
}
-
+
+ for(i=strlen(c); i>0; i--)
+ {
+ if(c[i] == '\n')
+ {
+ c[i] = '\0';
+ break;
+ }
+ }
+
result->type |= AR_STRING;
result->str = strdup(c);
@@ -1124,7 +1175,7 @@ int EXECUTE(const char *cmd, const char *command, unsigned flags, AGENT_RESULT *
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
f=popen( command,"r");
if(f==0)
@@ -1187,7 +1238,7 @@ int forward_request(char *proxy, char *command, int port, unsigned flags, AGENT_
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
host = gethostbyname(proxy);
if(host == NULL)
@@ -1487,7 +1538,7 @@ int CHECK_SERVICE_PERF(const char *cmd, const char *service_and_ip_and_port, uns
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
gettimeofday(&t1,&tz1);
@@ -1612,7 +1663,7 @@ int CHECK_SERVICE(const char *cmd, const char *service_and_ip_and_port, unsigned
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
/* Default IP address */
strscpy(ip,"127.0.0.1");
@@ -1768,7 +1819,7 @@ int CHECK_PORT(const char *cmd, const char *ip_and_port, unsigned flags, AGENT_R
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
c=strchr(ip_and_port,',');
strscpy(ip,ip_and_port);
@@ -1806,7 +1857,7 @@ int CHECK_DNS(const char *cmd, const char *ip_and_zone, unsigned flags, AGENT_RE
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
memset(&ip, 0, MAX_STRING_LEN);
memset(&zone, 0, MAX_STRING_LEN);
@@ -1883,7 +1934,7 @@ int SYSTEM_UNUM(const char *cmd, const char *param, unsigned flags, AGENT_RE
{
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
return EXECUTE(cmd, "who|wc -l", flags, result);
}
@@ -1892,7 +1943,7 @@ int SYSTEM_UNAME(const char *cmd, const char *param, unsigned flags, AGENT_R
{
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
return EXECUTE_STR(cmd, "uname -a", flags, result);
}
@@ -1901,7 +1952,7 @@ int SYSTEM_HOSTNAME(const char *cmd, const char *param, unsigned flags, AGEN
{
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
return EXECUTE_STR(cmd, "hostname", flags, result);
}
@@ -1913,7 +1964,7 @@ int OLD_SYSTEM(const char *cmd, const char *param, unsigned flags, AGENT_RES
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 1)
{
diff --git a/src/libs/zbxsysinfo/common/file.c b/src/libs/zbxsysinfo/common/file.c
index f75d0635..0481894a 100644
--- a/src/libs/zbxsysinfo/common/file.c
+++ b/src/libs/zbxsysinfo/common/file.c
@@ -30,7 +30,7 @@ int VFS_FILE_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESU
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 1)
{
@@ -58,7 +58,7 @@ int VFS_FILE_ATIME(const char *cmd, const char *param, unsigned flags, AGENT_RES
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 1)
{
@@ -86,7 +86,7 @@ int VFS_FILE_CTIME(const char *cmd, const char *param, unsigned flags, AGENT_RES
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 1)
{
@@ -114,7 +114,7 @@ int VFS_FILE_MTIME(const char *cmd, const char *param, unsigned flags, AGENT_RES
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 1)
{
@@ -142,7 +142,7 @@ int VFS_FILE_EXISTS(const char *cmd, const char *param, unsigned flags, AGENT_RE
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 1)
{
@@ -182,7 +182,7 @@ int VFS_FILE_REGEXP(const char *cmd, const char *param, unsigned flags, AGENT_RE
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
memset(tmp,0,MAX_STRING_LEN);
if(get_param(param, 1, filename, MAX_STRING_LEN) != 0)
@@ -265,7 +265,7 @@ int VFS_FILE_REGMATCH(const char *cmd, const char *param, unsigned flags, AGENT_
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(get_param(param, 1, filename, MAX_STRING_LEN) != 0)
{
diff --git a/src/libs/zbxsysinfo/common/system.c b/src/libs/zbxsysinfo/common/system.c
index 552fbee6..448cebe8 100644
--- a/src/libs/zbxsysinfo/common/system.c
+++ b/src/libs/zbxsysinfo/common/system.c
@@ -28,7 +28,7 @@ int SYSTEM_LOCALTIME(const char *cmd, const char *param, unsigned flags, AGENT_R
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
result->type |= AR_DOUBLE;
result->dbl = (double)time(NULL);
diff --git a/src/libs/zbxsysinfo/linux/cpu.c b/src/libs/zbxsysinfo/linux/cpu.c
index ca161e58..529737f6 100644
--- a/src/libs/zbxsysinfo/linux/cpu.c
+++ b/src/libs/zbxsysinfo/linux/cpu.c
@@ -46,7 +46,7 @@ CPU_FNCLIST
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 2)
{
@@ -122,7 +122,7 @@ CPU_FNCLIST
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 3)
{
@@ -283,7 +283,7 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *param, unsigned flags, AGENT_R
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(getloadavg(load, 3))
{
@@ -301,7 +301,7 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *param, unsigned flags, AGENT_R
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
@@ -324,7 +324,7 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *param, unsigned flags, AGENT_R
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if (!kc && !(kc = kstat_open()))
{
@@ -345,7 +345,7 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *param, unsigned flags, AGENT_R
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(getloadavg_kmem(loadavg,3) == FAIL)
{
@@ -358,7 +358,7 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *param, unsigned flags, AGENT_R
#else
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -374,7 +374,7 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *param, unsigned flags, AGENT_R
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(getloadavg(load, 3))
{
@@ -392,7 +392,7 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *param, unsigned flags, AGENT_R
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
@@ -415,7 +415,7 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *param, unsigned flags, AGENT_R
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if (!kc && !(kc = kstat_open()))
{
@@ -436,7 +436,7 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *param, unsigned flags, AGENT_R
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(getloadavg_kmem(loadavg,3) == FAIL)
{
@@ -449,7 +449,7 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *param, unsigned flags, AGENT_R
#else
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -465,7 +465,7 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *param, unsigned flags, AGENT_
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(getloadavg(load, 3))
{
@@ -483,7 +483,7 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *param, unsigned flags, AGENT_
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1)
{
@@ -506,7 +506,7 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *param, unsigned flags, AGENT_
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if (!kc && !(kc = kstat_open()))
{
@@ -527,7 +527,7 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *param, unsigned flags, AGENT_
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(getloadavg_kmem(loadavg,3) == FAIL)
{
@@ -540,7 +540,7 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *param, unsigned flags, AGENT_
#else
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
diff --git a/src/libs/zbxsysinfo/linux/diskio.c b/src/libs/zbxsysinfo/linux/diskio.c
index 328dceb3..a761187e 100644
--- a/src/libs/zbxsysinfo/linux/diskio.c
+++ b/src/libs/zbxsysinfo/linux/diskio.c
@@ -51,7 +51,7 @@ DEV_FNCLIST
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 3)
{
@@ -127,7 +127,7 @@ DEV_FNCLIST
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 3)
{
@@ -334,7 +334,7 @@ int OLD_IO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *res
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 1)
{
diff --git a/src/libs/zbxsysinfo/linux/diskspace.c b/src/libs/zbxsysinfo/linux/diskspace.c
index 9db5895a..3fde0069 100644
--- a/src/libs/zbxsysinfo/linux/diskspace.c
+++ b/src/libs/zbxsysinfo/linux/diskspace.c
@@ -48,7 +48,7 @@ FS_FNCLIST
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 2)
{
@@ -81,316 +81,165 @@ FS_FNCLIST
return SYSINFO_RET_FAIL;
}
-int VFS_FS_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+int get_fs_size_stat(char *fs, double *total, double *free, double *usage)
{
#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
- char mountPoint[MAX_STRING_LEN];
-
- assert(result);
-
- memset(result, 0, sizeof(AGENT_RESULT));
-
- if(num_param(param) > 1)
- {
- return SYSINFO_RET_FAIL;
- }
-
- if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- result->type |= AR_DOUBLE;
- result->dbl = (double)(s.f_bavail * (s.f_frsize / 1024.0));
- return SYSINFO_RET_OK;
+ struct statvfs s;
#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
- char mountPoint[MAX_STRING_LEN];
-
- assert(result);
+ struct statfs s;
+#endif
- memset(result, 0, sizeof(AGENT_RESULT));
+ assert(fs);
- if(num_param(param) > 1)
+#ifdef HAVE_SYS_STATVFS_H
+ if ( statvfs( fs, &s) != 0 )
+#else
+ if ( statfs( fs, &s) != 0 )
+#endif
{
- return SYSINFO_RET_FAIL;
+ return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- result->type |= AR_DOUBLE;
- result->dbl = (double)(s.f_bavail * (s.f_bsize / 1024.0));
- return SYSINFO_RET_OK;
-
- }
-
- return SYSINFO_RET_FAIL;
+#ifdef HAVE_SYS_STATVFS_H
+ if(total)
+ (*total) = (double)(s.f_blocks * (s.f_frsize / 1024.0));
+ if(free)
+ (*free) = (double)(s.f_bavail * (s.f_frsize / 1024.0));
+ if(usage)
+ (*usage) = (double)((s.f_blocks - s.f_bavail) * (s.f_frsize / 1024.0));
+#else
+ if(total)
+ (*total) = (double)(s.f_blocks * (s.f_bsize / 1024.0));
+ if(free)
+ (*free) = (double)(s.f_bfree * (s.f_bsize / 1024.0));
+ if(usage)
+ (*usage) = (double)((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0));
#endif
+ return SYSINFO_RET_OK;
}
int VFS_FS_USED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
- char mountPoint[MAX_STRING_LEN];
-
- assert(result);
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
- memset(result, 0, sizeof(AGENT_RESULT));
+ assert(result);
+
+ clean_result(result);
if(num_param(param) > 1)
- {
return SYSINFO_RET_FAIL;
- }
if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
- {
return SYSINFO_RET_FAIL;
- }
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
+ if(get_fs_size_stat(mountPoint, NULL, NULL, &value) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
- result->type |= AR_DOUBLE;
- result->dbl = (double)((s.f_blocks-s.f_bavail) * (s.f_frsize / 1024.0));
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
- char mountPoint[MAX_STRING_LEN];
-
- assert(result);
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
+}
+
+int VFS_FS_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
- memset(result, 0, sizeof(AGENT_RESULT));
+ assert(result);
+
+ clean_result(result);
if(num_param(param) > 1)
- {
return SYSINFO_RET_FAIL;
- }
if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
- {
return SYSINFO_RET_FAIL;
- }
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- result->type |= AR_DOUBLE;
- result->dbl = (double)(blocks_used * (s.f_bsize / 1024.0));
- return SYSINFO_RET_OK;
+ if(get_fs_size_stat(mountPoint, NULL, &value, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
- }
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
- return SYSINFO_RET_FAIL;
-#endif
+ return SYSINFO_RET_OK;
}
int VFS_FS_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
- char mountPoint[MAX_STRING_LEN];
-
- assert(result);
+ char mountPoint[MAX_STRING_LEN];
+ double value = 0;
- memset(result, 0, sizeof(AGENT_RESULT));
+ assert(result);
+
+ clean_result(result);
if(num_param(param) > 1)
- {
return SYSINFO_RET_FAIL;
- }
if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
- }
-
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
-/* return s.f_blocks * (s.f_bsize / 1024.0);*/
- result->type |= AR_DOUBLE;
- result->dbl = (double)(s.f_blocks * (s.f_frsize / 1024.0));
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
- char mountPoint[MAX_STRING_LEN];
-
- assert(result);
-
- memset(result, 0, sizeof(AGENT_RESULT));
-
- if(num_param(param) > 1)
- {
- return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
- {
- return SYSINFO_RET_FAIL;
- }
+ if(get_fs_size_stat(mountPoint, &value, NULL, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- result->type |= AR_DOUBLE;
- result->dbl = (double)(s.f_blocks * (s.f_bsize / 1024.0));
- return SYSINFO_RET_OK;
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
- }
+ return SYSINFO_RET_OK;
- return SYSINFO_RET_FAIL;
-#endif
}
-int VFS_FS_PUSED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+int VFS_FS_PFREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- AGENT_RESULT total_result;
- AGENT_RESULT used_result;
- char mountPoint[MAX_STRING_LEN];
-
- assert(result);
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double free_val = 0;
+
+ assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 1)
- {
return SYSINFO_RET_FAIL;
- }
if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
- {
return SYSINFO_RET_FAIL;
- }
-
- if(SYSINFO_RET_OK != VFS_FS_TOTAL(cmd, mountPoint, flags, &total_result))
- {
- memcpy(result, &total_result, sizeof(AGENT_RESULT));
- return SYSINFO_RET_FAIL;
- }
- if(SYSINFO_RET_OK != VFS_FS_USED(cmd, mountPoint, flags, &used_result))
- {
- memcpy(result, &used_result, sizeof(AGENT_RESULT));
- return SYSINFO_RET_FAIL;
- }
+ if(get_fs_size_stat(mountPoint, &tot_val, &free_val, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
- if(total_result.dbl == 0)
- {
- return SYSINFO_RET_FAIL;
- }
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * free_val) / tot_val;
- result->type |= AR_DOUBLE;
- result->dbl = (double)(100.0 * used_result.dbl / total_result.dbl);
- return SYSINFO_RET_OK;
+ return SYSINFO_RET_OK;
}
-int VFS_FS_PFREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+int VFS_FS_PUSED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- AGENT_RESULT total_result;
- AGENT_RESULT free_result;
- char mountPoint[MAX_STRING_LEN];
-
- assert(result);
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double usg_val = 0;
+
+ assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 1)
- {
return SYSINFO_RET_FAIL;
- }
if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
- {
return SYSINFO_RET_FAIL;
- }
- if(SYSINFO_RET_OK != VFS_FS_TOTAL(cmd, mountPoint, flags, &total_result))
- {
- memcpy(result, &total_result, sizeof(AGENT_RESULT));
- return SYSINFO_RET_FAIL;
- }
+ if(get_fs_size_stat(mountPoint, &tot_val, NULL, &usg_val) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
- if(SYSINFO_RET_OK != VFS_FS_FREE(cmd, mountPoint, flags, &free_result))
- {
- memcpy(result, &free_result, sizeof(AGENT_RESULT));
- return SYSINFO_RET_FAIL;
- }
-
- if(total_result.dbl == 0)
- {
- return SYSINFO_RET_FAIL;
- }
+ result->type |= AR_DOUBLE;
+ result->dbl = (100.0 * usg_val) / tot_val;
- result->type |= AR_DOUBLE;
- result->dbl = (double)(100.0 * free_result.dbl / total_result.dbl);
- return SYSINFO_RET_OK;
+ return SYSINFO_RET_OK;
}
diff --git a/src/libs/zbxsysinfo/linux/inodes.c b/src/libs/zbxsysinfo/linux/inodes.c
index 2def25a0..d6b124eb 100644
--- a/src/libs/zbxsysinfo/linux/inodes.c
+++ b/src/libs/zbxsysinfo/linux/inodes.c
@@ -50,7 +50,7 @@ FS_FNCLIST
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 2)
{
@@ -83,216 +83,162 @@ FS_FNCLIST
return SYSINFO_RET_FAIL;
}
-int VFS_FS_INODE_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+int get_fs_inodes_stat(char *fs, double *total, double *free, double *usage)
{
- char mountPoint[MAX_STRING_LEN];
#ifdef HAVE_SYS_STATVFS_H
struct statvfs s;
#else
struct statfs s;
#endif
- assert(result);
-
- memset(result, 0, sizeof(AGENT_RESULT));
-
- if(num_param(param) > 1)
- {
- return SYSINFO_RET_FAIL;
- }
-
- if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
- {
- return SYSINFO_RET_FAIL;
- }
-
+ assert(fs);
+
#ifdef HAVE_SYS_STATVFS_H
- if ( statvfs( (char *)mountPoint, &s) != 0 )
+ if ( statvfs( fs, &s) != 0 )
#else
- if ( statfs( (char *)mountPoint, &s) != 0 )
+ if ( statfs( fs, &s) != 0 )
#endif
{
return SYSINFO_RET_FAIL;
}
- if ( s.f_blocks > 0 ) {
- result->type |= AR_DOUBLE;
+ if(total)
+ (*total) = (double)(s.f_files);
#ifdef HAVE_SYS_STATVFS_H
- result->dbl = (double)(s.f_favail);
+ if(free)
+ (*free) = (double)(s.f_favail);
+ if(usage)
+ (*usage) = (double)(s.f_files - s.f_favail);
#else
- result->dbl = (double)(s.f_ffree);
+ if(free)
+ (*free) = (double)(s.ffree);
+ if(usage)
+ (*usage) = (double)(s.f_files - s.f_ffree);
#endif
- return SYSINFO_RET_OK;
- }
- return SYSINFO_RET_FAIL;
+ return SYSINFO_RET_OK;
}
int VFS_FS_INODE_USED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char mountPoint[MAX_STRING_LEN];
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
-#else
- struct statfs s;
-#endif
+ double value = 0;
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 1)
- {
return SYSINFO_RET_FAIL;
- }
if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
- {
return SYSINFO_RET_FAIL;
- }
-#ifdef HAVE_SYS_STATVFS_H
- if ( statvfs( (char *)mountPoint, &s) != 0 )
-#else
- if ( statfs( (char *)mountPoint, &s) != 0 )
-#endif
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- result->type |= AR_DOUBLE;
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
- result->dbl = (double)(s.f_files - s.f_favail);
-#else
- result->dbl = (double)(s.f_files - s.f_ffree);
-#endif
- return SYSINFO_RET_OK;
- }
- return SYSINFO_RET_FAIL;
+ if(get_fs_inodes_stat(mountPoint, NULL, NULL, &value) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_INODE_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+int VFS_FS_INODE_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
char mountPoint[MAX_STRING_LEN];
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
-#else
- struct statfs s;
-#endif
+ double value = 0;
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 1)
- {
return SYSINFO_RET_FAIL;
- }
if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
- {
return SYSINFO_RET_FAIL;
- }
-#ifdef HAVE_SYS_STATVFS_H
- if ( statvfs( (char *)mountPoint, &s) != 0 )
-#else
- if ( statfs( (char *)mountPoint, &s) != 0 )
-#endif
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- result->type |= AR_DOUBLE;
- result->dbl = (double)(s.f_files);
- return SYSINFO_RET_OK;
- }
- return SYSINFO_RET_FAIL;
+ if(get_fs_inodes_stat(mountPoint, NULL, &value, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
}
-int VFS_FS_INODE_PFREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+int VFS_FS_INODE_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- AGENT_RESULT total_result;
- AGENT_RESULT free_result;
char mountPoint[MAX_STRING_LEN];
+ double value = 0;
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 1)
- {
return SYSINFO_RET_FAIL;
- }
if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
{
return SYSINFO_RET_FAIL;
}
- if(SYSINFO_RET_OK != VFS_FS_INODE_TOTAL(cmd, mountPoint, flags, &total_result))
- {
- memcpy(result, &total_result, sizeof(AGENT_RESULT));
- return SYSINFO_RET_FAIL;
- }
+ if(get_fs_inodes_stat(mountPoint, &value, NULL, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
+
+ result->type |= AR_DOUBLE;
+ result->dbl = value;
+
+ return SYSINFO_RET_OK;
+}
- if(SYSINFO_RET_OK != VFS_FS_INODE_FREE(cmd, mountPoint, flags, &free_result))
- {
- memcpy(result, &free_result, sizeof(AGENT_RESULT));
- return SYSINFO_RET_FAIL;
- }
+int VFS_FS_INODE_PFREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double free_val = 0;
+
+ assert(result);
- if(total_result.dbl == 0)
- {
- return SYSINFO_RET_FAIL;
- }
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
+
+ if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
+ return SYSINFO_RET_FAIL;
+
+ if(get_fs_inodes_stat(mountPoint, &tot_val, &free_val, NULL) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
result->type |= AR_DOUBLE;
- result->dbl = 100.0 * free_result.dbl / total_result.dbl;
+ result->dbl = (100.0 * free_val) / tot_val;
+
return SYSINFO_RET_OK;
}
int VFS_FS_INODE_PUSED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- AGENT_RESULT total_result;
- AGENT_RESULT used_result;
char mountPoint[MAX_STRING_LEN];
+ double tot_val = 0;
+ double usg_val = 0;
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 1)
- {
return SYSINFO_RET_FAIL;
- }
if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0)
- {
return SYSINFO_RET_FAIL;
- }
-
- if(SYSINFO_RET_OK != VFS_FS_INODE_TOTAL(cmd, mountPoint, flags, &total_result))
- {
- memcpy(result, &total_result, sizeof(AGENT_RESULT));
- return SYSINFO_RET_FAIL;
- }
-
- if(SYSINFO_RET_OK != VFS_FS_INODE_USED(cmd, mountPoint, flags, &used_result))
- {
- memcpy(result, &used_result, sizeof(AGENT_RESULT));
- return SYSINFO_RET_FAIL;
- }
- if(total_result.dbl == 0)
- {
- return SYSINFO_RET_FAIL;
- }
+ if(get_fs_inodes_stat(mountPoint, &tot_val, NULL, &usg_val) != SYSINFO_RET_OK)
+ return SYSINFO_RET_FAIL;
result->type |= AR_DOUBLE;
- result->dbl = 100.0 * used_result.dbl / total_result.dbl;
+ result->dbl = (100.0 * usg_val) / tot_val;
+
return SYSINFO_RET_OK;
}
diff --git a/src/libs/zbxsysinfo/linux/memory.c b/src/libs/zbxsysinfo/linux/memory.c
index 92db6809..6bf06827 100644
--- a/src/libs/zbxsysinfo/linux/memory.c
+++ b/src/libs/zbxsysinfo/linux/memory.c
@@ -46,7 +46,7 @@ MEM_FNCLIST
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 1)
{
@@ -89,7 +89,7 @@ int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags, AGENT_R
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
f=fopen("/proc/meminfo","r");
if(NULL == f)
@@ -114,7 +114,7 @@ int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags, AGENT_R
#else
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
@@ -127,7 +127,7 @@ int VM_MEMORY_BUFFERS(const char *cmd, const char *param, unsigned flags, AGENT_
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if( 0 == sysinfo(&info))
{
@@ -146,7 +146,7 @@ int VM_MEMORY_BUFFERS(const char *cmd, const char *param, unsigned flags, AGENT_
#else
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
@@ -159,7 +159,7 @@ int VM_MEMORY_SHARED(const char *cmd, const char *param, unsigned flags, AGENT_R
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if( 0 == sysinfo(&info))
{
@@ -182,7 +182,7 @@ int VM_MEMORY_SHARED(const char *cmd, const char *param, unsigned flags, AGENT_R
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
@@ -205,7 +205,7 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RE
#ifdef HAVE_UNISTD_SYSCONF
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
result->type |= AR_DOUBLE;
result->dbl=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE);
@@ -217,7 +217,7 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RE
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1)
{
@@ -238,7 +238,7 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RE
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if( 0 == sysinfo(&info))
{
@@ -261,7 +261,7 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RE
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
@@ -281,7 +281,7 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RE
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
len=sizeof(memory);
@@ -299,7 +299,7 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RE
#else
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
@@ -315,7 +315,7 @@ int VM_MEMORY_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RES
#ifdef HAVE_UNISTD_SYSCONF
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
result->type |= AR_DOUBLE;
result->dbl=(double)sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE);
@@ -328,7 +328,7 @@ int VM_MEMORY_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RES
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1)
{
@@ -369,7 +369,7 @@ int VM_MEMORY_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RES
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if( 0 == sysinfo(&info))
{
@@ -392,7 +392,7 @@ int VM_MEMORY_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RES
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
len=sizeof(struct vmtotal);
mib[0]=CTL_VM;
@@ -414,7 +414,7 @@ int VM_MEMORY_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RES
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
pagesize = 0;
kret = host_page_size (mach_host_self(), &pagesize);
@@ -445,7 +445,7 @@ int VM_MEMORY_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RES
#else
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
diff --git a/src/libs/zbxsysinfo/linux/net.c b/src/libs/zbxsysinfo/linux/net.c
index accddb18..49867845 100644
--- a/src/libs/zbxsysinfo/linux/net.c
+++ b/src/libs/zbxsysinfo/linux/net.c
@@ -27,7 +27,7 @@ int NET_IF_IN(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
return SYSINFO_RET_FAIL;
}
@@ -37,7 +37,7 @@ int NET_IF_OUT(const char *cmd, const char *param, unsigned flags, AGENT_RESULT
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
return SYSINFO_RET_FAIL;
}
diff --git a/src/libs/zbxsysinfo/linux/proc.c b/src/libs/zbxsysinfo/linux/proc.c
index 57be6272..d80dac13 100644
--- a/src/libs/zbxsysinfo/linux/proc.c
+++ b/src/libs/zbxsysinfo/linux/proc.c
@@ -59,7 +59,7 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 3)
{
@@ -312,7 +312,7 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
int proccount = 0;
diff --git a/src/libs/zbxsysinfo/linux/sensors.c b/src/libs/zbxsysinfo/linux/sensors.c
index 234efefa..8620f12d 100644
--- a/src/libs/zbxsysinfo/linux/sensors.c
+++ b/src/libs/zbxsysinfo/linux/sensors.c
@@ -37,7 +37,7 @@ int SENSOR_TEMP1(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
@@ -92,7 +92,7 @@ int SENSOR_TEMP2(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
@@ -147,7 +147,7 @@ int SENSOR_TEMP3(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
dir=opendir("/proc/sys/dev/sensors");
if(NULL == dir)
@@ -196,7 +196,7 @@ int OLD_SENSOR(const char *cmd, const char *param, unsigned flags, AGENT_RES
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 1)
{
diff --git a/src/libs/zbxsysinfo/linux/swap.c b/src/libs/zbxsysinfo/linux/swap.c
index c86a2e46..f24cc3f0 100644
--- a/src/libs/zbxsysinfo/linux/swap.c
+++ b/src/libs/zbxsysinfo/linux/swap.c
@@ -48,7 +48,7 @@ SWP_FNCLIST
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 2)
{
@@ -100,7 +100,7 @@ int OLD_SWAP(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if(num_param(param) > 1)
{
@@ -201,7 +201,7 @@ int SYSTEM_SWAP_FREE(const char *cmd, const char *param, unsigned flags, AGENT_R
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if( 0 == sysinfo(&info))
{
@@ -224,7 +224,7 @@ int SYSTEM_SWAP_FREE(const char *cmd, const char *param, unsigned flags, AGENT_R
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
get_swapinfo(&swaptotal,&swapfree);
@@ -234,7 +234,7 @@ int SYSTEM_SWAP_FREE(const char *cmd, const char *param, unsigned flags, AGENT_R
#else
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
@@ -248,7 +248,7 @@ int SYSTEM_SWAP_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if( 0 == sysinfo(&info))
{
@@ -271,7 +271,7 @@ int SYSTEM_SWAP_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
get_swapinfo(&swaptotal,&swapfree);
@@ -281,7 +281,7 @@ int SYSTEM_SWAP_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_
#else
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
diff --git a/src/libs/zbxsysinfo/linux/uptime.c b/src/libs/zbxsysinfo/linux/uptime.c
index 52a38653..a38b2bd7 100644
--- a/src/libs/zbxsysinfo/linux/uptime.c
+++ b/src/libs/zbxsysinfo/linux/uptime.c
@@ -29,7 +29,7 @@ int SYSTEM_UPTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESU
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
if( 0 == sysinfo(&info))
{
@@ -49,7 +49,7 @@ int SYSTEM_UPTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESU
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
mib[0]=CTL_KERN;
mib[1]=KERN_BOOTTIME;
@@ -78,7 +78,7 @@ int SYSTEM_UPTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESU
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
hz = sysconf(_SC_CLK_TCK);
@@ -113,7 +113,7 @@ int SYSTEM_UPTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESU
#else
assert(result);
- memset(result, 0, sizeof(AGENT_RESULT));
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif