diff options
| author | alex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-06-08 13:05:08 +0000 |
|---|---|---|
| committer | alex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-06-08 13:05:08 +0000 |
| commit | 44f2671774e8bdfff69986a082924f82848040e1 (patch) | |
| tree | 931c4dac18bdc4151a087d04e082775814c72ee6 /src/libs/zbxsysinfo/linux | |
| parent | 135733dad10d39112c00fd1af0498d64f151b2ed (diff) | |
| download | zabbix-44f2671774e8bdfff69986a082924f82848040e1.tar.gz zabbix-44f2671774e8bdfff69986a082924f82848040e1.tar.xz zabbix-44f2671774e8bdfff69986a082924f82848040e1.zip | |
- fixed processing of cmdline for proc.num and proc.mem (Alexei)
git-svn-id: svn://svn.zabbix.com/trunk@4251 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/libs/zbxsysinfo/linux')
| -rw-r--r-- | src/libs/zbxsysinfo/linux/proc.c | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/src/libs/zbxsysinfo/linux/proc.c b/src/libs/zbxsysinfo/linux/proc.c index d5fc46c9..295cb6e5 100644 --- a/src/libs/zbxsysinfo/linux/proc.c +++ b/src/libs/zbxsysinfo/linux/proc.c @@ -48,6 +48,8 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE int usr_ok = 0; int do_task = DO_SUM; + int i,n; + struct passwd *usrinfo = NULL; zbx_uint64_t llvalue = 0; @@ -210,23 +212,28 @@ int PROC_MEMORY(const char *cmd, const char *param, unsigned flags, AGENT_RE comm_ok = 0; if(proccomm[0] != '\0') { - strscpy(filename,"/proc/"); + strscpy(filename,"/proc/"); zbx_strlcat(filename,entries->d_name,MAX_STRING_LEN); zbx_strlcat(filename,"/cmdline",MAX_STRING_LEN); - - if(stat(filename,&buf)!=0) - continue; - - if(NULL == (f2 = fopen(filename,"r") )) - continue; - - if(fgets(line, MAX_STRING_LEN, f2) != NULL) + + if(stat(filename,&buf)!=0) continue; + + f2=fopen(filename,"r"); + if(f2==NULL) continue; + + memset(line,0,MAX_STRING_LEN); + if((n = fread(line, 1, MAX_STRING_LEN, f2)) != 0) { + /* Replace all zero delimiters with spaces */ + for(i=0;i<n-1;i++) + { + if(line[i]==0) line[i]=' '; + } if(zbx_regexp_match(line,proccomm,NULL) != NULL) - comm_ok = 1; + comm_ok = 1; } - zbx_fclose(f2); + fclose(f2); } else { comm_ok = 1; } @@ -333,6 +340,8 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL int stat_ok = 0; int comm_ok = 0; + int i,n; + struct passwd *usrinfo = NULL; long int lvalue = 0; @@ -523,21 +532,28 @@ int PROC_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESUL comm_ok = 0; if(proccomm[0] != '\0') { - strscpy(filename,"/proc/"); + strscpy(filename,"/proc/"); zbx_strlcat(filename,entries->d_name,MAX_STRING_LEN); zbx_strlcat(filename,"/cmdline",MAX_STRING_LEN); + + if(stat(filename,&buf)!=0) continue; + + f=fopen(filename,"r"); + if(f==NULL) continue; - if(stat(filename,&buf)!=0) - continue; - - if(NULL == (f = fopen(filename,"r") )) - continue; - - if(fgets(line, MAX_STRING_LEN, f) != NULL) + memset(line,0,MAX_STRING_LEN); + if((n = fread(line, 1, MAX_STRING_LEN, f)) != 0) + { + /* Replace all zero delimiters with spaces */ + for(i=0;i<n-1;i++) + { + if(line[i]==0) line[i]=' '; + } if(zbx_regexp_match(line,proccomm,NULL) != NULL) - comm_ok = 1; + comm_ok = 1; + } + fclose(f); - zbx_fclose(f); } else { comm_ok = 1; } |
