[Sysfence-commit] sysfence conditions.c,1.7,1.8 datastruct.c,1.7,1.8 datastruct.h,1.8,1.9 getstats.c
Status: Alpha
Brought to you by:
emes
|
From: Michal S. <em...@us...> - 2004-05-31 14:10:36
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9425 Modified Files: conditions.c datastruct.c datastruct.h getstats.c mainloop.c Log Message: * BUGFIX: using long long int to avoid type overflow Index: datastruct.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/datastruct.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- datastruct.h 31 May 2004 11:59:29 -0000 1.8 +++ datastruct.h 31 May 2004 14:10:06 -0000 1.9 @@ -166,8 +166,8 @@ typedef struct { // Statistics of underlying filesystem in path - char *path; - unsigned long int val[ VA_LAST ]; + char *path; + unsigned long long int val[ VA_LAST ]; } sf_fs_stat; typedef struct { @@ -179,8 +179,8 @@ typedef struct { // Main statistics database double load[3]; - long int mem[ VA_LAST ]; - long int swap[ VA_LAST ]; + long long int mem[ VA_LAST ]; + long long int swap[ VA_LAST ]; sf_list *fs; // list of filesystems being watched int nr_proc; // number of process entries in array sf_proc_stat *proc; // array of processes Index: getstats.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/getstats.c,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- getstats.c 31 May 2004 11:59:29 -0000 1.18 +++ getstats.c 31 May 2004 14:10:06 -0000 1.19 @@ -37,7 +37,7 @@ #ifdef DEBUG syslog (LOG_DEBUG, - "get_stat_fs(%s): total = %ld, used = %ld, free = %ld, avail = %ld", + "get_stat_fs(%s): total = %llu, used = %llu, free = %llu, avail = %llu", def->arg[1].path, fs->val[VA_TOTAL], fs->val[VA_USED], @@ -147,7 +147,7 @@ void fetch_mem (sf_database *db) { char *ptr; - long int vmtot, vmused, vmbuf, vmcache; + long long int vmtot, vmused, vmbuf, vmcache; lseek (memfha, 0, SEEK_SET); read (memfha, (char *) &fbuf, BUFSIZE); @@ -156,10 +156,10 @@ /* 1. memory total is in second line after 'Mem:\ *' */ ptr = fto_notspace (fto_space (fto_newline ((char *)&fbuf))); - vmtot = atol (ptr); + vmtot = atoll (ptr); /* 2. used mem is next value */ ptr = fto_notspace (fto_space (ptr)); - vmused = atol (ptr); + vmused = atoll (ptr); /* 3. then there are: 'free' field, 'shared' field, * and what we're looking for - buffers */ @@ -168,22 +168,22 @@ fto_notspace (fto_space (ptr)) )) )); - vmbuf = atol (ptr); + vmbuf = atoll (ptr); /* 4. cached is next field */ ptr = fto_notspace (fto_space (ptr)); - vmcache = atol (ptr); + vmcache = atoll (ptr); /* 5. next line, swap values. first is 'Swap:', then total. */ ptr = fto_notspace (fto_space (fto_newline (ptr))); - db->swap[VA_TOTAL] = atol (ptr); + db->swap[VA_TOTAL] = atoll (ptr); /* 6. next one is swap-used */ ptr = fto_notspace (fto_space (ptr)); - db->swap[VA_USED] = atol (ptr); + db->swap[VA_USED] = atoll (ptr); /* 7. swap-free */ ptr = fto_notspace (fto_space (ptr)); - db->swap[VA_FREE] = atol (ptr); + db->swap[VA_FREE] = atoll (ptr); db->swap[VA_AVAIL] = db->swap[VA_FREE]; /* calculate real values, i.e. substract buffers and cache size */ @@ -209,17 +209,18 @@ statfs (fs->path, &buf); /* block size in KB */ - bsizeKB = buf.f_bsize / 1024; +// bsizeKB = buf.f_bsize / 1024; /* sizes are in kilobytes */ - fs->val[VA_TOTAL] = buf.f_blocks * bsizeKB; - fs->val[VA_AVAIL] = buf.f_bavail * bsizeKB; - fs->val[VA_FREE] = buf.f_bfree * bsizeKB; - fs->val[VA_USED] = (buf.f_blocks - buf.f_bfree) * bsizeKB; + fs->val[VA_TOTAL] = (long long int) buf.f_blocks * (long long int) buf.f_bsize; + fs->val[VA_AVAIL] = (long long int) buf.f_bavail * (long long int) buf.f_bsize; + fs->val[VA_FREE] = (long long int) buf.f_bfree * (long long int) buf.f_bsize; + fs->val[VA_USED] = + ((long long int) buf.f_blocks - (long long int) buf.f_bfree) * (long long int) buf.f_bsize; #ifdef DEBUG syslog (LOG_DEBUG, - "fetch_pathspace(): path %s bsize=%ld btotal=%ld bfree=%ld bavail=%ld", + "fetch_pathspace(): path %s bsize=%lu btotal=%lu bfree=%lu bavail=%lu", fs->path, buf.f_bsize, buf.f_blocks, @@ -227,7 +228,7 @@ buf.f_bavail ); syslog (LOG_DEBUG, - "fetch_pathspace(): path %s total=%luk used=%luk free=%luk avail=%luk", + "fetch_pathspace(): path %s total=%lld used=%lld free=%lld avail=%lld", fs->path, fs->val[VA_TOTAL], fs->val[VA_USED], @@ -240,7 +241,7 @@ void fetch_fs (sf_database *db) { sf_list *hd = db->fs; - sf_fs_stat *fs; + sf_fs_stat *fs; // Iterate through list of watched paths while (hd) { @@ -299,7 +300,7 @@ DIR *dh; struct dirent *de; struct stat statbuf; - long int pid; + long long int pid; char fnamebuf[ PROCDIRNAMELEN + 1 ]; sf_proc_stat res; @@ -317,12 +318,12 @@ if (de->d_type != DT_DIR) continue; /* try to convert file name to int */ - pid = atol (de->d_name); + pid = atoll (de->d_name); /* zero means it's not a process' dir */ if (!pid) continue; /* get real dir name */ - snprintf (&fnamebuf[0], PROCDIRNAMELEN, "%s/%ld", procdir, pid); + snprintf (&fnamebuf[0], PROCDIRNAMELEN, "%s/%llu", procdir, pid); stat (&fnamebuf[0], &statbuf); res.uid = statbuf.st_uid; res.state = get_proc_state (db, &fnamebuf[0]); @@ -357,7 +358,7 @@ close (fh); - syslog (LOG_NOTICE, "maximum number of threads in system: %ld", mt); + syslog (LOG_NOTICE, "maximum number of threads in system: %d", mt); return mt; } Index: conditions.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/conditions.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- conditions.c 26 May 2004 18:23:04 -0000 1.7 +++ conditions.c 31 May 2004 14:10:06 -0000 1.8 @@ -19,6 +19,9 @@ #include "datastruct.h" #include "getstats.h" #include "conditions.h" +#ifdef DEBUG +#include <syslog.h> +#endif int ordcmp (int le, int eq, int gt, token op) { @@ -57,13 +60,22 @@ sf_value val = get_stat_value (&(at->stat)); double dv = *((double *) val.ptr), dt = *((double *) at->thresh.ptr); - long int iv = *((long int *) val.ptr), - it = *((long int *) at->thresh.ptr); + long long int iv = *((long long int *) val.ptr), + it = *((long long int *) at->thresh.ptr); if (at->thresh.type != val.type) bail_out (EXIT_BUG, "check_atomic(): type mismatch!"); switch (at->thresh.type) { case DOUBLE: +#ifdef DEBUG + syslog (LOG_DEBUG, + "cmp val=%f vs thr=%f: <:%d =:%d >:%d", + dv, dt, + (dv < dt), + (dv == dt), + (dv > dt) + ); +#endif return ordcmp ( (dv < dt), (dv == dt), @@ -71,6 +83,15 @@ at->op ); case INTEGER: +#ifdef DEBUG + syslog (LOG_DEBUG, + "cmp val=%llu vs thr=%llu: <:%d =:%d >:%d", + iv, it, + (iv < it), + (iv == it), + (iv > it) + ); +#endif return ordcmp ( (iv < it), (iv == it), Index: datastruct.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/datastruct.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- datastruct.c 31 May 2004 11:59:29 -0000 1.7 +++ datastruct.c 31 May 2004 14:10:06 -0000 1.8 @@ -158,7 +158,7 @@ /* do not insert duplicates */ #ifdef DEBUG - syslog (LOG_DEBUG, "? %s == %s", e->path, path); + syslog (LOG_DEBUG, "? %s == %s : %d", e->path, path, strcmp (e->path, path)); #endif if (strcmp (e->path, path) == 0) return; @@ -207,7 +207,7 @@ case ST_FS: return ((d1->arg[0].resstat == d2->arg[0].resstat) && - strcmp (d1->arg[1].path, d2->arg[1].path)); + (strcmp (d1->arg[1].path, d2->arg[1].path) == 0)); case ST_PROC: return ((d1->arg[1].procstates == d2->arg[1].procstates) && Index: mainloop.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/mainloop.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- mainloop.c 31 May 2004 10:30:33 -0000 1.14 +++ mainloop.c 31 May 2004 14:10:06 -0000 1.15 @@ -92,7 +92,7 @@ fetch_la (db); fetch_mem (db); fetch_fs (db); - fetch_proc (db); +// fetch_proc (db); semaphore_post (semid); signals_handling (SIGUNBLOCK); |