summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-09-30 17:11:17 +0000
committerhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-09-30 17:11:17 +0000
commit5ff76a8be623db727c9931913a6513d7c19a116a (patch)
tree08c5db40f12ebfa954f10f97ab7aed8a3cf8eab0 /src
parentaa3431c5eaac09252d6153dbde29e788fb63334d (diff)
downloadzabbix-5ff76a8be623db727c9931913a6513d7c19a116a.tar.gz
zabbix-5ff76a8be623db727c9931913a6513d7c19a116a.tar.xz
zabbix-5ff76a8be623db727c9931913a6513d7c19a116a.zip
Minor changes.
git-svn-id: svn://svn.zabbix.com/trunk@2087 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src')
-rw-r--r--src/libs/zbxsysinfo/linux/file.c51
-rw-r--r--src/libs/zbxsysinfo/linux/param.c5
-rw-r--r--src/libs/zbxsysinfo/linux/regexp.c3
3 files changed, 41 insertions, 18 deletions
diff --git a/src/libs/zbxsysinfo/linux/file.c b/src/libs/zbxsysinfo/linux/file.c
index 688223a0..dbf042b9 100644
--- a/src/libs/zbxsysinfo/linux/file.c
+++ b/src/libs/zbxsysinfo/linux/file.c
@@ -175,6 +175,7 @@ int VFS_FILE_REGEXP(const char *cmd, const char *param, char **value)
ret = SYSINFO_RET_FAIL;
}
+
if(ret == SYSINFO_RET_OK)
{
f=fopen(filename,"r");
@@ -193,11 +194,10 @@ int VFS_FILE_REGEXP(const char *cmd, const char *param, char **value)
}
else
{
- memset(buf,0,100);
+ memset(buf,0,MAX_FILE_LEN);
}
}
-
if(ret == SYSINFO_RET_OK)
{
if(0 == fread(buf, 1, MAX_FILE_LEN-1, f))
@@ -206,37 +206,54 @@ int VFS_FILE_REGEXP(const char *cmd, const char *param, char **value)
}
}
- if(buf != NULL)
- {
- free(buf);
- }
if(f != NULL)
{
- close(f);
+ fclose(f);
}
- c=zbx_regexp_match(buf, regexp, &len);
-
- if(c == NULL)
+ if(ret == SYSINFO_RET_OK)
{
- tmp[0]=0;
+ c=zbx_regexp_match(buf, regexp, &len);
+
+ if(c == NULL)
+ {
+ tmp[0]=0;
+ }
+ else
+ {
+ strncpy(tmp,c,len);
+ }
+
+ *value = strdup(tmp);
}
- else
+
+ if(buf != NULL)
{
- strncpy(tmp,c,len);
+ free(buf);
}
- *value = strdup(tmp);
-
return ret;
}
-int VFS_FILE_REGMATCH(const char *cmd, const char *filename,double *value)
+int VFS_FILE_REGMATCH(const char *cmd, const char *param,double *value)
{
+ char filename[MAX_STRING_LEN];
+ char regexp[MAX_STRING_LEN];
+
int ret = SYSINFO_RET_OK;
+ if(get_param(param, 1, filename, MAX_STRING_LEN) != 0)
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, regexp, MAX_STRING_LEN) != 0)
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+
ret = SYSINFO_RET_FAIL;
-
+
return ret;
}
diff --git a/src/libs/zbxsysinfo/linux/param.c b/src/libs/zbxsysinfo/linux/param.c
index ed470d9d..db047d21 100644
--- a/src/libs/zbxsysinfo/linux/param.c
+++ b/src/libs/zbxsysinfo/linux/param.c
@@ -21,13 +21,14 @@
#include "config.h"
#include <string.h>
+#include <stdio.h>
int get_param(const char *param, int num, char *buf, int maxlen)
{
char tmp[MAX_STRING_LEN];
char *s;
int ret = 1;
- int i;
+ int i=0;
strscpy(tmp,param);
s=(char *)strtok(tmp,",");
@@ -37,6 +38,8 @@ int get_param(const char *param, int num, char *buf, int maxlen)
if(i == num)
{
strncpy(buf,s,maxlen);
+ ret = 0;
+ break;
}
s=(char *)strtok(NULL,";");
}
diff --git a/src/libs/zbxsysinfo/linux/regexp.c b/src/libs/zbxsysinfo/linux/regexp.c
index a25e5b1f..ff517329 100644
--- a/src/libs/zbxsysinfo/linux/regexp.c
+++ b/src/libs/zbxsysinfo/linux/regexp.c
@@ -20,16 +20,19 @@ char *zbx_regexp_match(const char *string, const char *pattern, int *len)
*len=0;
+
if (regcomp(&re, pattern, REG_EXTENDED | REG_ICASE | REG_NEWLINE) != 0)
{
return(NULL);
}
+
status = regexec(&re, string, (size_t) 1, &match, 0);
/* Not matched */
if (status != 0)
{
+ regfree(&re);
return(NULL);
}