[Sysfence-commit] sysfence conditions.c,1.4,1.5 conditions.h,1.8,1.9 cp2memory.c,1.1,1.2 cp2memory.h
Status: Alpha
Brought to you by:
emes
|
From: Michal S. <em...@us...> - 2004-05-23 20:52:38
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14456 Modified Files: conditions.c conditions.h cp2memory.c cp2memory.h exit.c exit.h getstats.c getstats.h log.c log.h mainloop.c mainloop.h sighandlers.c sysfence.c Log Message: * general redesign: moving to new, extensible data structures stat values logging is temporarily disabled Index: conditions.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/conditions.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- conditions.h 27 Feb 2004 11:16:07 -0000 1.8 +++ conditions.h 23 May 2004 20:52:22 -0000 1.9 @@ -17,54 +17,11 @@ #define DEFAULTSTEP 10 -typedef struct { - enum { - RELATION, - ATOMIC - } type; - - void *arg1; - void *arg2; - token op; -} expression; - -typedef struct { - vartype type; - int val_id; - void *thresh; - token op; -} atomic; - -typedef struct { - int once; - char *runcmd; -} rundata; - -typedef struct { - int once; -} logdata; - -typedef struct { - char *name; - expression *expr; - rundata *run; - logdata *log; - unsigned int step; - - // indicate if expression was true after this check and previous one - int hit, - prevhit; - - // bool vector that shows which stats are used within this rule. - // used by logging functions to report only important values - int showstat[STA_LAST]; -} ruleset; - /* * Functions */ -int check_atomic (atomic *at); -int check_expression (expression *ex); +int check_atomic (sf_atomic *at); +int check_expression (sf_expression *ex); /* $Id$ */ Index: getstats.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/getstats.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- getstats.c 20 May 2004 14:36:12 -0000 1.9 +++ getstats.c 23 May 2004 20:52:22 -0000 1.10 @@ -15,6 +15,8 @@ /* $Id$ */ #include "exit.h" +#include "parseopt/lex.h" +#include "datastruct.h" #include "getstats.h" #include <stdio.h> #include <stdlib.h> @@ -23,27 +25,72 @@ #include <string.h> #include <sys/vfs.h> -const char *lafile = "/proc/loadavg"; -int lafha; -const char *memfile = "/proc/meminfo"; -int memfha; +sf_value get_stat_fs (sf_stat_def def, sf_list *fslist) +{ + sf_value res; -char fbuf[ BUFSIZE ]; + bail_out (EXIT_BUG, "get_stat_fs(): NIY"); + return res; +} +sf_value get_stat_proc (sf_stat_def def, void *proctab) +{ + sf_value res; + + bail_out (EXIT_BUG, "get_stat_proc(): NIY"); + return res; +} -void stat_init (statval *stat) +sf_value get_stat_value (sf_stat_def def) { - strcpy (stat[STA_LA1].label, "la1"); stat[STA_LA1].type = DOUBLE; stat[STA_LA1].val.dbl = 0.0; - strcpy (stat[STA_LA5].label, "la5"); stat[STA_LA5].type = DOUBLE; stat[STA_LA5].val.dbl = 0.0; - strcpy (stat[STA_LA15].label, "la15"); stat[STA_LA15].type = DOUBLE; stat[STA_LA15].val.dbl = 0.0; + sf_value res; + sf_res_state selector = def.arg[0].resstat; - strcpy (stat[STA_MFREE].label, "memfree"); stat[STA_MFREE].type = SIZE; stat[STA_MFREE].val.siz = 0; - strcpy (stat[STA_MUSED].label, "memused"); stat[STA_MUSED].type = SIZE; stat[STA_MUSED].val.siz = 0; - strcpy (stat[STA_SFREE].label, "swapfree"); stat[STA_SFREE].type = SIZE; stat[STA_SFREE].val.siz = 0; - strcpy (stat[STA_SUSED].label, "swapused"); stat[STA_SUSED].type = SIZE; stat[STA_SUSED].val.siz = 0; + switch (def.label) { + case ST_PROC: + res = get_stat_proc (def, main_db->proc); + break; + case ST_FS: + res = get_stat_fs (def, main_db->fs); + break; + case ST_MEM: + res.type = INTEGER; + res.ptr = (void *) &(main_db->mem[selector]); + break; + case ST_SWAP: + res.type = INTEGER; + res.ptr = (void *) &(main_db->swap[selector]); + break; + case ST_LOAD: + res.type = DOUBLE; + switch (def.arg[0].laminutes) { + case 1: + res.ptr = (void *) &(main_db->load[0]); + break; + case 5: + res.ptr = (void *) &(main_db->load[1]); + break; + case 15: + res.ptr = (void *) &(main_db->load[2]); + break; + default: + bail_out (EXIT_BUG, "get_stat_value(): invalid minutes for LA"); + } + break; + default: + bail_out (EXIT_BUG, "get_stat_value(): invalid stat family"); + } + return res; } -void fetch_la () +const char *lafile = "/proc/loadavg"; +int lafha; +const char *memfile = "/proc/meminfo"; +int memfha; + +char fbuf[ BUFSIZE ]; + +void fetch_la (sf_database *db) { char *one, *two, *three; @@ -54,17 +101,17 @@ two = index (one, ' ') + 1; three = index (two, ' ') + 1; - stat[STA_LA1].val.dbl = atof (one); - stat[STA_LA5].val.dbl = atof (two); - stat[STA_LA15].val.dbl = atof (three); + db->load[0] = atof (one); + db->load[1] = atof (two); + db->load[2] = atof (three); #ifdef DEBUG printf ("fetch_la(): la1=%0.2f la5=%0.2f la15=%0.2f\n", - stat[STA_LA1], stat[STA_LA5], stat[STA_LA15]); + db->load[0], db->load[1], db->load[2]); #endif } -void fetch_mem () +void fetch_mem (sf_database *db) { char *ptr; long int vmtot, vmused, vmbuf, vmcache; @@ -93,65 +140,90 @@ ptr = fto_notspace (fto_space (ptr)); vmcache = atol (ptr); - /* 5. next line, swap values. first is 'Swap:', then total. - * next one is swap-used */ - ptr = fto_notspace (fto_space ( - fto_notspace (fto_space ( - fto_newline (ptr) - )) - )); - stat[STA_SUSED].val.siz = atol (ptr); - /* 6. swap-free */ + /* 5. next line, swap values. first is 'Swap:', then total. */ + ptr = fto_notspace (fto_space (fto_newline (ptr))); + db->swap[VA_TOTAL] = atol (ptr); + + /* 6. next one is swap-used */ ptr = fto_notspace (fto_space (ptr)); - stat[STA_SFREE].val.siz = atol (ptr); + db->swap[VA_USED] = atol (ptr); + + /* 7. swap-free */ + ptr = fto_notspace (fto_space (ptr)); + db->swap[VA_FREE] = atol (ptr); + db->swap[VA_AVAIL] = db->swap[VA_FREE]; /* calculate real values, i.e. substract buffers and cache size */ - stat[STA_MUSED].val.siz = vmused - (vmbuf + vmcache); - stat[STA_MFREE].val.siz = vmtot - stat[STA_MUSED].val.siz; + db->mem[VA_TOTAL] = vmtot; + db->mem[VA_USED] = vmused - (vmbuf + vmcache); + db->mem[VA_FREE] = vmtot - db->mem[VA_USED]; + db->mem[VA_AVAIL] = db->mem[VA_FREE]; #ifdef DEBUG printf ("fetch_mem(): memfree=%d memused=%d swapfree=%d swapused=%d\n", - stat[STA_MFREE].val.siz, - stat[STA_MUSED].val.siz, - stat[STA_SFREE].val.siz, - stat[STA_SUSED].val.siz + db->mem[VA_FREE], + db->mem[VA_USED], + db->swap[VA_FREE], + db->swap[VA_USED], ); #endif } -void open_files () -{ - lafha = open (lafile, O_RDONLY); - if (lafha < 0) bail_out (EXIT_IO, lafile); - - memfha = open (memfile, O_RDONLY); - if (memfha < 0) bail_out (EXIT_IO, memfile); -} - -void fetch_pathspace(pathspaceval *pathspace) +void fetch_pathspace (sf_fs_stats *fs) { - struct statfs buf; - long int bsizeKB; + struct statfs buf; + long int bsizeKB; - statfs(pathspace->path, &buf); + statfs (fs->path, &buf); /* block size in KB */ bsizeKB = buf.f_bsize / 1024; - pathspace->total = buf.f_blocks * bsizeKB; - pathspace->free = buf.f_bavail * bsizeKB; - pathspace->used = (buf.f_blocks - buf.f_bfree) * bsizeKB; + 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; #ifdef DEBUG - printf ("fetch_pathspace(): path %s total=%d used=%d free=%d\n", - pathspace->path, - pathspace->total, - pathspace->used, - pathspace->free + printf ("fetch_pathspace(): path %s total=%d used=%d free=%d available=%d\n", + fs->path, + fs->val[VA_TOTAL], + fs->val[VA_USED], + fs->val[VA_FREE], + fs->val[VA_AVAIL] ); #endif } +void fetch_fs (sf_database *db) +{ + sf_list *hd = db->fs; + sf_fs_stats *fs; + + // Iterate through list of watched paths + while (hd) { + fs = (sf_fs_stats *) hd->el; + if (fs) + fetch_pathspace (fs); + hd = hd->next; + } +} + +void fetch_proc (sf_database *db) +{ + return; +} + + +void open_files () +{ + lafha = open (lafile, O_RDONLY); + if (lafha < 0) bail_out (EXIT_IO, lafile); + + memfha = open (memfile, O_RDONLY); + if (memfha < 0) bail_out (EXIT_IO, memfile); +} + /* fast text parsing helpers */ char * fto_newline (char *b) Index: mainloop.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/mainloop.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- mainloop.h 20 May 2004 14:39:43 -0000 1.3 +++ mainloop.h 23 May 2004 20:52:22 -0000 1.4 @@ -15,11 +15,11 @@ /* $Id$ */ int semid; -int shmid; +int rule_shmid; int *ruleprocesses; int rulecount; -void rule_watch_loop (ruleset *rule); -void res_probe_loop (); +void rule_watch_loop (sf_rule *rule); +void res_probe_loop (sf_database *db); /* $Id$ */ Index: cp2memory.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/cp2memory.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- cp2memory.c 20 May 2004 14:47:53 -0000 1.1 +++ cp2memory.c 23 May 2004 20:52:22 -0000 1.2 @@ -13,61 +13,104 @@ */ #include <string.h> #include "parseopt/lex.h" -#include "getstats.h" -#include "conditions.h" +#include "datastruct.h" +#include "cp2memory.h" -int get_expression_size (expression *expr) +int get_data_size (sf_type label) { - int size=0; - atomic *a; + switch (label) { + case INTEGER: + return sizeof (long int); + case DOUBLE: + case PERCENT: + return sizeof (double); + } + return 0; +} - switch (expr->type) { - case ATOMIC: - a = (atomic *)expr->arg1; - if (a->type == DOUBLE) { - size += sizeof(double); - } else { - size += sizeof(long int); - } +int get_list_size (sf_list *list) +{ + int size = sizeof (sf_list); + + if (! list) return 0; - size += sizeof (atomic); - size += sizeof (expression); + size += list->elsize; + size += get_list_size (list->next); - return size ; - case RELATION: - /* copy expression */ - size += get_expression_size ((expression *)expr->arg1); - size += get_expression_size ((expression *)expr->arg2); - size += sizeof (expression); + return size; +} - return size; +int get_atomic_size (sf_atomic *atomic) +{ + int size = sizeof (sf_atomic); + + switch (atomic->stat.label) { + case ST_LOAD: + // arg[0] is integer in {1, 5, 15} + // arg[1] is ignored + size += sizeof (int); + break; + case ST_MEM: + case ST_SWAP: + // arg[0] is sf_res_state + // arg[1] is ignored + size += sizeof (sf_res_state); + break; + case ST_FS: + // arg[0] is sf_res_state + // arg[1] is path + size += sizeof (sf_res_state); + size += strlen (atomic->stat.arg[1].path); + break; + case ST_PROC: + // arg[0] is UID list + // arg[1] is state mask + size += get_list_size (atomic->stat.arg[0].uids); + size += sizeof (int); + break; default: - return 0; - } + break; + + } + return size; } -int get_rundata_size (rundata *run) +int get_expression_size (sf_expression *expr) { - int size=0; + int size = sizeof (sf_expression); - size += sizeof (rundata); - if (run->runcmd) - size += (int)strlen (run->runcmd) + 1; + switch (expr->type) { + case ATOMIC: + size += get_atomic_size ((sf_atomic *)expr->arg1); + break; + case RELATION: + size += get_expression_size ((sf_expression *)expr->arg1); + size += get_expression_size ((sf_expression *)expr->arg2); + break; + } + return size; +} + +int get_rundata_size (sf_rundata *run) +{ + int size = sizeof (sf_rundata); + + if (run->command) + size += (int)strlen (run->command) + 1; return size; } -int get_logdata_size (logdata *log) +int get_logdata_size (sf_logdata *log) { - return sizeof (logdata); + return sizeof (sf_logdata); } -int get_rule_size (ruleset *rule) +int get_rule_size (sf_rule *rule) { - int size=0; + int size = sizeof (sf_rule); - size += sizeof (ruleset); if (rule->name) size += (int)strlen (rule->name) + 1; @@ -85,48 +128,89 @@ return size; } -void *cp_expression (void **buf, expression *expr) +void *cp_list (void **buf, sf_list *list) { - void *b1, *b2; - atomic *a; - expression *e; + sf_list *l; - b1 = *buf; + if (! list) return NULL; + + /* copy list node */ + l = (sf_list *) *buf; + memcpy (*buf, (void *) list, sizeof (sf_list)); + + /* copy element linked to node */ + l->el = *buf; + memcpy (*buf, list->el, list->elsize); + + /* copy list tail */ + l->next = (sf_list *) cp_list (buf, list->next); + + return (void *) l; +} + +void *cp_atomic (void **buf, sf_atomic *atomic) +{ + sf_atomic *a; + int ds; + + a = (sf_atomic *) *buf; + memcpy (*buf, (void *) atomic, sizeof (sf_atomic)); + *buf += sizeof (sf_atomic); + + switch (atomic->stat.label) { + // Copy variable-size data from sf_stat_def + case ST_FS: + // arg[1] is pathname + a->stat.arg[1].path = (char *) *buf; + strcpy (*buf, atomic->stat.arg[1].path); + *buf += strlen (atomic->stat.arg[1].path) + 1; + break; + case ST_PROC: + // arg[0] is UID list + a->stat.arg[0].uids = (sf_list *) cp_list (buf, a->stat.arg[0].uids); + break; + default: + break; + } + + /* copy threshold */ + ds = get_data_size (atomic->thresh.type); + memcpy (*buf, (void *) atomic->thresh.ptr, ds); + buf += ds; + + return a; +} + + +void *cp_expression (void **buf, sf_expression *expr) +{ + void *b1, *b2; + sf_atomic *a = (sf_atomic *) expr->arg1; + sf_expression *e; switch (expr->type) { case ATOMIC: - /* copy thresh */ - a = (atomic *)expr->arg1; - if (a->type == DOUBLE) { - memcpy (*buf, (void *)a->thresh, sizeof (double)); - *buf += sizeof(double); - } else { - memcpy (*buf, (void *)a->thresh, sizeof (long int)); - *buf += sizeof(long int); - } - /* copy atomic */ - memcpy (*buf, (void *)a, sizeof(atomic)); - a = (atomic *) *buf; - a->thresh = b1; - *buf += sizeof (atomic); + a = (sf_atomic *) cp_atomic (buf, a); - /* copy expression */ - memcpy (*buf, (void *)expr, sizeof(expression)); - e = (expression *) *buf; - e->arg1 = (void *)a; - *buf += sizeof (expression); + /* copy expression itself */ + memcpy (*buf, (void *)expr, sizeof(sf_expression)); + e = (sf_expression *) *buf; + e->arg1 = (void *) a; + *buf += sizeof (sf_expression); return (void *)e ; case RELATION: - /* copy expression */ - b1 = cp_expression (buf, (expression *)expr->arg1); - b2 = cp_expression (buf, (expression *)expr->arg2); - memcpy (*buf, (void *)expr, sizeof (expression)); - e = (expression *) *buf; + /* copy child expressions */ + b1 = cp_expression (buf, (sf_expression *)expr->arg1); + b2 = cp_expression (buf, (sf_expression *)expr->arg2); + + /* copy expression itself */ + memcpy (*buf, (void *)expr, sizeof (sf_expression)); + e = (sf_expression *) *buf; e->arg1 = b1; e->arg2 = b2; - *buf += sizeof (expression); + *buf += sizeof (sf_expression); return (void *)e; default: @@ -134,48 +218,48 @@ } } -void *cp_rundata (void **buf, rundata *run) +void *cp_rundata (void **buf, sf_rundata *run) { - rundata *r; + sf_rundata *r; /* copy rundata */ - memcpy (*buf, (void *)run, sizeof (rundata)); - r = (rundata *) *buf; - *buf += sizeof (rundata); + memcpy (*buf, (void *)run, sizeof (sf_rundata)); + r = (sf_rundata *) *buf; + *buf += sizeof (sf_rundata); - /* copy runcmd */ - if (run->runcmd) { - strcpy (*buf, run->runcmd); - r->runcmd = (char *) *buf; - *buf += (int)strlen (run->runcmd) + 1; + /* copy command */ + if (run->command) { + strcpy (*buf, run->command); + r->command = (char *) *buf; + *buf += (int)strlen (run->command) + 1; } return (void *)r; } -void *cp_logdata (void **buf, logdata *log) +void *cp_logdata (void **buf, sf_logdata *log) { void *b; /* copy logdata */ - memcpy (*buf, (void *)log, sizeof (logdata)); + memcpy (*buf, (void *)log, sizeof (sf_logdata)); b = *buf; - *buf += sizeof (logdata); + *buf += sizeof (sf_logdata); return b; } -void *cp_rule (void **buf, ruleset *rule) +void *cp_rule (void **buf, sf_rule *rule) { - ruleset *r; + sf_rule *r; /* copy rule */ - memcpy (*buf, (void *)rule, sizeof (ruleset)); - r = (ruleset *) *buf; - *buf += sizeof (ruleset); + memcpy (*buf, (void *)rule, sizeof (sf_rule)); + r = (sf_rule *) *buf; + *buf += sizeof (sf_rule); - /* copy name*/ + /* copy name */ if (rule->name) { strcpy (*buf, rule->name); r->name = (char *) *buf; @@ -183,15 +267,19 @@ } /* copy expression */ - r->expr = (expression *) cp_expression (buf, rule->expr); + r->expr = (sf_expression *) cp_expression (buf, rule->expr); /* copy rundata */ if (r->run) - r->run = (rundata *) cp_rundata (buf, rule->run); + r->run = (sf_rundata *) cp_rundata (buf, rule->run); /* copy logdata */ if (r->log) - r->log = (logdata *) cp_logdata (buf, rule->log); + r->log = (sf_logdata *) cp_logdata (buf, rule->log); return (void *)r; } + +/* + $Id$ +*/ Index: getstats.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/getstats.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- getstats.h 20 May 2004 14:34:33 -0000 1.6 +++ getstats.h 23 May 2004 20:52:22 -0000 1.7 @@ -16,49 +16,25 @@ #define BUFSIZE 512 -#define STA_LA1 0 -#define STA_LA5 1 -#define STA_LA15 2 -#define STA_MFREE 3 -#define STA_MUSED 4 -#define STA_SFREE 5 -#define STA_SUSED 6 -#define STA_LAST 7 - -typedef enum { - DOUBLE, - SIZE -} vartype; - -#define MAX_LABEL 10 - -typedef struct { - char label[MAX_LABEL]; - vartype type; +#define FS_DATA_SIZE 32768 // 32k +#define PROC_DATA_SIZE 524288 // 512k - union { - double dbl; - long int siz; - } val; - -} statval; +/* shared memory segments */ +int db_shmid, fs_shmid, proc_shmid, rules_shmid; +void *db_shm, *fs_shm, *proc_shm, *rules_shm; -typedef struct { - char *path; - long int total, used, free; - -} pathspaceval; +sf_database *main_db; -statval *stat; +sf_value get_stat_value (sf_stat_def def); -void stat_init (statval *stat); +void stat_init (sf_database *db); +void fetch_la (sf_database *db); +void fetch_mem (sf_database *db); +void fetch_fs (sf_database *db); +void fetch_proc (sf_database *db); -void fetch_la (); -void fetch_mem (); void open_files (); -void fetch_pathspace(pathspaceval *pathspace); - char * fto_newline (char *b); char * fto_notspace (char *b); char * fto_space (char *b); Index: conditions.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/conditions.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- conditions.c 26 Feb 2004 20:11:09 -0000 1.4 +++ conditions.c 23 May 2004 20:52:15 -0000 1.5 @@ -14,7 +14,9 @@ */ #include <stdio.h> +#include "exit.h" #include "parseopt/lex.h" +#include "datastruct.h" #include "getstats.h" #include "conditions.h" @@ -50,43 +52,47 @@ } } -int check_atomic (atomic *at) +int check_atomic (sf_atomic *at) { - double dv = stat[at->val_id].val.dbl, - *dt = (double *) at->thresh; - long int iv = stat[at->val_id].val.siz, - *it = (long int *) at->thresh; + 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); + + if (at->thresh.type != val.type) bail_out (EXIT_BUG, "check_atomic(): type mismatch!"); - switch (at->type) { + switch (at->thresh.type) { case DOUBLE: return ordcmp ( - (dv < *dt), - (dv == *dt), - (dv > *dt), + (dv < dt), + (dv == dt), + (dv > dt), at->op ); - case SIZE: + case INTEGER: return ordcmp ( - (iv < *it), - (iv == *it), - (iv > *it), + (iv < it), + (iv == it), + (iv > it), at->op ); default: - return 0; + bail_out (EXIT_BUG, " check_atomic(): used type that is not implemented yet"); + return 0; // to avoid warnings } } -int check_expression (expression *ex) +int check_expression (sf_expression *ex) { switch (ex->type) { case ATOMIC: - return check_atomic ((atomic *) ex->arg1); + return check_atomic ((sf_atomic *) ex->arg1); case RELATION: return logcmp ( - check_expression ((expression *) ex->arg1), + check_expression ((sf_expression *) ex->arg1), ex->op, - check_expression ((expression *) ex->arg2) + check_expression ((sf_expression *) ex->arg2) ); default: return 0; Index: cp2memory.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/cp2memory.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- cp2memory.h 20 May 2004 14:48:59 -0000 1.1 +++ cp2memory.h 23 May 2004 20:52:22 -0000 1.2 @@ -12,5 +12,7 @@ */ -int get_rule_size (ruleset *rule); -void *cp_rule (void **buf, ruleset *rule); +int get_list_size (sf_list *list); +int get_rule_size (sf_rule *rule); +void *cp_list (void **buf, sf_list *list); +void *cp_rule (void **buf, sf_rule *rule); Index: mainloop.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/mainloop.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- mainloop.c 20 May 2004 14:37:37 -0000 1.8 +++ mainloop.c 23 May 2004 20:52:22 -0000 1.9 @@ -18,6 +18,7 @@ #include <stdlib.h> #include <unistd.h> #include "parseopt/lex.h" +#include "datastruct.h" #include "getstats.h" #include "conditions.h" #include "log.h" @@ -26,7 +27,7 @@ int step = 10; -void rule_watch_loop (ruleset *rule) +void rule_watch_loop (sf_rule *rule) { while (1) { /* save result of this and previous hit */ @@ -54,9 +55,9 @@ /* second - run command */ if (rule->run != NULL) { if (! (rule->run->once && rule->prevhit)) { - system (rule->run->runcmd); + system (rule->run->command); #ifdef DEBUG - printf ("executed '%s'\n", rule->run->runcmd); + printf ("executed '%s'\n", rule->run->command); #endif } } @@ -71,14 +72,15 @@ } -void res_probe_loop () +void res_probe_loop (sf_database *db) { while (1) { /* set semaphore while changing data */ semaphore_wait (semid); - fetch_la (); - fetch_mem (); + fetch_la (db); + fetch_mem (db); + fetch_fs (db); semaphore_post (semid); sleep (step); Index: sysfence.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/sysfence.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- sysfence.c 22 May 2004 16:45:08 -0000 1.15 +++ sysfence.c 23 May 2004 20:52:22 -0000 1.16 @@ -23,6 +23,7 @@ #include "xalloc.h" #include "exit.h" #include "parseopt/lex.h" +#include "datastruct.h" #include "getstats.h" #include "conditions.h" #include "parseopt/parse.h" @@ -41,46 +42,18 @@ "Report bugs to <em...@pl...>\n" "\n"; -#ifdef DEBUG -void print_atomic (atomic *a) -{ - if (a->type == DOUBLE) { - printf ("(%0.2f ", stat[a->val_id].val.dbl); - printf (tok2string (a->op)); - printf (" %0.2f)", *((double *)a->thresh)); - } else if (a->type == SIZE) { - printf ("(%d ", stat[a->val_id].val.siz); - printf (tok2string (a->op)); - printf (" %d)", *((long int *)a->thresh)); - } -} - -void print_expr (expression *e) -{ - if (e->type == ATOMIC) { - print_atomic ((atomic *) e->arg1); - } else { - printf (" ("); - print_expr ((expression *) e->arg1); - printf (" %s ", tok2string (e->op)); - print_expr ((expression *) e->arg2); - printf (") "); - } -} -#endif - int main (int argc, char *argv[]) { - ruleset **ruletab, **ruleshm; + sf_rule **ruletab, **shmruletab; + void *shmruleptr; + int i; - int ruletabsize; + int total_rules_size = 0; int pid; - void *shm; - #ifdef DEBUG - ruleset *rl; + sf_rule *rl; #endif if (argc < 2) bail_out (EXIT_NOCONF, NULL); @@ -94,33 +67,6 @@ while (*(ruletab + rulecount) != NULL) rulecount ++; log_start (rulecount); - -#ifdef DEBUG - - printf ("read %d rules.\n", rulecount); - - i = 0; - rl = *(ruletab + i); - - while (rl != NULL) { - printf ("\nRULESET %d:\n", i); - print_expr (rl->expr); - printf (" == %d\n", check_expression (rl->expr)); - if (rl->log != NULL) { - printf ("log"); - if ((rl->log)->once) printf (" once"); - printf ("\n"); - } - if (rl->run != NULL) { - printf ("run '%s'", (rl->run)->runcmd); - if ((rl->run)->once) printf (" once"); - printf ("\n"); - } - printf ("RULESET-END\n\n"); - i ++; - rl = *(ruletab + i); - } -#endif /* open files for reading data and detach from console */ open_files (); @@ -132,34 +78,53 @@ if (semid < 0) bail_out (EXIT_SEM, NULL); /* count ruletab size */ - ruletabsize = 0; - for (i=0; i<rulecount; i++) - ruletabsize += get_rule_size (*(ruletab+i)); + for (i = 0; i < rulecount; i++) + total_rules_size += get_rule_size (*(ruletab + i)); + + /* initialize shared memory for rules */ + rules_shmid = shared_mem_init (total_rules_size + rulecount * sizeof (void *)); + if (rules_shmid < 0) bail_out (EXIT_SHM, NULL); + rules_shm = shared_mem_attach (rules_shmid); - /* initialize shared memory */ - shmid = shared_mem_init (STA_LAST * sizeof(statval) + - ruletabsize + - rulecount * sizeof (void *)); - if (shmid < 0) bail_out (EXIT_SHM, NULL); - shm = shared_mem_attach (shmid); + /* initialize shared memory for stats database */ + db_shmid = shared_mem_init (sizeof (sf_database)); + if (db_shmid < 0) bail_out (EXIT_SHM, NULL); + db_shm = shared_mem_attach (db_shmid); + main_db = (sf_database *) db_shm; - stat = (statval *)shm; + /* initialize shared memory for fs database */ + fs_shmid = shared_mem_init (FS_DATA_SIZE); + if (fs_shmid < 0) bail_out (EXIT_SHM, NULL); + fs_shm = shared_mem_attach (fs_shmid); - /* copy ruletab to shared memory */ - ruleshm = (ruleset **)(shm + STA_LAST * sizeof (statval)); - shm = (void *)(ruleshm + rulecount * sizeof (void *)); + /* initialize shared memory for proc database */ + proc_shmid = shared_mem_init (PROC_DATA_SIZE); + if (proc_shmid < 0) bail_out (EXIT_SHM, NULL); + proc_shm = shared_mem_attach (proc_shmid); - for (i=0; i<rulecount ;i++) { - *(ruleshm + i) = (ruleset *)cp_rule (&shm, *(ruletab + i)); + /* initialize database */ + main_db->fs = (sf_list *) fs_shm; + main_db->proc = proc_shm; + main_db->fs->elsize = -1; + main_db->fs->el = NULL; + main_db->fs->next = NULL; + + /* copy ruletab to shared memory */ + shmruletab = (sf_rule **) rules_shm; + shmruleptr = (rules_shm + rulecount * sizeof (void *)); + for (i = 0; i < rulecount; i++) { + *(shmruletab + i) = (sf_rule *) cp_rule (&shmruleptr, *(ruletab + i)); } /* rule-watching processes start before data provider, so we must get fresh * stats before starting them */ - fetch_la (); - fetch_mem (); + fetch_la (main_db); + fetch_mem (main_db); + fetch_fs (main_db); + fetch_proc (main_db); assert (rulecount); - ruleprocesses = (int *)xalloc (NULL, rulecount*sizeof(int)); + ruleprocesses = (int *) xalloc (NULL, rulecount * sizeof (int)); i = rulecount; do { pid = (int)fork (); @@ -170,14 +135,14 @@ /* child */ if (pid == 0) { /* one child process one ruleset */ - rule_watch_loop (*(ruleshm + i)); + rule_watch_loop (*(shmruletab + i)); } else /* parent */ { /* start handling signals */ signal_init (); /* parent goes into data-providing loop */ - res_probe_loop (); + res_probe_loop (main_db); } /* remove compilation warning */ Index: log.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/log.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- log.c 1 Mar 2004 17:28:10 -0000 1.6 +++ log.c 23 May 2004 20:52:22 -0000 1.7 @@ -20,10 +20,12 @@ #include <syslog.h> #include "xalloc.h" #include "parseopt/lex.h" +#include "datastruct.h" #include "getstats.h" #include "conditions.h" #include "log.h" +#if 0 char * stats2str (int *sta) { char *res = xalloc (NULL, LOGLINEBUF); @@ -67,6 +69,7 @@ return res; } +#endif void log_start (int rules) { @@ -77,9 +80,10 @@ syslog (LOG_INFO, "loaded %d rules", rules); } -void log_rulehit (ruleset *rule) +void log_rulehit (sf_rule *rule) { - char *stattxt = stats2str (&(rule->showstat[0])); +// char *stattxt = stats2str (&(rule->showstat[0])); + char *stattxt = "stat logging temporarily disabled"; if (rule->name != NULL) syslog (LOG_WARNING, Index: sighandlers.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/sighandlers.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- sighandlers.c 20 May 2004 14:43:21 -0000 1.1 +++ sighandlers.c 23 May 2004 20:52:22 -0000 1.2 @@ -18,6 +18,7 @@ #include <string.h> #include "exit.h" #include "parseopt/lex.h" +#include "datastruct.h" #include "getstats.h" #include "conditions.h" #include "mainloop.h" @@ -69,8 +70,14 @@ if (*(ruleprocesses + i)) kill ((pid_t)*(ruleprocesses + i), SIGTERM); /* detach, deallocate shared memory */ - shared_mem_detach ((void *)stat); - shared_mem_del (shmid); + shared_mem_detach (db_shm); + shared_mem_del (db_shmid); + shared_mem_detach (fs_shm); + shared_mem_del (fs_shmid); + shared_mem_detach (proc_shm); + shared_mem_del (proc_shmid); + shared_mem_detach (rules_shm); + shared_mem_del (rules_shmid); /* deallocate semaphore */ semaphore_del (semid); Index: log.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/log.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- log.h 26 Feb 2004 20:11:09 -0000 1.2 +++ log.h 23 May 2004 20:52:22 -0000 1.3 @@ -18,7 +18,7 @@ #define LOGVARBUF 64 void log_start (int rules); -void log_rulehit (ruleset *rule); +void log_rulehit (sf_rule *rule); void log_end (); /* $Id$ */ Index: exit.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/exit.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- exit.h 20 May 2004 14:31:35 -0000 1.5 +++ exit.h 23 May 2004 20:52:22 -0000 1.6 @@ -29,6 +29,8 @@ #define EXIT_SHM 31 #define EXIT_SEM 32 +#define EXIT_BUG 41 + void bail_out (int excode, const char *details); /* $Id$ */ Index: exit.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/exit.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- exit.c 20 May 2004 14:32:35 -0000 1.5 +++ exit.c 23 May 2004 20:52:22 -0000 1.6 @@ -29,8 +29,11 @@ [EXIT_PARSE] = "Parse error: %s", [EXIT_VALUE] = "Invalid value: %s", [EXIT_OPTION] = "Invalid option: %s", + [EXIT_SHM] = "Shared memory exists", - [EXIT_SEM] = "Semaphore exists" + [EXIT_SEM] = "Semaphore exists", + + [EXIT_BUG] = "Internal bug" }; extern char *usage; |