~ubuntu-dev/ubuntu/lucid/zabbix/lucid-201002110857

« back to all changes in this revision

Viewing changes to src/libs/zbxsysinfo/linux/proc.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Ablassmeier
  • Date: 2007-07-02 09:06:51 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070702090651-8l6fl3fjw9rh6l2u
Tags: 1:1.4.1-2
Add patch from SVN in order to fix Incorrect processing of character '%'
in user parameters and remote commands.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 * ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
18
 * **/
19
19
 
20
 
#include "config.h"
21
 
 
22
20
#include "common.h"
 
21
 
23
22
#include "sysinfo.h"
24
23
 
25
24
#define DO_SUM 0
56
55
 
57
56
        FILE    *f = NULL, *f2 = NULL;
58
57
 
59
 
        zbx_uint64_t    memsize;
 
58
        zbx_uint64_t    memsize = 0;
60
59
        int             first=0;
61
60
        zbx_uint64_t    proccount = 0;
62
61
 
136
135
 
137
136
        while((entries=readdir(dir))!=NULL)
138
137
        {
139
 
                if(f)
140
 
                {
141
 
                        fclose(f);
142
 
                        f = NULL;
143
 
                }
 
138
                zbx_fclose(f);
144
139
 
145
140
                proc_ok = 0;
146
141
                usr_ok = 0;
158
153
 
159
154
                if(stat(filename,&buf)==0)
160
155
                {
161
 
                        f=fopen(filename,"r");
162
 
                        if(f==NULL)
 
156
                        if(NULL == ( f = fopen(filename,"r") ))
163
157
                        {
164
158
                                continue;
165
159
                        }
218
212
                        comm_ok = 0;
219
213
                        if(proccomm[0] != '\0')
220
214
                        {
221
 
                                strscpy(filename,"/proc/");     
 
215
                                strscpy(filename,"/proc/");
222
216
                                zbx_strlcat(filename,entries->d_name,MAX_STRING_LEN);
223
217
                                zbx_strlcat(filename,"/cmdline",MAX_STRING_LEN);
224
 
                                
225
 
                                if(stat(filename,&buf)!=0)      continue;
226
 
                                
 
218
 
 
219
                                if(stat(filename,&buf)!=0)      continue;
 
220
 
227
221
                                f2=fopen(filename,"r");
228
 
                                if(f2==NULL)                    continue;
229
 
                                
 
222
                                if(f2==NULL)                    continue;
 
223
 
230
224
                                memset(line,0,MAX_STRING_LEN);
231
225
                                if((n = fread(line, 1, MAX_STRING_LEN, f2)) != 0)
232
226
                                {
233
227
                                        /* Replace all zero delimiters with spaces */
234
228
                                        for(i=0;i<n-1;i++)
235
229
                                        {
236
 
                                                if(line[i]==0)  line[i]=' ';
 
230
                                                if(line[i]==0)  line[i]=' ';
237
231
                                        }
238
232
                                        if(zbx_regexp_match(line,proccomm,NULL) != NULL)
239
 
                                                comm_ok = 1;
 
233
                                        comm_ok = 1;
240
234
                                }
241
235
 
242
236
                                fclose(f2);
304
298
                        }
305
299
                }
306
300
        }
307
 
        if(f) fclose(f);
 
301
        zbx_fclose(f);
308
302
        closedir(dir);
309
303
 
310
304
        if(first == 0)
447
441
                        continue;
448
442
                }
449
443
 
450
 
                f=fopen(filename,"r");
451
 
                if(f==NULL)
 
444
                if(NULL == (f = fopen(filename,"r") ))
452
445
                {
453
446
                        continue;
454
447
                }
470
463
                
471
464
                    if(proc_ok == 0) 
472
465
                    {
473
 
                        fclose(f);
 
466
                        zbx_fclose(f);
474
467
                        continue;
475
468
                    }
476
469
                }
480
473
                }
481
474
 
482
475
                stat_ok = 0;
483
 
                if(procstat[0] != 0)
484
 
                {
485
 
                
 
476
                if(procstat[0] != 0)
 
477
                {
486
478
                    while(fgets(line, MAX_STRING_LEN, f) != NULL)
487
479
                    {   
488
480
                    
535
527
                {
536
528
                    usr_ok = 1;
537
529
                }
538
 
                fclose(f);
 
530
                zbx_fclose(f);
539
531
                
540
532
                comm_ok = 0;
541
533
                if(proccomm[0] != '\0')
542
534
                {
543
 
                        strscpy(filename,"/proc/");     
 
535
                        strscpy(filename,"/proc/");
544
536
                        zbx_strlcat(filename,entries->d_name,MAX_STRING_LEN);
545
537
                        zbx_strlcat(filename,"/cmdline",MAX_STRING_LEN);
546
538
 
547
 
                        if(stat(filename,&buf)!=0)      continue;
548
 
                        
 
539
                        if(stat(filename,&buf)!=0)      continue;
 
540
 
549
541
                        f=fopen(filename,"r");
550
 
                        if(f==NULL)                     continue;
 
542
                        if(f==NULL)                    continue;
551
543
                        
552
544
                        memset(line,0,MAX_STRING_LEN);
553
545
                        if((n = fread(line, 1, MAX_STRING_LEN, f)) != 0)
555
547
                                /* Replace all zero delimiters with spaces */
556
548
                                for(i=0;i<n-1;i++)
557
549
                                {
558
 
                                        if(line[i]==0)  line[i]=' ';
 
550
                                        if(line[i]==0)  line[i]=' ';
559
551
                                }
560
552
                                if(zbx_regexp_match(line,proccomm,NULL) != NULL)
561
 
                                        comm_ok = 1;
 
553
                                comm_ok = 1;
562
554
                        }
 
555
                        fclose(f);
563
556
 
564
 
                        fclose(f);
565
557
                } else {
566
558
                        comm_ok = 1;
567
559
                }